Skip to content

Add Rust-backed C++ linter subset - #2689

Merged
zackees merged 6 commits into
masterfrom
feat/lint-cpp-rs
Jun 3, 2026
Merged

zackees merged 6 commits into
masterfrom
feat/lint-cpp-rs

Conversation

@zackees

@zackees zackees commented Jun 3, 2026 •

Copy link
Copy Markdown
Member

Refs #2488

Summary:

  • Add ci/lint_cpp_rs/ with a fastled-lint Rust binary, FileContentChecker trait, cached file processor, rayon parallel file processing, text/JSON output, checker selection, and --list-checkers.
  • Port the first Rust-backed checker subset: serial_printf, using_namespace_fl_in_examples, banned_macros, include_paths, bare_allocation, static_in_headers, builtin_memcpy, weak_attribute, banned_define, banned_namespace, cpp_include, impl_hpp_includes, asm_js_location, reinterpret_cast, and pragma_once.
  • Wire bash lint --cpp --rust / run_all_checkers.py --rust through soldr cargo run --release --bin fastled-lint --manifest-path ci/lint_cpp_rs/Cargo.toml.
  • Add FL_LINT_AB=1 parity mode and Python parity tests that compare normalized Rust JSON against the Python checker oracle.

Notes:

Tests:

  • soldr cargo test --manifest-path ci/lint_cpp_rs/Cargo.toml
  • uv run python -m pytest ci/lint_cpp/test_rust_parity.py -q
  • uv run ruff check ci/lint_cpp/rust_bridge.py ci/lint_cpp/test_rust_parity.py ci/lint/args_parser.py ci/lint.py ci/lint/stage_impls.py ci/lint_cpp/run_all_checkers.py
  • soldr cargo run --release --bin fastled-lint --manifest-path ci/lint_cpp_rs/Cargo.toml -- --list-checkers
  • uv run python ci/lint_cpp/run_all_checkers.py --rust src/color.h
  • $env:FL_LINT_AB='1'; uv run python ci/lint_cpp/run_all_checkers.py src/color.h
  • uv run python ci/lint_cpp/run_all_checkers.py --rust
  • $env:FL_LINT_AB='1'; uv run python ci/lint_cpp/run_all_checkers.py

Summary by CodeRabbit

  • New Features

    • Added a --rust option to enable a Rust-backed C++ linter (bash lint --cpp --rust).
    • Introduced a fastled-lint Rust binary: parallel, faster linting with JSON output and selectable checkers.
    • Optional merging of Rust and Python checker results with an AB parity mode.
  • Bug Fixes

    • Do not flag includes or FastLED usage when they appear inside block comments.
  • Tests

    • Added parity tests validating Rust linter matches Python checker output.
  • Chores

    • Updated ignore rules to exclude Rust build artifacts.

@coderabbitai

coderabbitai Bot commented Jun 3, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 51bd6426-8855-41c7-8e22-668aeda1da00

📥 Commits

Reviewing files that changed from the base of the PR and between 28cdc5a and defc3d7.

📒 Files selected for processing (4)
  • ci/lint_cpp/fastled_header_usage_checker.py
  • ci/lint_cpp/relative_include_checker.py
  • ci/lint_cpp/test_rust_parity.py
  • ci/lint_cpp_rs/src/lib.rs

📝 Walkthrough

Walkthrough

Adds a Rust crate implementing fastled-lint, wires a new --rust option through the Python lint CLI and stage runners, integrates Rust results via a bridge (merge + optional AB parity), adds parity tests, and ignores Rust build artifacts in .gitignore.

Changes

Rust-based C++ Linter Implementation and Python Integration

Layer / File(s) Summary
Python CLI argument wiring and local invocations
ci/lint/args_parser.py, ci/lint.py, ci/lint/stage_impls.py, .gitignore
Adds --rust flag and use_rust_cpp_lint arg, threads it through single-file and multi-stage lint paths, updates help/AI hints, and ignores ci/lint_cpp_rs/target/.
Python-Rust orchestration and result merging
ci/lint_cpp/run_all_checkers.py, ci/lint_cpp/rust_bridge.py
Invokes the Rust linter, removes Rust-supported Python checkers, merges Rust and Python violations, and supports an AB parity gate controlled by FL_LINT_AB.
Rust linter core: data models, checkers, and CLI
ci/lint_cpp_rs/src/lib.rs
Introduces fastled-lint crate with FileContent model, FileContentChecker trait, a multi-checker processor, file discovery, helpers, and ~16 concrete checkers plus unit tests.
Rust crate manifest and binary entrypoint
ci/lint_cpp_rs/Cargo.toml, ci/lint_cpp_rs/src/main.rs
Adds Cargo manifest and main that invokes fastled_lint::run_cli and maps results to exit codes.
Rust-Python parity test suite
ci/lint_cpp/test_rust_parity.py
Parametrized pytest comparing Rust JSON output to Python checker oracle with path normalization, temporary project layout, and environment monkeypatching.

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Possibly related issues

