diff --git a/cpp_linter/run.py b/cpp_linter/run.py index ea416cbf..c5782780 100644 --- a/cpp_linter/run.py +++ b/cpp_linter/run.py @@ -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 = "\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 = "\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: @@ -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.""" @@ -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(",") @@ -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