Skip to content

Commit 977eb16

Browse files
authored
fix format comment (#36)
* fix format comments - make sure that total count of files that need formatting align with the number of files listed - respect all values of `lines-changed-only` when creating format comment * ensure clang v12 is installed Ubuntu-latest runners no longer ship with clang v12 * update pre-commit hooks
1 parent b556ddb commit 977eb16

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

.github/workflows/run-dev-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ jobs:
5757
- os: 'ubuntu-22.04'
5858
version: '13'
5959
tools_dir: 'N/A'
60-
- os: 'ubuntu-22.04'
61-
version: '12'
62-
tools_dir: 'N/A'
6360

6461
runs-on: ${{ matrix.os }}
6562
steps:

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.4.0
3+
rev: v4.5.0
44
hooks:
55
- id: trailing-whitespace
66
- id: end-of-file-fixer
@@ -13,12 +13,12 @@ repos:
1313
- id: mixed-line-ending
1414
args: ["--fix=lf"]
1515
- repo: https://github.com/python/black
16-
rev: '23.3.0'
16+
rev: '23.10.1'
1717
hooks:
1818
- id: black
1919
args: ["--diff"]
2020
- repo: https://github.com/pycqa/pylint
21-
rev: v3.0.0a6
21+
rev: v3.0.1
2222
hooks:
2323
- id: pylint
2424
name: pylint (action code)

cpp_linter/run.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -418,15 +418,14 @@ def create_comment_body(
418418
if CLANG_FORMAT_XML.exists() and CLANG_FORMAT_XML.stat().st_size:
419419
parse_format_replacements_xml(PurePath(filename).as_posix())
420420
if GlobalParser.format_advice and GlobalParser.format_advice[-1].replaced_lines:
421-
should_comment = lines_changed_only == 0
422-
if not should_comment:
423-
for line in [
424-
replacement.line
425-
for replacement in GlobalParser.format_advice[-1].replaced_lines
426-
]:
427-
if line in ranges:
428-
should_comment = True
429-
break
421+
should_comment = False
422+
for line in [
423+
replacement.line
424+
for replacement in GlobalParser.format_advice[-1].replaced_lines
425+
]:
426+
if (lines_changed_only and line in ranges) or not lines_changed_only:
427+
should_comment = True
428+
break
430429
if should_comment:
431430
Globals.FORMAT_COMMENT += f"- {file_obj['filename']}\n"
432431

@@ -478,9 +477,10 @@ def capture_clang_tools_output(
478477
if Globals.FORMAT_COMMENT or Globals.TIDY_COMMENT:
479478
Globals.OUTPUT += ":warning:\nSome files did not pass the configured checks!\n"
480479
if Globals.FORMAT_COMMENT:
480+
files_count = Globals.FORMAT_COMMENT.count("\n")
481481
Globals.OUTPUT += (
482482
"\n<details><summary>clang-format reports: <strong>"
483-
+ f"{len(GlobalParser.format_advice)} file(s) not formatted</strong>"
483+
+ f"{files_count} file(s) not formatted</strong>"
484484
+ f"</summary>\n\n{Globals.FORMAT_COMMENT}\n\n</details>"
485485
)
486486
if Globals.TIDY_COMMENT:

0 commit comments

Comments
 (0)