Poem

I'm a rabbit with a linting quest,
I hop through code to keep it neat,
Rust and Python sniff out the mess,
Merged results help make builds complete,
Carrots for clean trees, hop, repeat 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.66% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add Rust-backed C++ linter subset' directly and accurately describes the main change: adding a new Rust-based C++ linter implementation as a foundational prototype for gradual migration.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/lint-cpp-rs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
ci/lint/args_parser.py (1)

9-10: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Add @typechecked decorator to LintArgs dataclass.

As per coding guidelines, dataclasses must use the @typechecked decorator for runtime type validation.

♻️ Proposed fix
+from typeguard import typechecked
+
+@typechecked
 `@dataclass`
 class LintArgs:

As per coding guidelines: "Use @typechecked decorator with @dataclass for runtime type validation"

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/lint/args_parser.py` around lines 9 - 10, The LintArgs dataclass is
missing the required `@typechecked` decorator; update the definition by importing
and applying typechecked to the LintArgs dataclass so runtime type validation is
enforced (ensure you add the import for typechecked and annotate the class with
`@typechecked` above `@dataclass` on the LintArgs declaration).
🧹 Nitpick comments (2)
ci/lint_cpp/rust_bridge.py (1)

37-46: 💤 Low value

Replace list comprehension with explicit loop.

Per coding guidelines, use explicit loops instead of list comprehensions for code clarity and debuggability.

♻️ Proposed fix
 def remove_rust_supported_checkers(
     checkers_by_scope: dict[str, list[FileContentChecker]],
 ) -> None:
     """Remove checker instances handled by the Rust fast path."""
     for scope, checkers in checkers_by_scope.items():
-        checkers_by_scope[scope] = [
-            checker
-            for checker in checkers
-            if checker.__class__.__name__ not in RUST_SUPPORTED_CHECKERS
-        ]
+        filtered: list[FileContentChecker] = []
+        for checker in checkers:
+            if checker.__class__.__name__ not in RUST_SUPPORTED_CHECKERS:
+                filtered.append(checker)
+        checkers_by_scope[scope] = filtered

As per coding guidelines: "Use explicit loops instead of list comprehensions for code clarity and debuggability"

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/lint_cpp/rust_bridge.py` around lines 37 - 46, The list comprehension in
remove_rust_supported_checkers should be replaced with an explicit loop for
clarity and easier debugging: iterate over checkers_by_scope.items(), build a
new list by appending each checker whose class name is not in
RUST_SUPPORTED_CHECKERS, and then assign that list back to
checkers_by_scope[scope]; reference the function remove_rust_supported_checkers,
the parameter checkers_by_scope, the FileContentChecker instances in the lists,
and the RUST_SUPPORTED_CHECKERS set when making the change.
ci/lint_cpp_rs/src/lib.rs (1)

809-815: ⚡ Quick win

Collapse identical else if/else branches (Clippy).

Both fallback branches produce PathBuf::from("."), which Clippy flags (if_same_then_else). If CI runs cargo clippy -D warnings, this fails the build.

