Skip to content
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1aff6c7
upload new demo image
2bndy5 Aug 22, 2021
26c6744
Revert "upload new demo image"
2bndy5 Aug 22, 2021
c8b7121
Merge branch 'shenxianpeng:master' into master
2bndy5 Aug 22, 2021
a274052
update readme & upload new demo pic
2bndy5 Aug 22, 2021
c9b8889
avoids duplicated checks on commits to open PR
2bndy5 Aug 22, 2021
778e10d
fix workflow from last commit
2bndy5 Aug 22, 2021
8da8e0d
Revert "fix workflow from last commit"
2bndy5 Aug 23, 2021
d0a6384
Merge branch 'master' of https://github.com/shenxianpeng/cpp-linter-a…
2bndy5 Aug 23, 2021
ae35f76
Merge branch 'shenxianpeng:master' into main
2bndy5 Aug 25, 2021
f633223
Merge branch 'shenxianpeng:master' into main
2bndy5 Oct 11, 2021
e459c41
rename py pkg; allow no clang-tidy & no event.json
2bndy5 Oct 20, 2021
bb3aade
pleasing pylint
2bndy5 Oct 20, 2021
323a159
various bug fixes
2bndy5 Oct 20, 2021
3979a31
Merge branch 'shenxianpeng:master' into main
2bndy5 Oct 20, 2021
f9f7067
pleasing pylint
2bndy5 Oct 20, 2021
c5eb9d3
update README about `tidy-checks=-*`
2bndy5 Oct 20, 2021
7226e58
increase indent in last change
2bndy5 Oct 20, 2021
bae2d17
increase indent again (I don't like mkdocs)
2bndy5 Oct 20, 2021
18c04f2
update docs
2bndy5 Oct 20, 2021
5bbdd0a
avoid nesting log groups
2bndy5 Oct 20, 2021
1733c4f
switch pylint to my check-python-sources action
2bndy5 Oct 20, 2021
f65a8f1
trigger pylint action
2bndy5 Oct 20, 2021
87c42f9
Revert "switch pylint to my check-python-sources action"
2bndy5 Oct 20, 2021
9f3f283
Merge branch 'shenxianpeng:master' into main
2bndy5 Oct 20, 2021
d295581
fix regressions from last update
2bndy5 Oct 21, 2021
8bee079
break out parsing ignore option from main()
2bndy5 Oct 21, 2021
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
82 changes: 52 additions & 30 deletions cpp_linter/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,16 @@ def capture_clang_tools_output(
tidy_notes.append(note)
GlobalParser.tidy_notes.clear() # empty list to avoid duplicated output

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

if Globals.PAYLOAD_TIDY:
if not Globals.OUTPUT:
Expand Down Expand Up @@ -651,19 +655,56 @@ def make_annotations(style: str) -> bool:
# log_commander obj's verbosity is hard-coded to show debug statements
ret_val = False
count = 0
for note in GlobalParser.tidy_notes:
ret_val = True
log_commander.info(note.log_command())
count += 1
for note in GlobalParser.format_advice:
if note.replaced_lines:
ret_val = True
log_commander.info(note.log_command(style))
count += 1
for note in GlobalParser.tidy_notes:
ret_val = True
log_commander.info(note.log_command())
count += 1
logger.info("Created %d annotations", count)
return ret_val


def parse_ignore_option(paths: str):
"""Parse a givven string of paths (separated by a '|') into `ignored` and
`not_ignored` lists of strings.

Args:
paths: This argument conforms to the CLI arg `--ignore` (or `-i`).

Returns:
A tuple of lists in which each list is a set of strings.
- index 0 is the `ignored` list
- index 1 is the `not_ignored` list
"""
ignored, not_ignored = ([], [])
paths = paths.split("|")
for path in paths:
is_included = path.startswith("!")
if path.startswith("!./" if is_included else "./"):
path = path.replace("./", "", 1) # relative dir is assumed
path = path.strip() # strip leading/trailing spaces
if is_included:
not_ignored.append(path[1:])
else:
ignored.append(path)

if ignored:
logger.info(
"Ignoring the following paths/files:\n\t./%s",
"\n\t./".join(f for f in ignored),
)
if not_ignored:
logger.info(
"Not ignoring the following paths/files:\n\t./%s",
"\n\t./".join(f for f in not_ignored),
)
return (ignored, not_ignored)


def main():
"""The main script."""

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

# prepare ignored paths list
ignored, not_ignored = ([], [])
if args.ignore is not None:
args.ignore = args.ignore.split("|")
for path in args.ignore:
path = path.lstrip("./") # relative dir is assumed
path = path.strip() # strip leading/trailing spaces
if path.startswith("!"):
not_ignored.append(path[1:])
else:
ignored.append(path)
ignored, not_ignored = parse_ignore_option("" if not args.ignore else args.ignore)

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

if ignored:
logger.info(
"Ignoring the following paths/files:\n\t%s",
"\n\t./".join(f for f in ignored),
)
if not_ignored:
logger.info(
"Not ignoring the following paths/files:\n\t%s",
"\n\t./".join(f for f in not_ignored),
)
exit_early = False
if args.files_changed_only:
# load event's json info about the workflow run
Expand Down