Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions scripts/ci/check_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,34 @@ def filter_py(root, fnames):
mime=True) == "text/x-python")]


class CMakeStyle(ComplianceTest):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it is better to split this into own script to be able to extend it in the future with more cmake style checks and also be able to run it standalone and just call that script from check_compliance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check is very rudimental, it doesn't check for elseif/else/endif/foreach/endforeach and probably many more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, thart is my point. my concern is that we will start expanding the linter functionality inside check_compliance, which is in general a wrapper on top of linters, not a linter itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please let me know if you want me to update the commit. I would be happy if you could point me to existing examples of such linters and where to put the python script linting cmake code.

"""
Checks cmake style added/modified files
"""
name = "CMakeStyle"
doc = "See https://docs.zephyrproject.org/latest/contribute/style/cmake.html for more details."

def run(self):
# Loop through added/modified files
for fname in get_files(filter="d"):
if fname.endswith(".cmake") or fname == "CMakeLists.txt":
self.check_style(fname)

def check_style(self, fname):
SPACE_BEFORE_OPEN_BRACKETS_CHECK = re.compile(r"^\s*if\s+\(")
TAB_INDENTATION_CHECK = re.compile(r"^\t+")

with open(fname, encoding="utf-8") as f:
for line_num, line in enumerate(f.readlines(), start=1):
if TAB_INDENTATION_CHECK.match(line):
self.fmtd_failure("error", "CMakeStyle", fname, line_num,
"Use spaces instead of tabs for indentation")

if SPACE_BEFORE_OPEN_BRACKETS_CHECK.match(line):
self.fmtd_failure("error", "CMakeStyle", fname, line_num,
"Remove space before '(' in if() statements")


class Identity(ComplianceTest):
"""
Checks if Emails of author and signed-off messages are consistent.
Expand Down
Loading