♻️ Proposed simplification
-    let project_root = if let Some(index) = normalized_path.find("/src/") {
-        PathBuf::from(&normalized_path[..index])
-    } else if normalized_path.starts_with("src/") {
-        PathBuf::from(".")
-    } else {
-        PathBuf::from(".")
-    };
+    let project_root = if let Some(index) = normalized_path.find("/src/") {
+        PathBuf::from(&normalized_path[..index])
+    } else {
+        PathBuf::from(".")
+    };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/lint_cpp_rs/src/lib.rs` around lines 809 - 815, The two fallback branches
for computing project_root both return PathBuf::from(".") causing a Clippy
if_same_then_else lint; simplify the logic by removing the redundant else if
normalized_path.starts_with("src/") branch and make the code an if let
Some(index) = normalized_path.find("/src/") {
PathBuf::from(&normalized_path[..index]) } else { PathBuf::from(".") }, keeping
the variable name project_root and the use of normalized_path.find("/src/") and
PathBuf::from(".") to locate the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ci/lint_cpp_rs/src/lib.rs`:
- Around line 178-186: The current loader uses FileContent::read inside
pending_paths.par_iter() and then uses loaded? which aborts the whole run on the
first read/UTF-8 error; change the logic so you handle each Result<(PathBuf,
FileContent), DynError> individually instead of using the ? operator: when
iterating loaded_files, match on each Result returned by FileContent::read (the
symbols to edit are pending_paths, FileContent::read, loaded_files and the loop
that calls loaded? and self.file_cache.insert), and for Err log a warning or
record a per-file error for interested checkers and continue, and for Ok insert
the (path, content) into self.file_cache; do not propagate a read error to stop
the whole process.

In `@ci/lint_cpp/rust_bridge.py`:
- Around line 96-111: In parse_rust_json_output, adjust the try/except so
KeyboardInterrupt is handled first: inside the loop where decoder.raw_decode is
called, add an except KeyboardInterrupt: raise to re-raise the interrupt before
the except json.JSONDecodeError: continue branch; this ensures
parse_rust_json_output will propagate user interrupts while still catching JSON
decode errors.
- Around line 114-136: The run_rust_ab_check function signature should not use a
default for the files parameter: change def run_rust_ab_check(..., files:
list[str] | None = None) to require files: list[str] (or list[str] | None
without a default if None is allowed but must be passed); then update all call
sites to pass the files argument explicitly (the two callers in
run_all_checkers.py referenced in the review must be modified to provide the
files list when calling run_rust_ab_check); ensure any internal logic that
assumed a default None still handles the explicitly passed value and that
run_rust_linter(files) continues to receive the files variable.
- Around line 49-93: The function run_rust_linter currently declares a default
for the files parameter; remove the default so its signature becomes files:
list[str] | None (no "= None") and update every caller to pass an explicit
argument (pass None when no files are intended). Ensure callers that previously
relied on the default are changed to call run_rust_linter(None) and that the
body of run_rust_linter continues to handle files being None (no other logic
changes required).

In `@ci/lint.py`:
- Around line 40-42: The function signature for run_single_file_mode currently
gives use_rust_cpp_lint a default value; remove the default so the signature
becomes run_single_file_mode(files: list[str], strict: bool, use_rust_cpp_lint:
bool) and update every call site to pass an explicit boolean for
use_rust_cpp_lint (search for run_single_file_mode(...) usages and add
true/false as appropriate); ensure the parameter still has its type annotation
and run tests/lint to catch any missed callers.

In `@ci/lint/stage_impls.py`:
- Around line 694-696: The function run_cpp_lint_single_file currently uses
default parameter values; remove the defaults so the signature becomes
run_cpp_lint_single_file(file_path: str, strict: bool, use_rust_cpp_lint: bool)
and update every call site to pass explicit bool arguments for strict and
use_rust_cpp_lint (i.e., do not rely on defaults). Ensure type annotations
remain and adjust callers that previously invoked
run_cpp_lint_single_file(file_path) or with fewer args to supply the two boolean
flags.
- Around line 193-198: The parameter use_rust_cpp_lint on function run_cpp_lint
must not have a default value — remove the "= False" default from the
run_cpp_lint signature and update all call sites to pass an explicit boolean
argument; specifically locate the run_cpp_lint definition and callers (e.g., the
call in ci/lint.py that currently omits the argument) and change the calls to
provide either True or False so the new non-defaulted parameter is always
supplied.

---

Outside diff comments:
In `@ci/lint/args_parser.py`:
- Around line 9-10: The LintArgs dataclass is missing the required `@typechecked`
decorator; update the definition by importing and applying typechecked to the
LintArgs dataclass so runtime type validation is enforced (ensure you add the
import for typechecked and annotate the class with `@typechecked` above `@dataclass`
on the LintArgs declaration).

---

Nitpick comments:
In `@ci/lint_cpp_rs/src/lib.rs`:
- Around line 809-815: The two fallback branches for computing project_root both
return PathBuf::from(".") causing a Clippy if_same_then_else lint; simplify the
logic by removing the redundant else if normalized_path.starts_with("src/")
branch and make the code an if let Some(index) = normalized_path.find("/src/") {
PathBuf::from(&normalized_path[..index]) } else { PathBuf::from(".") }, keeping
the variable name project_root and the use of normalized_path.find("/src/") and
PathBuf::from(".") to locate the change.

