added build-time test for line length

Tue, 27 Jul 2021 09:56:06 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 27 Jul 2021 09:56:06 +0300
changeset 114
4e03b0e2a29f
parent 113
c0d064521ee0
child 115
ed884a2fb009

added build-time test for line length

CMakeLists.txt file | annotate | diff | comparison | revisions
tools/linelength.py file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Mon Jul 26 11:50:45 2021 +0300
+++ b/CMakeLists.txt	Tue Jul 27 09:56:06 2021 +0300
@@ -212,6 +212,15 @@
 set_source_files_properties (${CMAKE_BINARY_DIR}/configuration.cpp PROPERTIES GENERATED TRUE)
 set_property(SOURCE configuration.cpp PROPERTY SKIP_AUTOGEN ON)
 
+
+add_custom_target(linelength ALL
+	COMMAND python3
+		"${CMAKE_SOURCE_DIR}/tools/linelength.py"
+		${LDFORGE_SOURCES}
+		${LDFORGE_HEADERS}
+	WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
+add_dependencies(ldforge linelength)
+
 # 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/linelength.py	Tue Jul 27 09:56:06 2021 +0300
@@ -0,0 +1,20 @@
+#!/usr/bin/env python3
+import sys
+def check(filename):
+	with open(filename) as file:
+		for linenumber, line in enumerate(file, 1):
+			if line[-1] == '\n':
+				line = line[:-1]
+			line = str.replace(line, '\t', ' ' * 4)
+			if len(line) > 120:
+				print(str.format(
+					'{filename}:{linenumber}: warning: line length exceeds 120 characters',
+					filename = filename,
+					linenumber = linenumber
+				), file = sys.stderr)
+def main():
+	for filename in sys.argv[1:]:
+		check(filename)
+	return 0
+if __name__ == '__main__':
+	sys.exit(main())

mercurial