Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

コーディング規約チェックスクリプトに,ルール単位でのignoreを追加 #309

Merged
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions Script/CI/check_coding_rule.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
"ignore_files" : [
"src_user/TlmCmd/telemetry_definitions.c"
],
"ignore_rules" : [
],
"comment_ignore_rules" : [
"以下を指定すると,該当ルールが無視される",
"comment",
"newline",
"eof",
"space",
"operator_space",
"preprocessor",
"include_guard"
],
"additional_type" : [
"TCP",
"CommonTlmCmdPacket",
Expand Down
33 changes: 22 additions & 11 deletions Script/CI/check_coding_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

# コード中に現れた型
# unsigned hoge, signed hoge を除く
g_type_set = set()
g_type_set: set = set()


def main():
Expand All @@ -39,6 +39,26 @@ def main():
if DEBUG:
pprint.pprint(settings)

check_funcs_all = [
check_comment_,
check_newline_,
check_eof_,
check_space_,
check_operator_space_,
check_preprocessor_,
check_include_guard_,
]
check_funcs = []

# ignore rules のチェック
for func in check_funcs_all:
rule_name = func.__name__[6:-1]
if rule_name not in settings["ignore_rules"]:
check_funcs.append(func)
else:
print("WARNING: " + rule_name + " rule is ignored!!")
settings["check_funcs"] = check_funcs # ここだけ, settings に追記している

if not check_coding_rule(settings):
print("The above files are invalid coding rule.")
sys.exit(1)
Expand Down Expand Up @@ -166,16 +186,7 @@ def check_file_(path: str, settings: dict) -> bool:
with open(path, encoding=settings["input_file_encoding"]) as f:
code_lines = f.read().split("\n")

check_funcs = [
check_comment_,
check_newline_,
check_eof_,
check_space_,
check_operator_space_,
check_preprocessor_,
check_include_guard_,
]
for check_func in check_funcs:
for check_func in settings["check_funcs"]:
if not check_func(path, code_lines):
flag = False

Expand Down