Let's try to keep the amount of indents in check...

Sun, 03 Jul 2022 12:20:26 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sun, 03 Jul 2022 12:20:26 +0300
changeset 317
852021f38b66
parent 316
aab8e139a149
child 318
216f02b50b0a

Let's try to keep the amount of indents in check...

CMakeLists.txt file | annotate | diff | comparison | revisions
tools/indentlevel.py file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Sat Jul 02 19:05:05 2022 +0300
+++ b/CMakeLists.txt	Sun Jul 03 12:20:26 2022 +0300
@@ -182,6 +182,14 @@
 	WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
 add_dependencies(${TARGET_NAME} linelength)
 
+add_custom_target(indentlevel ALL
+	COMMAND python3
+		"${CMAKE_SOURCE_DIR}/tools/indentlevel.py"
+		${SOURCE_FILES}
+		${HEADER_FILESl}
+	WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
+add_dependencies(${TARGET_NAME} indentlevel)
+
 # Collect the current hg revision into hginfo.h
 add_custom_target(revision_check ALL
 	COMMAND python3 "${CMAKE_SOURCE_DIR}/tools/updaterevision.py" --cwd "$(CMAKE_SOURCE_DIR)" hginfo.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/indentlevel.py	Sun Jul 03 12:20:26 2022 +0300
@@ -0,0 +1,14 @@
+#!/usr/bin/env python3
+import sys
+too_many = 6
+for filename in sys.argv[1:]:
+	with open(filename) as file:
+		at_start_of_new_block = False
+		old_n = 0
+		for linenumber, line in enumerate(file, 1):
+			import re
+			n = len(re.match('^(\t*).*$', line).group(1))
+			if at_start_of_new_block and n >= too_many and old_n < too_many:
+				print(f'{filename}:{linenumber}: warning: block with {n} indent levels', file = sys.stderr)
+			at_start_of_new_block = line.strip().endswith('{')
+			old_n = n

mercurial