From 75f44b678fa58eb587726b23c983f6fb9e51ee67 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sat, 30 Aug 2025 19:12:49 +0200 Subject: [PATCH 01/41] free styler --- .github/workflows/style.yml | 28 +++++++++++++++++++++++++ scripts/build/style.py | 41 +++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 .github/workflows/style.yml create mode 100644 scripts/build/style.py diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml new file mode 100644 index 0000000000000..e963208e60235 --- /dev/null +++ b/.github/workflows/style.yml @@ -0,0 +1,28 @@ +name: Style Check + +on: + pull_request: + - '.github/workflows/**' + - 'src/**.cpp' + - 'src/**.h' + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install reviewdog + uses: reviewdog/action-setup@v1 + with: + reviewdog_version: latest + + - name: Run linter + run: | + # Get changed files in the PR + files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E '\.(c|cpp|h|hpp)$' || true) + if [ -n "$files" ]; then + scripts/build/style.py $files | reviewdog -efm="%f:%l: %m" -name="pr-linter" -reporter=github-pr-review -level=error + fi diff --git a/scripts/build/style.py b/scripts/build/style.py new file mode 100644 index 0000000000000..5a0bd587f1df5 --- /dev/null +++ b/scripts/build/style.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +import re +import sys +from pathlib import Path + +def check_file(path: Path): + errors = [] + try: + text = path.read_text() + except Exception: + return errors # skip non-text files + + # Must end with newline + if not text.endswith("\n"): + errors.append((len(text.splitlines()) or 1, "File must end with a newline")) + + # Hex literals lowercase + hex_pattern = re.compile(r"0x[A-F]+") + for i, line in enumerate(text.splitlines(), 1): + if hex_pattern.search(line): + errors.append((i, "Hex literals must be lowercase")) + + # No single-line C-style comments + comment_pattern = re.compile(r"/\*.*\*/") + for i, line in enumerate(text.splitlines(), 1): + if comment_pattern.search(line): + errors.append((i, "Single-line block comments (/* ... */) are not allowed")) + + return errors + +def main(): + failed = False + for file in sys.argv[1:]: + path = Path(file) + for lineno, msg in check_file(path): + print(f"{path}:{lineno}: {msg}") + failed = True + sys.exit(1 if failed else 0) + +if __name__ == "__main__": + main() From 2ce0989d8e24771aad2b14ddfbd38674f2c2a7c8 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sat, 30 Aug 2025 19:57:57 +0200 Subject: [PATCH 02/41] also check mame.lst --- .github/workflows/style.yml | 10 +++- scripts/build/style.py | 110 ++++++++++++++++++++++++++++++------ 2 files changed, 101 insertions(+), 19 deletions(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index e963208e60235..747dc751f3d25 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -19,10 +19,14 @@ jobs: with: reviewdog_version: latest - - name: Run linter + - name: Run style check run: | - # Get changed files in the PR files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E '\.(c|cpp|h|hpp)$' || true) if [ -n "$files" ]; then - scripts/build/style.py $files | reviewdog -efm="%f:%l: %m" -name="pr-linter" -reporter=github-pr-review -level=error + scripts/build/style.py $files \ + | reviewdog -efm="%f:%l: %m" \ + -name="cpp-style" \ + -reporter=github-pr-review \ + -filter-mode=diff_context \ + -fail-on-error=false fi diff --git a/scripts/build/style.py b/scripts/build/style.py index 5a0bd587f1df5..f19ef7e866e51 100644 --- a/scripts/build/style.py +++ b/scripts/build/style.py @@ -3,39 +3,117 @@ import sys from pathlib import Path -def check_file(path: Path): +def is_screaming_snake(name: str): + return re.fullmatch(r"[A-Z][A-Z0-9_]*", name) is not None + +def is_snake_case(name: str): + return re.fullmatch(r"[a-z][a-z0-9_]*(_[a-z0-9]+)*", name) is not None + +def check_cpp_file(path: Path): errors = [] try: text = path.read_text() except Exception: return errors # skip non-text files - # Must end with newline + lines = text.splitlines() + if not text.endswith("\n"): - errors.append((len(text.splitlines()) or 1, "File must end with a newline")) + errors.append((len(lines) or 1, "File should end with a newline")) - # Hex literals lowercase - hex_pattern = re.compile(r"0x[A-F]+") - for i, line in enumerate(text.splitlines(), 1): + for i, line in enumerate(lines, 1): + hex_pattern = re.compile(r"0x[A-F]+") if hex_pattern.search(line): - errors.append((i, "Hex literals must be lowercase")) + errors.append((i, "Hex literals should be lowercase (0x1a not 0x1A)")) + + comment_pattern = re.compile(r"/\*.*\*/") + if comment_pattern.search(line.strip()): + errors.append((i, "/* Single-line block comments */ are not allowed, use // instead")) + + macro_pattern = re.compile(r"^\s*#define\s+([A-Za-z0-9_]+)") + m = macro_pattern.match(line) + if m and not is_screaming_snake(m.group(1)): + errors.append((i, f"Macro '{m.group(1)}' should use SCREAMING_SNAKE_CASE")) + + const_pattern = re.compile(r"\bconst\b[^;=()]*\b([A-Za-z_][A-Za-z0-9_]*)\b\s*(?:=|;)") + c = const_pattern.search(line) + if c and not is_screaming_snake(c.group(1)): + errors.append((i, f"Constant '{c.group(1)}' should use SCREAMING_SNAKE_CASE")) + + function_pattern = re.compile(r"\b([a-z][a-z0-9_]*)\s*\(") + f = function_pattern.search(line) + if f and not is_snake_case(f.group(1)): + errors.append((i, f"Function '{f.group(1)}' should use snake_case")) + + class_pattern = re.compile(r"\bclass\s+([A-Za-z0-9_]+)") + cl = class_pattern.search(line) + if cl and not is_snake_case(cl.group(1)): + errors.append((i, f"Class '{cl.group(1)}' should use snake_case")) + + enum_pattern = re.compile(r"\benum\s+(class\s+)?([A-Za-z0-9_]+)") + en = enum_pattern.search(line) + if en and not is_snake_case(en.group(2)): + errors.append((i, f"Enum '{en.group(2)}' should use snake_case")) + + return errors - # No single-line C-style comments - comment_pattern = re.compile(r"/\*.*\*/") - for i, line in enumerate(text.splitlines(), 1): - if comment_pattern.search(line): - errors.append((i, "Single-line block comments (/* ... */) are not allowed")) +def check_mame_lst(changed_cpp_files: set[str]): + errors = [] + try: + lines = Path("src/mame/mame.lst").read_text().splitlines() + except Exception: + return errors + + current_block = [] + block_start_line = 0 + current_source = None + + def check_block(block, start_line, src_file): + if not src_file or src_file not in changed_cpp_files: + return [] + sorted_block = sorted(block, key=lambda s: s.lower()) + errors_local = [] + for offset, (expected, actual) in enumerate(zip(sorted_block, block)): + if expected != actual: + line_no = start_line + offset + 1 + errors_local.append( + (line_no, f"Entry '{actual}' is out of order, expected '{expected}'") + ) + return errors_local + + for i, line in enumerate(lines): + if line.startswith("@source:"): + # clear previous block + if current_block: + errors.extend(check_block(current_block, block_start_line, current_source)) + # new block + current_source = "src/mame/" + line[len("@source:"):].strip() + + current_block = [] + block_start_line = i + 1 + elif line.strip(): + current_block.append(line.strip()) + + if current_block: + errors.extend(check_block(current_block, block_start_line, current_source)) return errors def main(): - failed = False + cpp_files = {f for f in sys.argv[1:] if f.endswith(".cpp")} + for file in sys.argv[1:]: path = Path(file) - for lineno, msg in check_file(path): + errors = check_cpp_file(path) + + for lineno, msg in errors: print(f"{path}:{lineno}: {msg}") - failed = True - sys.exit(1 if failed else 0) + + errors = check_mame_lst(cpp_files) + for lineno, msg in errors: + print(f"src/mame/mame.lst:{lineno}: {msg}") + + sys.exit(0) # needed so workflow doesn't fail if __name__ == "__main__": main() From 19690207ea990cc666353dea6595c3cb27d4b6b6 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sat, 30 Aug 2025 20:03:27 +0200 Subject: [PATCH 03/41] bad indentation --- .github/workflows/style.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 747dc751f3d25..1d95a8359b428 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -1,7 +1,8 @@ name: Style Check on: - pull_request: + pull_request: + paths: - '.github/workflows/**' - 'src/**.cpp' - 'src/**.h' From 08c359a6f07879777d31effcc94543c35e1014d2 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sat, 30 Aug 2025 20:10:52 +0200 Subject: [PATCH 04/41] get filenames --- .github/workflows/style.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 1d95a8359b428..bd0b9d7e984b5 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -14,6 +14,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 2 - name: Install reviewdog uses: reviewdog/action-setup@v1 @@ -22,7 +24,7 @@ jobs: - name: Run style check run: | - files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E '\.(c|cpp|h|hpp)$' || true) + files=$(git diff --name-only HEAD^1 HEAD | grep -E '\.(c|cpp|h|hpp)$' || true) if [ -n "$files" ]; then scripts/build/style.py $files \ | reviewdog -efm="%f:%l: %m" \ From 99e9a5dae3e96641e43323b0923aa254a7c779d6 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sat, 30 Aug 2025 20:16:25 +0200 Subject: [PATCH 05/41] run it --- .github/workflows/style.yml | 8 ++++---- scripts/build/style.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) mode change 100644 => 100755 scripts/build/style.py diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index bd0b9d7e984b5..da838c0869cfa 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -18,15 +18,15 @@ jobs: fetch-depth: 2 - name: Install reviewdog - uses: reviewdog/action-setup@v1 - with: - reviewdog_version: latest + uses: reviewdog/action-setup@v1.3.2 - name: Run style check + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | files=$(git diff --name-only HEAD^1 HEAD | grep -E '\.(c|cpp|h|hpp)$' || true) if [ -n "$files" ]; then - scripts/build/style.py $files \ + python3 scripts/build/style.py $files \ | reviewdog -efm="%f:%l: %m" \ -name="cpp-style" \ -reporter=github-pr-review \ diff --git a/scripts/build/style.py b/scripts/build/style.py old mode 100644 new mode 100755 index f19ef7e866e51..0678c13fbac6e --- a/scripts/build/style.py +++ b/scripts/build/style.py @@ -14,7 +14,7 @@ def check_cpp_file(path: Path): try: text = path.read_text() except Exception: - return errors # skip non-text files + return errors # skip non-text files lines = text.splitlines() From e67e21f20b263504c06b3362bb90ca653dd16cec Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sun, 31 Aug 2025 20:05:15 +0200 Subject: [PATCH 06/41] try another way --- .github/workflows/style.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index da838c0869cfa..ec82854e9d97a 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -15,7 +15,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 with: - fetch-depth: 2 + fetch-depth: 0 - name: Install reviewdog uses: reviewdog/action-setup@v1.3.2 @@ -24,7 +24,7 @@ jobs: env: REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - files=$(git diff --name-only HEAD^1 HEAD | grep -E '\.(c|cpp|h|hpp)$' || true) + files=$(git diff --name-only --diff-filter=d "${{ github.event.base_ref }}~1" "${{ github.event.head_ref }}" | grep -E '\.(c|cpp|h|hpp)$' || true) if [ -n "$files" ]; then python3 scripts/build/style.py $files \ | reviewdog -efm="%f:%l: %m" \ From f9e51bbaa50a445605c162a428723e49adde0977 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sun, 31 Aug 2025 20:15:44 +0200 Subject: [PATCH 07/41] use a library --- .github/workflows/style.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index ec82854e9d97a..142f04b73f895 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -20,11 +20,15 @@ jobs: - name: Install reviewdog uses: reviewdog/action-setup@v1.3.2 + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v46.0.5 + - name: Run style check env: REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - files=$(git diff --name-only --diff-filter=d "${{ github.event.base_ref }}~1" "${{ github.event.head_ref }}" | grep -E '\.(c|cpp|h|hpp)$' || true) + files=$(echo ${{ steps.changed-files.outputs.all_changed_files }} | grep -E '\.(cpp|h)$' || true) if [ -n "$files" ]; then python3 scripts/build/style.py $files \ | reviewdog -efm="%f:%l: %m" \ From 1aa3684b56a3f326b5606d3aa29977704eb8b946 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sun, 31 Aug 2025 20:23:57 +0200 Subject: [PATCH 08/41] pretty useless --- scripts/build/style.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/build/style.py b/scripts/build/style.py index 0678c13fbac6e..dcc546010a868 100755 --- a/scripts/build/style.py +++ b/scripts/build/style.py @@ -14,7 +14,7 @@ def check_cpp_file(path: Path): try: text = path.read_text() except Exception: - return errors # skip non-text files + return errors lines = text.splitlines() @@ -83,10 +83,8 @@ def check_block(block, start_line, src_file): for i, line in enumerate(lines): if line.startswith("@source:"): - # clear previous block if current_block: errors.extend(check_block(current_block, block_start_line, current_source)) - # new block current_source = "src/mame/" + line[len("@source:"):].strip() current_block = [] @@ -113,7 +111,7 @@ def main(): for lineno, msg in errors: print(f"src/mame/mame.lst:{lineno}: {msg}") - sys.exit(0) # needed so workflow doesn't fail + sys.exit(0) if __name__ == "__main__": main() From be66388f4f3e722f4fae50cda74dcdadfa0e863c Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Mon, 1 Sep 2025 13:20:58 +0200 Subject: [PATCH 09/41] license --- scripts/build/style.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/build/style.py b/scripts/build/style.py index dcc546010a868..b5d1dfe23212e 100755 --- a/scripts/build/style.py +++ b/scripts/build/style.py @@ -1,4 +1,8 @@ #!/usr/bin/env python3 +## +## license:BSD-3-Clause +## copyright-holders:stonedDiscord + import re import sys from pathlib import Path From 3af2e02ca70771809f51d6d0efc24d6b9d0d4581 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Mon, 1 Sep 2025 13:33:43 +0200 Subject: [PATCH 10/41] filter files in script --- .github/workflows/style.yml | 5 +---- scripts/build/style.py | 10 +++++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 142f04b73f895..6e3e8ac2ee1a8 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -28,12 +28,9 @@ jobs: env: REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - files=$(echo ${{ steps.changed-files.outputs.all_changed_files }} | grep -E '\.(cpp|h)$' || true) - if [ -n "$files" ]; then - python3 scripts/build/style.py $files \ + python3 scripts/build/style.py ${{ steps.changed-files.outputs.all_changed_files }} \ | reviewdog -efm="%f:%l: %m" \ -name="cpp-style" \ -reporter=github-pr-review \ -filter-mode=diff_context \ -fail-on-error=false - fi diff --git a/scripts/build/style.py b/scripts/build/style.py index b5d1dfe23212e..ac9a5ea7de572 100755 --- a/scripts/build/style.py +++ b/scripts/build/style.py @@ -103,8 +103,16 @@ def check_block(block, start_line, src_file): def main(): cpp_files = {f for f in sys.argv[1:] if f.endswith(".cpp")} + h_files = {f for f in sys.argv[1:] if f.endswith(".h")} - for file in sys.argv[1:]: + for file in cpp_files: + path = Path(file) + errors = check_cpp_file(path) + + for lineno, msg in errors: + print(f"{path}:{lineno}: {msg}") + + for file in h_files: path = Path(file) errors = check_cpp_file(path) From 5473780c3f3770178d07e92385e4f86ee4141eb9 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Mon, 1 Sep 2025 13:35:11 +0200 Subject: [PATCH 11/41] less strong wording --- scripts/build/style.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build/style.py b/scripts/build/style.py index ac9a5ea7de572..4f6cb72ac3ef7 100755 --- a/scripts/build/style.py +++ b/scripts/build/style.py @@ -32,7 +32,7 @@ def check_cpp_file(path: Path): comment_pattern = re.compile(r"/\*.*\*/") if comment_pattern.search(line.strip()): - errors.append((i, "/* Single-line block comments */ are not allowed, use // instead")) + errors.append((i, "/* Single-line block comments */ should use // instead")) macro_pattern = re.compile(r"^\s*#define\s+([A-Za-z0-9_]+)") m = macro_pattern.match(line) From 86c15b45fcca1a17555d5f7814f9a62a4e73b663 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Mon, 1 Sep 2025 16:31:26 +0200 Subject: [PATCH 12/41] offer to fix the newline --- .github/workflows/style.yml | 11 +++++++---- scripts/build/style.py | 17 +++++++++++------ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 6e3e8ac2ee1a8..c3a008c9ce6ab 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -8,14 +8,12 @@ on: - 'src/**.h' jobs: - lint: + stylecheck: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - with: - fetch-depth: 0 - name: Install reviewdog uses: reviewdog/action-setup@v1.3.2 @@ -30,7 +28,12 @@ jobs: run: | python3 scripts/build/style.py ${{ steps.changed-files.outputs.all_changed_files }} \ | reviewdog -efm="%f:%l: %m" \ - -name="cpp-style" \ + -name="stylecheck" \ -reporter=github-pr-review \ -filter-mode=diff_context \ -fail-on-error=false + + - name: Make suggestions + uses: reviewdog/action-suggester@v1.22 + with: + tool_name: python3 scripts/build/style.py python3 scripts/build/style.py -f ${{ steps.changed-files.outputs.all_changed_files }} diff --git a/scripts/build/style.py b/scripts/build/style.py index 4f6cb72ac3ef7..8f609ec1ebfa2 100755 --- a/scripts/build/style.py +++ b/scripts/build/style.py @@ -13,7 +13,7 @@ def is_screaming_snake(name: str): def is_snake_case(name: str): return re.fullmatch(r"[a-z][a-z0-9_]*(_[a-z0-9]+)*", name) is not None -def check_cpp_file(path: Path): +def check_cpp_file(path: Path, fix: bool = False): errors = [] try: text = path.read_text() @@ -23,6 +23,8 @@ def check_cpp_file(path: Path): lines = text.splitlines() if not text.endswith("\n"): + if fix: + path.write_text(text + "\n") errors.append((len(lines) or 1, "File should end with a newline")) for i, line in enumerate(lines, 1): @@ -102,19 +104,22 @@ def check_block(block, start_line, src_file): return errors def main(): - cpp_files = {f for f in sys.argv[1:] if f.endswith(".cpp")} - h_files = {f for f in sys.argv[1:] if f.endswith(".h")} + fix = "-f" in sys.argv + args = [f for f in sys.argv[1:] if f != "-f"] + + cpp_files = {f for f in args if f.endswith(".cpp")} + h_files = {f for f in args if f.endswith(".h")} for file in cpp_files: path = Path(file) - errors = check_cpp_file(path) + errors = check_cpp_file(path, fix=fix) for lineno, msg in errors: print(f"{path}:{lineno}: {msg}") for file in h_files: path = Path(file) - errors = check_cpp_file(path) + errors = check_cpp_file(path, fix=fix) for lineno, msg in errors: print(f"{path}:{lineno}: {msg}") @@ -126,4 +131,4 @@ def main(): sys.exit(0) if __name__ == "__main__": - main() + main() \ No newline at end of file From e6323755a31550257de45190ed4cae4912387be8 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Mon, 1 Sep 2025 16:47:05 +0200 Subject: [PATCH 13/41] tool_name works different --- .github/workflows/style.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index c3a008c9ce6ab..4e7d5be9f94e5 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -26,7 +26,7 @@ jobs: env: REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - python3 scripts/build/style.py ${{ steps.changed-files.outputs.all_changed_files }} \ + python3 scripts/build/style.py -f ${{ steps.changed-files.outputs.all_changed_files }} \ | reviewdog -efm="%f:%l: %m" \ -name="stylecheck" \ -reporter=github-pr-review \ @@ -35,5 +35,3 @@ jobs: - name: Make suggestions uses: reviewdog/action-suggester@v1.22 - with: - tool_name: python3 scripts/build/style.py python3 scripts/build/style.py -f ${{ steps.changed-files.outputs.all_changed_files }} From 5be1476e405a6b9ba9a8223357d4c077361612d0 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Mon, 1 Sep 2025 17:11:05 +0200 Subject: [PATCH 14/41] newline fix was merged in feb --- .github/workflows/style.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 4e7d5be9f94e5..e0c332644e7d0 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -17,6 +17,8 @@ jobs: - name: Install reviewdog uses: reviewdog/action-setup@v1.3.2 + with: + reviewdog_version: nightly - name: Get changed files id: changed-files From 6488652eefbe2d1139fdd56844123dd5479bb602 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Mon, 1 Sep 2025 17:26:54 +0200 Subject: [PATCH 15/41] consider hpp files --- scripts/build/style.py | 48 ++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/scripts/build/style.py b/scripts/build/style.py index 8f609ec1ebfa2..313a9457a2ebb 100755 --- a/scripts/build/style.py +++ b/scripts/build/style.py @@ -13,7 +13,7 @@ def is_screaming_snake(name: str): def is_snake_case(name: str): return re.fullmatch(r"[a-z][a-z0-9_]*(_[a-z0-9]+)*", name) is not None -def check_cpp_file(path: Path, fix: bool = False): +def check_file(path: Path, fix: bool = False): errors = [] try: text = path.read_text() @@ -27,6 +27,17 @@ def check_cpp_file(path: Path, fix: bool = False): path.write_text(text + "\n") errors.append((len(lines) or 1, "File should end with a newline")) + return errors + +def check_cpp_file(path: Path, fix: bool = False): + errors = [] + try: + text = path.read_text() + except Exception: + return errors + + lines = text.splitlines() + for i, line in enumerate(lines, 1): hex_pattern = re.compile(r"0x[A-F]+") if hex_pattern.search(line): @@ -63,10 +74,24 @@ def check_cpp_file(path: Path, fix: bool = False): return errors +def check_block(block, start_line, src_file): + if not src_file or src_file not in changed_cpp_files: + return [] + sorted_block = sorted(block, key=lambda s: s.lower()) + errors_local = [] + for offset, (expected, actual) in enumerate(zip(sorted_block, block)): + if expected != actual: + line_no = start_line + offset + 1 + errors_local.append( + (line_no, f"Entry '{actual}' is out of order, expected '{expected}'") + ) + return errors_local + def check_mame_lst(changed_cpp_files: set[str]): - errors = [] + path = Path("src/mame/mame.lst") + errors = check_file(path, False) try: - lines = Path("src/mame/mame.lst").read_text().splitlines() + lines = path.read_text().splitlines() except Exception: return errors @@ -74,19 +99,6 @@ def check_mame_lst(changed_cpp_files: set[str]): block_start_line = 0 current_source = None - def check_block(block, start_line, src_file): - if not src_file or src_file not in changed_cpp_files: - return [] - sorted_block = sorted(block, key=lambda s: s.lower()) - errors_local = [] - for offset, (expected, actual) in enumerate(zip(sorted_block, block)): - if expected != actual: - line_no = start_line + offset + 1 - errors_local.append( - (line_no, f"Entry '{actual}' is out of order, expected '{expected}'") - ) - return errors_local - for i, line in enumerate(lines): if line.startswith("@source:"): if current_block: @@ -107,8 +119,8 @@ def main(): fix = "-f" in sys.argv args = [f for f in sys.argv[1:] if f != "-f"] - cpp_files = {f for f in args if f.endswith(".cpp")} - h_files = {f for f in args if f.endswith(".h")} + cpp_files = {f for f in args if f.endswith(".c") or f.endswith(".cpp")} + h_files = {f for f in args if f.endswith(".h") or f.endswith(".hpp") or f.endswith(".hxx")} for file in cpp_files: path = Path(file) From f51c436d8e7f53ad074830d61999b2b79f640918 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Mon, 1 Sep 2025 17:27:53 +0200 Subject: [PATCH 16/41] oops --- scripts/build/style.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/build/style.py b/scripts/build/style.py index 313a9457a2ebb..707e6a1d12d7a 100755 --- a/scripts/build/style.py +++ b/scripts/build/style.py @@ -74,7 +74,7 @@ def check_cpp_file(path: Path, fix: bool = False): return errors -def check_block(block, start_line, src_file): +def check_block(block, changed_cpp_files, start_line, src_file): if not src_file or src_file not in changed_cpp_files: return [] sorted_block = sorted(block, key=lambda s: s.lower()) @@ -102,7 +102,7 @@ def check_mame_lst(changed_cpp_files: set[str]): for i, line in enumerate(lines): if line.startswith("@source:"): if current_block: - errors.extend(check_block(current_block, block_start_line, current_source)) + errors.extend(check_block(current_block, changed_cpp_files, block_start_line, current_source)) current_source = "src/mame/" + line[len("@source:"):].strip() current_block = [] @@ -111,7 +111,7 @@ def check_mame_lst(changed_cpp_files: set[str]): current_block.append(line.strip()) if current_block: - errors.extend(check_block(current_block, block_start_line, current_source)) + errors.extend(check_block(current_block, changed_cpp_files, block_start_line, current_source)) return errors From 27cfee6d91622014625fe9a23ffb743d93c30b76 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Mon, 1 Sep 2025 17:41:17 +0200 Subject: [PATCH 17/41] didnt i remove this already --- .github/workflows/style.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index e0c332644e7d0..de789c5ea9de3 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -32,7 +32,7 @@ jobs: | reviewdog -efm="%f:%l: %m" \ -name="stylecheck" \ -reporter=github-pr-review \ - -filter-mode=diff_context \ + -filter-mode=nofilter \ -fail-on-error=false - name: Make suggestions From e268fb6e3ca7334f1394dc5c34e8ce2079c628c3 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Mon, 1 Sep 2025 17:53:39 +0200 Subject: [PATCH 18/41] lst --- scripts/build/style.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/build/style.py b/scripts/build/style.py index 707e6a1d12d7a..9f9c70bfe702b 100755 --- a/scripts/build/style.py +++ b/scripts/build/style.py @@ -74,7 +74,7 @@ def check_cpp_file(path: Path, fix: bool = False): return errors -def check_block(block, changed_cpp_files, start_line, src_file): +def check_lst_block(block, changed_cpp_files, start_line, src_file): if not src_file or src_file not in changed_cpp_files: return [] sorted_block = sorted(block, key=lambda s: s.lower()) @@ -102,7 +102,7 @@ def check_mame_lst(changed_cpp_files: set[str]): for i, line in enumerate(lines): if line.startswith("@source:"): if current_block: - errors.extend(check_block(current_block, changed_cpp_files, block_start_line, current_source)) + errors.extend(check_lst_block(current_block, changed_cpp_files, block_start_line, current_source)) current_source = "src/mame/" + line[len("@source:"):].strip() current_block = [] @@ -111,7 +111,7 @@ def check_mame_lst(changed_cpp_files: set[str]): current_block.append(line.strip()) if current_block: - errors.extend(check_block(current_block, changed_cpp_files, block_start_line, current_source)) + errors.extend(check_lst_block(current_block, changed_cpp_files, block_start_line, current_source)) return errors From c80e14b2b749da307a31de0dc2a3cb8b48230b2f Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Mon, 1 Sep 2025 17:57:39 +0200 Subject: [PATCH 19/41] check utf8, line endings and whitespaces --- scripts/build/style.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/build/style.py b/scripts/build/style.py index 9f9c70bfe702b..7c2321c05ada4 100755 --- a/scripts/build/style.py +++ b/scripts/build/style.py @@ -16,10 +16,21 @@ def is_snake_case(name: str): def check_file(path: Path, fix: bool = False): errors = [] try: - text = path.read_text() + raw_bytes = path.read_bytes() + try: + text = raw_bytes.decode("utf-8", errors="strict") + except UnicodeDecodeError as e: + errors.append((1, f"Invalid UTF-8 sequence at byte {e.start}-{e.end}")) + return errors except Exception: return errors + # Detect non-native line endings + if sys.platform != "win32" and b"\r\n" in raw_bytes: + errors.append((1, "File contains Windows (CRLF) line endings on a non-Windows system")) + elif sys.platform == "win32" and b"\n" in raw_bytes and b"\r\n" not in raw_bytes: + errors.append((1, "File contains Unix (LF) line endings on Windows")) + lines = text.splitlines() if not text.endswith("\n"): @@ -27,6 +38,12 @@ def check_file(path: Path, fix: bool = False): path.write_text(text + "\n") errors.append((len(lines) or 1, "File should end with a newline")) + for i, line in enumerate(lines, 1): + if line.rstrip() != line: + if fix: + lines[i - 1] = line.rstrip() + errors.append((i, "Trailing whitespace detected")) + return errors def check_cpp_file(path: Path, fix: bool = False): From f4b220ab700999f7bb4e946a1bdd358a1b5e4030 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Mon, 1 Sep 2025 18:02:00 +0200 Subject: [PATCH 20/41] do not fix whitespaces and check other files --- scripts/build/style.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/build/style.py b/scripts/build/style.py index 7c2321c05ada4..29c55cdf9b121 100755 --- a/scripts/build/style.py +++ b/scripts/build/style.py @@ -40,8 +40,6 @@ def check_file(path: Path, fix: bool = False): for i, line in enumerate(lines, 1): if line.rstrip() != line: - if fix: - lines[i - 1] = line.rstrip() errors.append((i, "Trailing whitespace detected")) return errors @@ -137,7 +135,8 @@ def main(): args = [f for f in sys.argv[1:] if f != "-f"] cpp_files = {f for f in args if f.endswith(".c") or f.endswith(".cpp")} - h_files = {f for f in args if f.endswith(".h") or f.endswith(".hpp") or f.endswith(".hxx")} + h_files = {f for f in args if f.endswith(".h") or f.endswith(".hpp") or f.endswith(".hxx") or f.endswith(".ipp")} + other_files = {f for f in args if f.endswith(".py") or f.endswith(".lua") or f.endswith(".mm") or f.endswith(".lay") or f.endswith(".lst")} for file in cpp_files: path = Path(file) @@ -153,6 +152,13 @@ def main(): for lineno, msg in errors: print(f"{path}:{lineno}: {msg}") + for file in other_files: + path = Path(file) + errors = check_file(path, fix=fix) + + for lineno, msg in errors: + print(f"{path}:{lineno}: {msg}") + errors = check_mame_lst(cpp_files) for lineno, msg in errors: print(f"src/mame/mame.lst:{lineno}: {msg}") From 1dfbfcaed5e52aec31e1a407524586476435ed1c Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Mon, 1 Sep 2025 18:03:19 +0200 Subject: [PATCH 21/41] HUH --- scripts/build/style.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build/style.py b/scripts/build/style.py index 29c55cdf9b121..ff215334ef93a 100755 --- a/scripts/build/style.py +++ b/scripts/build/style.py @@ -45,7 +45,7 @@ def check_file(path: Path, fix: bool = False): return errors def check_cpp_file(path: Path, fix: bool = False): - errors = [] + errors = check_file(path, fix) try: text = path.read_text() except Exception: From a8193b6e5351dd18d63b738b9b0a9cb376a7f1a9 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 2 Sep 2025 00:05:15 +0200 Subject: [PATCH 22/41] disable suggestions --- .github/workflows/style.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index de789c5ea9de3..e1f3357ed7297 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -28,12 +28,10 @@ jobs: env: REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - python3 scripts/build/style.py -f ${{ steps.changed-files.outputs.all_changed_files }} \ + python3 scripts/build/style.py ${{ steps.changed-files.outputs.all_changed_files }} \ | reviewdog -efm="%f:%l: %m" \ -name="stylecheck" \ -reporter=github-pr-review \ -filter-mode=nofilter \ -fail-on-error=false - - name: Make suggestions - uses: reviewdog/action-suggester@v1.22 From 98b684804fcf99ca53e476588fa68dc8e58e27f1 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 2 Sep 2025 00:16:07 +0200 Subject: [PATCH 23/41] wording --- scripts/build/style.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/build/style.py b/scripts/build/style.py index ff215334ef93a..71bbb498f4e48 100755 --- a/scripts/build/style.py +++ b/scripts/build/style.py @@ -25,7 +25,6 @@ def check_file(path: Path, fix: bool = False): except Exception: return errors - # Detect non-native line endings if sys.platform != "win32" and b"\r\n" in raw_bytes: errors.append((1, "File contains Windows (CRLF) line endings on a non-Windows system")) elif sys.platform == "win32" and b"\n" in raw_bytes and b"\r\n" not in raw_bytes: @@ -40,7 +39,7 @@ def check_file(path: Path, fix: bool = False): for i, line in enumerate(lines, 1): if line.rstrip() != line: - errors.append((i, "Trailing whitespace detected")) + errors.append((i, "Lines should not have trailing whitespaces")) return errors From e8e442d77f1b7e21a8701bcdd72fcdb38ada4416 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 2 Sep 2025 14:31:39 +0200 Subject: [PATCH 24/41] the irony --- scripts/build/style.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build/style.py b/scripts/build/style.py index 71bbb498f4e48..7df782a68f7dd 100755 --- a/scripts/build/style.py +++ b/scripts/build/style.py @@ -165,4 +165,4 @@ def main(): sys.exit(0) if __name__ == "__main__": - main() \ No newline at end of file + main() From 92309611ab7447fd02fa82c4622a92fe35233e46 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 2 Sep 2025 15:37:46 +0200 Subject: [PATCH 25/41] remove ext deps --- .github/workflows/style.yml | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index e1f3357ed7297..83b52ecf78524 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -15,23 +15,19 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Install reviewdog - uses: reviewdog/action-setup@v1.3.2 - with: - reviewdog_version: nightly - - name: Get changed files id: changed-files - uses: tj-actions/changed-files@v46.0.5 + uses: actions/github-script@v7 + with: + result-encoding: string + script: | + const { execSync } = require('child_process') + const { commits } = context.payload.pull_request + const rawFiles = execSync(`git diff --name-only HEAD HEAD~${commits}`).toString() + return rawFiles.split('\n').filter(Boolean) - name: Run style check env: - REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - python3 scripts/build/style.py ${{ steps.changed-files.outputs.all_changed_files }} \ - | reviewdog -efm="%f:%l: %m" \ - -name="stylecheck" \ - -reporter=github-pr-review \ - -filter-mode=nofilter \ - -fail-on-error=false - + python3 scripts/build/style.py ${{ steps.changed-files.outputs.result }} \ No newline at end of file From 9c7a077fa85b4edf9bebaa5b51083a1113426def Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 2 Sep 2025 15:50:31 +0200 Subject: [PATCH 26/41] WIP --- .github/workflows/style.yml | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 83b52ecf78524..e43894922978c 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -21,13 +21,33 @@ jobs: with: result-encoding: string script: | - const { execSync } = require('child_process') - const { commits } = context.payload.pull_request - const rawFiles = execSync(`git diff --name-only HEAD HEAD~${commits}`).toString() - return rawFiles.split('\n').filter(Boolean) + const { execSync } = require('child_process'); + const { commits } = context.payload.pull_request; + const rawFiles = execSync(`git diff --name-only HEAD HEAD~${commits}`).toString(); + return rawFiles.split('\n').filter(Boolean); - name: Run style check + id: style-check env: GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - python3 scripts/build/style.py ${{ steps.changed-files.outputs.result }} \ No newline at end of file + python3 scripts/build/style.py ${{ steps.changed-files.outputs.result }} + + - name: Post review comments + uses: actions/github-script@v7 + id: post-comments + env: + REVIEWS: ${{ steps.style-check.outputs.result }} + with: + result-encoding: string + script: | + const reviews = process.env.REVIEWS; + console.log(reviews); + github.rest.pulls.createReviewComment({ + context.repo.owner, + context.repo.repo, + context.payload.pull_request.number, + body, + commit_id, + path, + }); From 5ffed742ca5bd2f45e65c88f1c7cb3afb1a838ca Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 2 Sep 2025 15:57:41 +0200 Subject: [PATCH 27/41] post the warnings from the script --- .github/workflows/style.yml | 19 ------------------- scripts/build/style.py | 12 ++++++++---- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index e43894922978c..97edd624139b5 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -32,22 +32,3 @@ jobs: GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | python3 scripts/build/style.py ${{ steps.changed-files.outputs.result }} - - - name: Post review comments - uses: actions/github-script@v7 - id: post-comments - env: - REVIEWS: ${{ steps.style-check.outputs.result }} - with: - result-encoding: string - script: | - const reviews = process.env.REVIEWS; - console.log(reviews); - github.rest.pulls.createReviewComment({ - context.repo.owner, - context.repo.repo, - context.payload.pull_request.number, - body, - commit_id, - path, - }); diff --git a/scripts/build/style.py b/scripts/build/style.py index 7df782a68f7dd..347e9c0d7c980 100755 --- a/scripts/build/style.py +++ b/scripts/build/style.py @@ -129,6 +129,10 @@ def check_mame_lst(changed_cpp_files: set[str]): return errors +def print_warning(path,lineno,msg): + print(f"::warning file={path},line={lineno},col=1,endColumn=99,title=style::{msg}") + + def main(): fix = "-f" in sys.argv args = [f for f in sys.argv[1:] if f != "-f"] @@ -142,25 +146,25 @@ def main(): errors = check_cpp_file(path, fix=fix) for lineno, msg in errors: - print(f"{path}:{lineno}: {msg}") + print_warning(path,lineno,msg) for file in h_files: path = Path(file) errors = check_cpp_file(path, fix=fix) for lineno, msg in errors: - print(f"{path}:{lineno}: {msg}") + print_warning(path,lineno,msg) for file in other_files: path = Path(file) errors = check_file(path, fix=fix) for lineno, msg in errors: - print(f"{path}:{lineno}: {msg}") + print_warning(path,lineno,msg) errors = check_mame_lst(cpp_files) for lineno, msg in errors: - print(f"src/mame/mame.lst:{lineno}: {msg}") + print_warning("src/mame/mame.lst",lineno,msg) sys.exit(0) From 3321f8c7c091242fb5f9e265a812b12baf14fcc8 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 2 Sep 2025 18:24:37 +0200 Subject: [PATCH 28/41] fix changed files? --- .github/workflows/style.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 97edd624139b5..47a15f0791265 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -17,18 +17,11 @@ jobs: - name: Get changed files id: changed-files - uses: actions/github-script@v7 - with: - result-encoding: string - script: | - const { execSync } = require('child_process'); - const { commits } = context.payload.pull_request; - const rawFiles = execSync(`git diff --name-only HEAD HEAD~${commits}`).toString(); - return rawFiles.split('\n').filter(Boolean); + run: echo "changed_files=$(git diff --name-only HEAD^1 HEAD | xargs)" >> $GITHUB_OUTPUT - name: Run style check id: style-check env: GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - python3 scripts/build/style.py ${{ steps.changed-files.outputs.result }} + python3 scripts/build/style.py ${{ steps.changed-files.outputs.changed_files }} From 5531a3d31ff5d4303bcd5e60c847ac24e4e7ae40 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 2 Sep 2025 18:36:25 +0200 Subject: [PATCH 29/41] use gh command over git --- .github/workflows/style.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 47a15f0791265..0e9614bef9dd7 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -17,7 +17,7 @@ jobs: - name: Get changed files id: changed-files - run: echo "changed_files=$(git diff --name-only HEAD^1 HEAD | xargs)" >> $GITHUB_OUTPUT + run: echo "changed_files=$(gh pr diff --name-only | xargs)" >> $GITHUB_OUTPUT - name: Run style check id: style-check From 03089b9e73ae93520b48ed936b3a51953d99e810 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 2 Sep 2025 18:38:12 +0200 Subject: [PATCH 30/41] missing token --- .github/workflows/style.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 0e9614bef9dd7..5aa1360bcfdee 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -17,11 +17,11 @@ jobs: - name: Get changed files id: changed-files + env: + GH_TOKEN: ${{ github.token }} run: echo "changed_files=$(gh pr diff --name-only | xargs)" >> $GITHUB_OUTPUT - name: Run style check id: style-check - env: - GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | python3 scripts/build/style.py ${{ steps.changed-files.outputs.changed_files }} From c335f651583d98e8fc486fc0dd97622f91aa93f7 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 2 Sep 2025 18:42:44 +0200 Subject: [PATCH 31/41] try yet another method --- .github/workflows/style.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 5aa1360bcfdee..88c04abca9d18 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -17,9 +17,7 @@ jobs: - name: Get changed files id: changed-files - env: - GH_TOKEN: ${{ github.token }} - run: echo "changed_files=$(gh pr diff --name-only | xargs)" >> $GITHUB_OUTPUT + run: echo "::set-output name=changed_files::$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | xargs)" - name: Run style check id: style-check From 6bc0ec407b78d84ef478023d46ca95f8c3760a04 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 2 Sep 2025 18:46:11 +0200 Subject: [PATCH 32/41] use my HEAD for a bit --- .github/workflows/style.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 88c04abca9d18..b8db691b8a907 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -17,7 +17,7 @@ jobs: - name: Get changed files id: changed-files - run: echo "::set-output name=changed_files::$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | xargs)" + run: echo "::set-output name=changed_files::$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | xargs)" - name: Run style check id: style-check From eb564f21da253772b5901ab86e6fe10588cb6c7e Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 2 Sep 2025 18:47:26 +0200 Subject: [PATCH 33/41] deprecated --- .github/workflows/style.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index b8db691b8a907..3b50926ed2c37 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -17,7 +17,7 @@ jobs: - name: Get changed files id: changed-files - run: echo "::set-output name=changed_files::$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | xargs)" + run: echo "changed_files=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | xargs)" >> $GITHUB_OUTPUT - name: Run style check id: style-check From 84e9228505dc90b553fff28d69b71ea58e2d724c Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 2 Sep 2025 18:59:13 +0200 Subject: [PATCH 34/41] use 3 dot compare and fetch more data --- .github/workflows/style.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 3b50926ed2c37..77eac82b30a53 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -14,10 +14,12 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 2 - name: Get changed files id: changed-files - run: echo "changed_files=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | xargs)" >> $GITHUB_OUTPUT + run: echo "changed_files=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }}...HEAD | xargs)" >> $GITHUB_OUTPUT - name: Run style check id: style-check From 57bcdf5c46248f4706e201f3d9895df1c4721929 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 2 Sep 2025 19:14:29 +0200 Subject: [PATCH 35/41] use error --- scripts/build/style.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/scripts/build/style.py b/scripts/build/style.py index 347e9c0d7c980..f7dece3c2da6a 100755 --- a/scripts/build/style.py +++ b/scripts/build/style.py @@ -129,9 +129,8 @@ def check_mame_lst(changed_cpp_files: set[str]): return errors -def print_warning(path,lineno,msg): - print(f"::warning file={path},line={lineno},col=1,endColumn=99,title=style::{msg}") - +def print_review(path,lineno,msg): + print(f"::error file={path},line={lineno}::{msg}") def main(): fix = "-f" in sys.argv @@ -146,25 +145,25 @@ def main(): errors = check_cpp_file(path, fix=fix) for lineno, msg in errors: - print_warning(path,lineno,msg) + print_review(path,lineno,msg) for file in h_files: path = Path(file) errors = check_cpp_file(path, fix=fix) for lineno, msg in errors: - print_warning(path,lineno,msg) + print_review(path,lineno,msg) for file in other_files: path = Path(file) errors = check_file(path, fix=fix) for lineno, msg in errors: - print_warning(path,lineno,msg) + print_review(path,lineno,msg) errors = check_mame_lst(cpp_files) for lineno, msg in errors: - print_warning("src/mame/mame.lst",lineno,msg) + print_review("src/mame/mame.lst",lineno,msg) sys.exit(0) From 9fda6ddc9dbf5aaff3c79c1a900d147db0cd38fb Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 2 Sep 2025 19:29:26 +0200 Subject: [PATCH 36/41] one big review --- .github/workflows/style.yml | 32 ++++++++++++++++++++++++++++++-- scripts/build/style.py | 6 ++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 77eac82b30a53..995db9873f14a 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -23,5 +23,33 @@ jobs: - name: Run style check id: style-check - run: | - python3 scripts/build/style.py ${{ steps.changed-files.outputs.changed_files }} + run: echo "reviews=$(python3 scripts/build/style.py ${{ steps.changed-files.outputs.changed_files }} | jq -s .)" >> $GITHUB_OUTPUT + + - name: Post review comments + uses: actions/github-script@v7 + id: post-comments + env: + REVIEWS: ${{ steps.style-check.outputs.reviews }} + with: + script: | + const reviews = JSON.parse(process.env.REVIEWS || "[]"); + console.log("review log", reviews); + + const comments = reviews.map(r => ({ + body: r.body, + path: r.path, + line: r.line, + side: "RIGHT", + })); + + if (comments.length > 0) { + await github.rest.pulls.createReview({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + event: "COMMENT", + comments, + }); + } else { + console.log("Nothing wrong."); + } \ No newline at end of file diff --git a/scripts/build/style.py b/scripts/build/style.py index f7dece3c2da6a..ee4a0eab979c0 100755 --- a/scripts/build/style.py +++ b/scripts/build/style.py @@ -3,6 +3,7 @@ ## license:BSD-3-Clause ## copyright-holders:stonedDiscord +import json import re import sys from pathlib import Path @@ -129,8 +130,9 @@ def check_mame_lst(changed_cpp_files: set[str]): return errors -def print_review(path,lineno,msg): - print(f"::error file={path},line={lineno}::{msg}") +def print_review(path, lineno, msg): + review = {"body": str(msg), "path": str(path), "line": int(lineno)} + print(json.dumps(review)) def main(): fix = "-f" in sys.argv From 8592d1205889b54ff4065356f5b6cf73eb8fb8b9 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 2 Sep 2025 19:32:25 +0200 Subject: [PATCH 37/41] one line please --- .github/workflows/style.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 995db9873f14a..9c294620d0dee 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -23,7 +23,7 @@ jobs: - name: Run style check id: style-check - run: echo "reviews=$(python3 scripts/build/style.py ${{ steps.changed-files.outputs.changed_files }} | jq -s .)" >> $GITHUB_OUTPUT + run: echo "reviews=$(python3 scripts/build/style.py ${{ steps.changed-files.outputs.changed_files }} | jq -s -c .)" >> $GITHUB_OUTPUT - name: Post review comments uses: actions/github-script@v7 From 292c580eb996f388d3927896e2139edde84d3033 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 2 Sep 2025 19:40:01 +0200 Subject: [PATCH 38/41] ugly log --- .github/workflows/style.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 9c294620d0dee..52439a96487f6 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -33,7 +33,6 @@ jobs: with: script: | const reviews = JSON.parse(process.env.REVIEWS || "[]"); - console.log("review log", reviews); const comments = reviews.map(r => ({ body: r.body, @@ -43,6 +42,7 @@ jobs: })); if (comments.length > 0) { + console.debug("Reviews: ", reviews); await github.rest.pulls.createReview({ owner: context.repo.owner, repo: context.repo.repo, @@ -51,5 +51,5 @@ jobs: comments, }); } else { - console.log("Nothing wrong."); + console.info("Review list empty."); } \ No newline at end of file From c53fabd2bce2c603548762d51a3a147e3d75a359 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 2 Sep 2025 19:40:54 +0200 Subject: [PATCH 39/41] forgot newline in yml file --- .github/workflows/style.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 52439a96487f6..3907ba6c902b3 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -52,4 +52,4 @@ jobs: }); } else { console.info("Review list empty."); - } \ No newline at end of file + } From e1649eda1ed683c9ab270f54b3526ee744447c73 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 2 Sep 2025 19:41:55 +0200 Subject: [PATCH 40/41] also check yml files --- scripts/build/style.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build/style.py b/scripts/build/style.py index ee4a0eab979c0..c2302b22e67c2 100755 --- a/scripts/build/style.py +++ b/scripts/build/style.py @@ -140,7 +140,7 @@ def main(): cpp_files = {f for f in args if f.endswith(".c") or f.endswith(".cpp")} h_files = {f for f in args if f.endswith(".h") or f.endswith(".hpp") or f.endswith(".hxx") or f.endswith(".ipp")} - other_files = {f for f in args if f.endswith(".py") or f.endswith(".lua") or f.endswith(".mm") or f.endswith(".lay") or f.endswith(".lst")} + other_files = {f for f in args if f.endswith(".lua") or f.endswith(".lay") or f.endswith(".lst") or f.endswith(".mm") or f.endswith(".py") or f.endswith(".yml")} for file in cpp_files: path = Path(file) From b0330343da5281f6940a04ed80a45b0ec1913938 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Thu, 4 Sep 2025 21:26:42 +0200 Subject: [PATCH 41/41] misread the documentation --- scripts/build/style.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/build/style.py b/scripts/build/style.py index c2302b22e67c2..56c9cd4925a07 100755 --- a/scripts/build/style.py +++ b/scripts/build/style.py @@ -67,10 +67,10 @@ def check_cpp_file(path: Path, fix: bool = False): if m and not is_screaming_snake(m.group(1)): errors.append((i, f"Macro '{m.group(1)}' should use SCREAMING_SNAKE_CASE")) - const_pattern = re.compile(r"\bconst\b[^;=()]*\b([A-Za-z_][A-Za-z0-9_]*)\b\s*(?:=|;)") + const_pattern = re.compile(r"\bconstexpr\b[^;=()]*\b([A-Za-z_][A-Za-z0-9_]*)\b\s*(?:=|;)") c = const_pattern.search(line) if c and not is_screaming_snake(c.group(1)): - errors.append((i, f"Constant '{c.group(1)}' should use SCREAMING_SNAKE_CASE")) + errors.append((i, f"Constant expression '{c.group(1)}' should use SCREAMING_SNAKE_CASE")) function_pattern = re.compile(r"\b([a-z][a-z0-9_]*)\s*\(") f = function_pattern.search(line)