In `@ci/lint_cpp/rust_bridge.py`:
- Around line 37-46: The list comprehension in remove_rust_supported_checkers
should be replaced with an explicit loop for clarity and easier debugging:
iterate over checkers_by_scope.items(), build a new list by appending each
checker whose class name is not in RUST_SUPPORTED_CHECKERS, and then assign that
list back to checkers_by_scope[scope]; reference the function
remove_rust_supported_checkers, the parameter checkers_by_scope, the
FileContentChecker instances in the lists, and the RUST_SUPPORTED_CHECKERS set
when making the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 670ffbd3-6f32-4fdb-bdb9-3164b83d8d65

📥 Commits

Reviewing files that changed from the base of the PR and between 9e3b9eb and 88b1699.

⛔ Files ignored due to path filters (1)
  • ci/lint_cpp_rs/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (10)
  • .gitignore
  • ci/lint.py
  • ci/lint/args_parser.py
  • ci/lint/stage_impls.py
  • ci/lint_cpp/run_all_checkers.py
  • ci/lint_cpp/rust_bridge.py
  • ci/lint_cpp/test_rust_parity.py
  • ci/lint_cpp_rs/Cargo.toml
  • ci/lint_cpp_rs/src/lib.rs
  • ci/lint_cpp_rs/src/main.rs

Comment thread ci/lint_cpp_rs/src/lib.rs Resolved
Comment thread ci/lint_cpp/rust_bridge.py Resolved
Comment thread ci/lint_cpp/rust_bridge.py Resolved
Comment thread ci/lint_cpp/rust_bridge.py Resolved
Comment thread ci/lint.py Resolved
Comment thread ci/lint/stage_impls.py
Comment on lines +193 to +198
def run_cpp_lint(
no_fingerprint: bool,
run_full: bool,
run_iwyu: bool,
use_rust_cpp_lint: bool = False,
) -> bool:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Remove default value from use_rust_cpp_lint parameter.

Function parameters must not have default values per coding guidelines.

♻️ Proposed fix
 def run_cpp_lint(
     no_fingerprint: bool,
     run_full: bool,
     run_iwyu: bool,
-    use_rust_cpp_lint: bool = False,
+    use_rust_cpp_lint: bool,
 ) -> bool:

Update the caller in ci/lint.py at lines 192-197.

As per coding guidelines: "All function parameters MUST have explicit type annotations and MUST NOT have default values"

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def run_cpp_lint(
no_fingerprint: bool,
run_full: bool,
run_iwyu: bool,
use_rust_cpp_lint: bool = False,
) -> bool:
def run_cpp_lint(
no_fingerprint: bool,
run_full: bool,
run_iwyu: bool,
use_rust_cpp_lint: bool,
) -> bool:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/lint/stage_impls.py` around lines 193 - 198, The parameter
use_rust_cpp_lint on function run_cpp_lint must not have a default value —
remove the "= False" default from the run_cpp_lint signature and update all call
sites to pass an explicit boolean argument; specifically locate the run_cpp_lint
definition and callers (e.g., the call in ci/lint.py that currently omits the
argument) and change the calls to provide either True or False so the new
non-defaulted parameter is always supplied.

Comment thread ci/lint/stage_impls.py Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ci/lint_cpp_rs/src/lib.rs`:
- Around line 2187-2210: RelativeIncludeChecker::check_file_content currently
ignores /* */ block comments and will flag includes inside multi-line comments;
update check_file_content to mirror other checkers by tracking a
block_comment_open boolean while iterating FileContent.lines (before using
regex_relative_include()), toggle it when encountering start/end of /* */
(handling same-line open+close), and only test lines with
regex_relative_include() when block_comment_open is false and the line does not
contain the single-line exception marker ("// ok relative include"); reference
the function names regex_relative_include(),
RelativeIncludeChecker::check_file_content, and FileContent.lines to locate
where to add the block comment state handling.
- Around line 2232-2260: The checker in check_file_content is producing false
positives for includes inside block comments because it doesn't track multi-line
/* */ comment state; update check_file_content to maintain an in_block_comment
boolean that is updated per line by scanning for opening "/*" and closing "*/"
(handling multiple comment delimiters per line) and skip any
regex_fastled_h_include() matches that occur inside a block comment; keep the
existing single-line comment ("// ok include") logic and the lookback for
regex_fastled_internal_define(), but only perform those checks when the match is
not inside a block comment so commented-out includes won't be reported.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 73e9506f-d0c4-4043-b66a-0c1e29f29f03

