Skip to content

Commit 3ad10e1

Browse files
authored
fix some reggression from #30 (#31)
* upload new demo image * Revert "upload new demo image" This reverts commit 1aff6c7. * update readme & upload new demo pic * avoids duplicated checks on commits to open PR * fix workflow from last commit * Revert "fix workflow from last commit" This reverts commit 778e10d. * rename py pkg; allow no clang-tidy & no event.json * pleasing pylint * various bug fixes * pleasing pylint * update README about `tidy-checks=-*` * increase indent in last change * increase indent again (I don't like mkdocs) * update docs * avoid nesting log groups * switch pylint to my check-python-sources action * trigger pylint action * Revert "switch pylint to my check-python-sources action" This reverts commit 1733c4f. * fix regressions from last update * break out parsing ignore option from main()
1 parent b4e9991 commit 3ad10e1

File tree

1 file changed

+52
-30
lines changed

1 file changed

+52
-30
lines changed

cpp_linter/run.py

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,16 @@ def capture_clang_tools_output(
469469
tidy_notes.append(note)
470470
GlobalParser.tidy_notes.clear() # empty list to avoid duplicated output
471471

472-
parse_format_replacements_xml(filename.replace("/", os.sep))
473-
if GlobalParser.format_advice[-1].replaced_lines:
474-
if not Globals.OUTPUT:
475-
Globals.OUTPUT = "<!-- cpp linter action -->\n## :scroll: "
476-
Globals.OUTPUT += "Run `clang-format` on the following files\n"
477-
Globals.OUTPUT += f"- [ ] {file['filename']}\n"
472+
if os.path.getsize("clang_format_output.xml"):
473+
parse_format_replacements_xml(filename.replace("/", os.sep))
474+
if (
475+
GlobalParser.format_advice
476+
and GlobalParser.format_advice[-1].replaced_lines
477+
):
478+
if not Globals.OUTPUT:
479+
Globals.OUTPUT = "<!-- cpp linter action -->\n## :scroll: "
480+
Globals.OUTPUT += "Run `clang-format` on the following files\n"
481+
Globals.OUTPUT += f"- [ ] {file['filename']}\n"
478482

479483
if Globals.PAYLOAD_TIDY:
480484
if not Globals.OUTPUT:
@@ -651,19 +655,56 @@ def make_annotations(style: str) -> bool:
651655
# log_commander obj's verbosity is hard-coded to show debug statements
652656
ret_val = False
653657
count = 0
654-
for note in GlobalParser.tidy_notes:
655-
ret_val = True
656-
log_commander.info(note.log_command())
657-
count += 1
658658
for note in GlobalParser.format_advice:
659659
if note.replaced_lines:
660660
ret_val = True
661661
log_commander.info(note.log_command(style))
662662
count += 1
663+
for note in GlobalParser.tidy_notes:
664+
ret_val = True
665+
log_commander.info(note.log_command())
666+
count += 1
663667
logger.info("Created %d annotations", count)
664668
return ret_val
665669

666670

671+
def parse_ignore_option(paths: str):
672+
"""Parse a givven string of paths (separated by a '|') into `ignored` and
673+
`not_ignored` lists of strings.
674+
675+
Args:
676+
paths: This argument conforms to the CLI arg `--ignore` (or `-i`).
677+
678+
Returns:
679+
A tuple of lists in which each list is a set of strings.
680+
- index 0 is the `ignored` list
681+
- index 1 is the `not_ignored` list
682+
"""
683+
ignored, not_ignored = ([], [])
684+
paths = paths.split("|")
685+
for path in paths:
686+
is_included = path.startswith("!")
687+
if path.startswith("!./" if is_included else "./"):
688+
path = path.replace("./", "", 1) # relative dir is assumed
689+
path = path.strip() # strip leading/trailing spaces
690+
if is_included:
691+
not_ignored.append(path[1:])
692+
else:
693+
ignored.append(path)
694+
695+
if ignored:
696+
logger.info(
697+
"Ignoring the following paths/files:\n\t./%s",
698+
"\n\t./".join(f for f in ignored),
699+
)
700+
if not_ignored:
701+
logger.info(
702+
"Not ignoring the following paths/files:\n\t./%s",
703+
"\n\t./".join(f for f in not_ignored),
704+
)
705+
return (ignored, not_ignored)
706+
707+
667708
def main():
668709
"""The main script."""
669710

@@ -674,16 +715,7 @@ def main():
674715
logger.setLevel(int(args.verbosity))
675716

676717
# prepare ignored paths list
677-
ignored, not_ignored = ([], [])
678-
if args.ignore is not None:
679-
args.ignore = args.ignore.split("|")
680-
for path in args.ignore:
681-
path = path.lstrip("./") # relative dir is assumed
682-
path = path.strip() # strip leading/trailing spaces
683-
if path.startswith("!"):
684-
not_ignored.append(path[1:])
685-
else:
686-
ignored.append(path)
718+
ignored, not_ignored = parse_ignore_option("" if not args.ignore else args.ignore)
687719

688720
# prepare extensions list
689721
args.extensions = args.extensions.split(",")
@@ -693,16 +725,6 @@ def main():
693725
# change working directory
694726
os.chdir(args.repo_root)
695727

696-
if ignored:
697-
logger.info(
698-
"Ignoring the following paths/files:\n\t%s",
699-
"\n\t./".join(f for f in ignored),
700-
)
701-
if not_ignored:
702-
logger.info(
703-
"Not ignoring the following paths/files:\n\t%s",
704-
"\n\t./".join(f for f in not_ignored),
705-
)
706728
exit_early = False
707729
if args.files_changed_only:
708730
# load event's json info about the workflow run

0 commit comments

Comments
 (0)