📥 Commits

Reviewing files that changed from the base of the PR and between 88b1699 and 812cf19.

📒 Files selected for processing (3)
  • ci/lint_cpp/rust_bridge.py
  • ci/lint_cpp/test_rust_parity.py
  • ci/lint_cpp_rs/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • ci/lint_cpp/test_rust_parity.py
  • ci/lint_cpp/rust_bridge.py

Comment thread ci/lint_cpp_rs/src/lib.rs Resolved
Comment thread ci/lint_cpp_rs/src/lib.rs Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
ci/lint_cpp_rs/src/lib.rs (2)

498-506: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fail when an explicit input resolves to nothing.

A typoed path or unmatched glob currently produces an empty file set, and the CLI reports a clean run. That turns a missing target into a false pass.

♻️ Proposed fix
 fn collect_input_files(project_root: &Path, inputs: &[String]) -> Result<Vec<PathBuf>, DynError> {
     let mut files = BTreeSet::new();

     if inputs.is_empty() {
         for dir in ["src", "examples", "tests"] {
@@
     } else {
         for input in inputs {
             if input.contains('*') || input.contains('?') || input.contains('[') {
+                let mut matched = false;
                 for entry in glob(input)? {
+                    matched = true;
                     let path = entry?;
                     collect_path(&path, &mut files, false);
                 }
+                if !matched {
+                    return Err(format!("input pattern matched no files: {input}").into());
+                }
             } else {
-                collect_path(&PathBuf::from(input), &mut files, true);
+                let path = PathBuf::from(input);
+                if !path.exists() {
+                    return Err(format!("input path not found: {input}").into());
+                }
+                collect_path(&path, &mut files, true);
             }
         }
     }

     Ok(files.into_iter().collect())
 }
As per coding guidelines: "Never use silent fallbacks for missing critical resources - always fail fast with descriptive errors"

Also applies to: 513-520

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/lint_cpp_rs/src/lib.rs` around lines 498 - 506, The loop over inputs
currently silently accepts unmatched patterns and empty explicit paths; update
the logic in the inputs iteration (the branch that checks
input.contains('*'/'?'/'[') and the else branch that calls
collect_path(&PathBuf::from(input), &mut files, true)) to detect when a glob
produces zero matches or when an explicit input resolves to no files and return
an Err with a descriptive message instead of leaving files empty; use the
glob(...) iterator length or a match on entries to determine zero matches for
glob(), and verify collect_path's result (or check files after calling
collect_path) to fail fast with a clear error mentioning the original input
string. Ensure the same change is applied to the similar block around the other
occurrence (lines handling inputs again at the second location).

425-433: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Separate --help from the --list-checkers exit path.

--help currently returns CliConfig { list_checkers: true, ... }, so run_cli prints the checker list after the usage text instead of exiting cleanly after help.

♻️ Proposed fix
 pub fn run_cli<I>(args: I) -> Result<u8, DynError>
 where
     I: IntoIterator<Item = String>,
 {
     let config = CliConfig::parse(args)?;
+    if config.show_help {
+        return Ok(0);
+    }

     if config.list_checkers {
         for checker in supported_checker_names() {
             println!("{checker}");
         }
@@
 struct CliConfig {
     output_format: OutputFormat,
     project_root: PathBuf,
     selected_checkers: Option<HashSet<String>>,
+    show_help: bool,
     list_checkers: bool,
     paths: Vec<String>,
 }
@@
                 "--help" | "-h" => {
                     print_help();
                     return Ok(Self {
                         output_format,
                         project_root,
                         selected_checkers: None,
-                        list_checkers: true,
+                        show_help: true,
+                        list_checkers: false,
                         paths,
                     });
                 }
@@
         Ok(Self {
             output_format,
             project_root,
             selected_checkers,
+            show_help: false,
             list_checkers,
             paths,
         })
     }
 }

Also applies to: 350-355

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/lint_cpp_rs/src/lib.rs` around lines 425 - 433, The "--help" match arm
currently returns a CliConfig with list_checkers: true so run_cli prints the
checker list after usage; change the "--help" | "-h" arm in the argument-parsing
match (the branch that calls print_help()) to return a CliConfig with
list_checkers set to false (or the default exit-without-list value) so help
exits cleanly, and make the analogous change in the other occurrence around the
350–355 match; look for the CliConfig construction and the print_help() call to
update the list_checkers field accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@ci/lint_cpp_rs/src/lib.rs`:
- Around line 498-506: The loop over inputs currently silently accepts unmatched
patterns and empty explicit paths; update the logic in the inputs iteration (the
branch that checks input.contains('*'/'?'/'[') and the else branch that calls
collect_path(&PathBuf::from(input), &mut files, true)) to detect when a glob
produces zero matches or when an explicit input resolves to no files and return
an Err with a descriptive message instead of leaving files empty; use the
glob(...) iterator length or a match on entries to determine zero matches for
glob(), and verify collect_path's result (or check files after calling
collect_path) to fail fast with a clear error mentioning the original input
string. Ensure the same change is applied to the similar block around the other
occurrence (lines handling inputs again at the second location).
- Around line 425-433: The "--help" match arm currently returns a CliConfig with
list_checkers: true so run_cli prints the checker list after usage; change the
"--help" | "-h" arm in the argument-parsing match (the branch that calls
print_help()) to return a CliConfig with list_checkers set to false (or the
default exit-without-list value) so help exits cleanly, and make the analogous
change in the other occurrence around the 350–355 match; look for the CliConfig
construction and the print_help() call to update the list_checkers field
accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4c355664-34dc-4b8c-b8f6-14d292f189a6

📥 Commits

Reviewing files that changed from the base of the PR and between 812cf19 and 41fdb44.

📒 Files selected for processing (6)
  • ci/lint.py
  • ci/lint/args_parser.py
  • ci/lint/stage_impls.py
  • ci/lint_cpp/run_all_checkers.py
  • ci/lint_cpp/rust_bridge.py
  • ci/lint_cpp_rs/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (3)
  • ci/lint.py
  • ci/lint_cpp/run_all_checkers.py
  • ci/lint_cpp/rust_bridge.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
ci/lint_cpp_rs/src/lib.rs (1)

2984-3001: ⚡ Quick win

Move Regex::new(r"^#\s*include\b") construction out of RawNoexceptChecker’s per-line loop.

RawNoexceptChecker::check_file_content rebuilds the include regex on every scanned line; most other regexes in this file are cached via OnceLock.

♻️ Proposed fix
+fn regex_preprocessor_include() -> &'static Regex {
+    static VALUE: OnceLock<Regex> = OnceLock::new();
+    VALUE.get_or_init(|| Regex::new(r"^#\s*include\b").unwrap())
+}
+
 impl FileContentChecker for RawNoexceptChecker {
@@
         for (index, line) in file_content.lines.iter().enumerate() {
@@
             let code = split_line_comment(stripped).trim();
             if code.is_empty()
-                || Regex::new(r"^#\s*include\b").unwrap().is_match(code)
+                || regex_preprocessor_include().is_match(code)
                 || regex_define_fl_noexcept().is_match(code)
                 || !regex_raw_noexcept().is_match(code)
             {
                 continue;
             }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/lint_cpp_rs/src/lib.rs` around lines 2984 - 3001, The include-regex
Regex::new(r"^#\s*include\b") is being constructed inside
RawNoexceptChecker::check_file_content for every line; move its construction out
of the per-line loop by creating and reusing a single compiled regex before the
loop (either store it in a local variable at the start of check_file_content or
cache it on the type using OnceLock like the other regexes), then replace the
inline Regex::new(...) call in the loop with that cached/borrowed regex.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@ci/lint_cpp_rs/src/lib.rs`:
- Around line 2984-3001: The include-regex Regex::new(r"^#\s*include\b") is
being constructed inside RawNoexceptChecker::check_file_content for every line;
move its construction out of the per-line loop by creating and reusing a single
compiled regex before the loop (either store it in a local variable at the start
of check_file_content or cache it on the type using OnceLock like the other
regexes), then replace the inline Regex::new(...) call in the loop with that
cached/borrowed regex.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: de063862-4a94-4a19-aaaf-b0cdee67cdac

📥 Commits

Reviewing files that changed from the base of the PR and between 41fdb44 and 28cdc5a.

📒 Files selected for processing (3)
  • ci/lint_cpp/rust_bridge.py
  • ci/lint_cpp/test_rust_parity.py
  • ci/lint_cpp_rs/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • ci/lint_cpp/test_rust_parity.py
  • ci/lint_cpp/rust_bridge.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant