E531 fix: exit status to 1 when no match by Dsaquel · Pull Request #2392 · ast-grep/ast-grep · GitHub
[go: up one dir, main page]

Skip to content

fix: exit status to 1 when no match#2392

Merged
HerringtonDarkholme merged 4 commits intoast-grep:mainfrom
Dsaquel:fix/run-exit-status-code
Dec 14, 2025
Merged

fix: exit status to 1 when no match#2392
HerringtonDarkholme merged 4 commits intoast-grep:mainfrom
Dsaquel:fix/run-exit-status-code

Conversation

@Dsaquel
Copy link
Contributor
@Dsaquel Dsaquel commented Dec 14, 2025

close #2388

Summary by CodeRabbit

  • Bug Fixes

    • CLI now consistently returns explicit exit codes for all commands and operations; success is exit 0, and cases like "no matches" return non‑zero to signal failure.
  • Tests

    • Tests updated and added to assert correct exit code behavior and empty output where appropriate.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor
coderabbitai bot commented Dec 14, 2025

Walkthrough

This PR changes many CLI functions to return Result instead of Result<()>, threading ExitCode through public entry points, command handlers, workers, and tests so the process can surface explicit success/failure exit codes.

Changes

Cohort / File(s) Summary
Main entry points
crates/cli/src/main.rs, crates/cli/src/lib.rs
main(), execute_main(), and main_with_args() now return Result<ExitCode>; ExitCode imported.
Command handlers
crates/cli/src/completions.rs, crates/cli/src/new.rs, crates/cli/src/verify.rs
Public command entry points and internal implementations updated to return Result<ExitCode>; success paths now return Ok(ExitCode::SUCCESS); ExitCode imports added.
Run and scan pipeline
crates/cli/src/run.rs, crates/cli/src/scan.rs
run_with_pattern(), run_pattern_with_printer(), run_with_config(), run_scan() and related trait methods (consume_items) return Result<ExitCode>; logic added to track matches and return non‑zero exit when no matches or on failure.
Worker utilities
crates/cli/src/utils/worker.rs, crates/cli/src/utils/error_context.rs
Worker, PathWorker, StdInWorker method signatures updated to Result<ExitCode>; run_worker() and exit_with_error() updated; failure paths now return ExitCode::FAILURE; ExitCode imported.
Tests
crates/cli/tests/run_test.rs, crates/cli/tests/scan_test.rs, crates/cli/tests/verify_test.rs
Test helpers (sg) updated to return Result<ExitCode>; new tests added and expectations updated to assert success/failure exit codes for no-match and inspect/run scenarios; ExitCode imported in tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Areas needing extra attention:
    • run.rs / scan.rs: correctness of has_matches tracking and where non-zero ExitCode is returned.
    • Worker trait surface: ensure all implementations consistently return ExitCode and preserve error semantics.
    • Tests: updated expectations in run_test.rs and scan_test.rs to match new exit-code behavior.
    • error_context.rs: verify clap::Error paths still terminate as intended and return types align.

Possibly related PRs

Suggested reviewers

  • HerringtonDarkholme

Poem

🐰 I hopped through code where exits hide,
Swapped empty tuples for status wide.
Now success or fail proudly show,
Shells can read and logs will know.
A tiny hop — a clearer tide.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 17.39% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ 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 'fix: exit status to 1 when no match' directly relates to the main objective of returning exit code 1 when no matches are found in ast-grep run.
Linked Issues check ✅ Passed Changes comprehensively address issue #2388 by updating exit codes throughout the CLI to return ExitCode::SUCCESS on match found and ExitCode::FAILURE (1) on no match, affecting run, scan, and verify commands.
Out of Scope Changes check ✅ Passed All changes are in scope: introducing ExitCode return types throughout the CLI pipeline, updating worker traits and implementations, and modifying test expectations to verify new exit code behavior.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@codecov
Copy link
codecov bot commented Dec 14, 2025

Codecov Report

❌ Patch coverage is 93.75000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.79%. Comparing base (ac69fd7) to head (7855996).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
crates/cli/src/completions.rs 66.66% 1 Missing ⚠️
crates/cli/src/lib.rs 66.66% 1 Missing ⚠️
crates/cli/src/new.rs 94.73% 1 Missing ⚠️
crates/cli/src/utils/worker.rs 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2392      +/-   ##
==========================================
+ Coverage   87.78%   87.79%   +0.01%     
==========================================
  Files         107      107              
  Lines       17302    17327      +25     
==========================================
+ Hits        15188    15213      +25     
  Misses       2114     2114              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (2)
crates/cli/src/scan.rs (2)

275-291: Same inverted exit code issue as ScanWithConfig.

ScanStdin::consume_items also returns ExitCode::FAILURE when error_count == 0. This should be consistent with the intended behavior defined for ScanWithConfig.


163-180: Fix inverted exit code: return SUCCESS when scan completes without errors.

The code currently returns ExitCode::FAILURE when error_count == 0, which is semantically inverted. Tests confirm that a successful scan with no diagnostic errors should exit with code 0 (SUCCESS), not 1 (FAILURE). This matches standard UNIX conventions where 0 indicates success.

  if error_count > 0 {
    Err(anyhow::anyhow!(EC::DiagnosticError(error_count)))
  } else {
-   Ok(ExitCode::FAILURE)
+   Ok(ExitCode::SUCCESS)
  }
🧹 Nitpick comments (1)
crates/cli/src/utils/worker.rs (1)

58-66: Parse errors are silently converted to exit code without reporting.

When parse_stdin returns Err, the error is discarded and ExitCode::FAILURE is returned. The user won't know why parsing failed.

Consider logging or reporting the error before returning:

  fn run_std_in<P: Printer>(&self, printer: P) -> Result<ExitCode> {
    let source = std::io::read_to_string(std::io::stdin())?;
    let processor = printer.get_processor();
-   if let Ok(items) = self.parse_stdin::<P>(source, &processor) {
-     self.consume_items(Items::once(items)?, printer)
-   } else {
-     Ok(ExitCode::FAILURE)
-   }
+   match self.parse_stdin::<P>(source, &processor) {
+     Ok(items) => self.consume_items(Items::once(items)?, printer),
+     Err(e) => {
+       eprintln!("ERROR: {e}");
+       Ok(ExitCode::FAILURE)
+     }
+   }
  }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b214b8b and 08fb28e.

📒 Files selected for processing (12)
  • crates/cli/src/completions.rs (3 hunks)
  • crates/cli/src/lib.rs (4 hunks)
  • crates/cli/src/main.rs (1 hunks)
  • crates/cli/src/new.rs (12 hunks)
  • crates/cli/src/run.rs (6 hunks)
  • crates/cli/src/scan.rs (7 hunks)
  • crates/cli/src/utils/error_context.rs (2 hunks)
  • crates/cli/src/utils/worker.rs (5 hunks)
  • crates/cli/src/verify.rs (4 hunks)
  • crates/cli/tests/run_test.rs (3 hunks)
  • crates/cli/tests/scan_test.rs (3 hunks)
  • crates/cli/tests/verify_test.rs (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.rs: Rust code must be formatted with rustfmt (run cargo fmt --all -- --check before committing)
Rust code must pass Clippy with -D clippy::all (cargo clippy --all-targets --all-features --workspace --release --locked -- -D clippy::all)

Files:

  • crates/cli/src/verify.rs
  • crates/cli/src/utils/error_context.rs
  • crates/cli/src/new.rs
  • crates/cli/src/completions.rs
  • crates/cli/tests/verify_test.rs
  • crates/cli/src/lib.rs
  • crates/cli/src/run.rs
  • crates/cli/tests/scan_test.rs
  • crates/cli/tests/run_test.rs
  • crates/cli/src/scan.rs
  • crates/cli/src/main.rs
  • crates/cli/src/utils/worker.rs
🧠 Learnings (12)
📓 Common learnings
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1497
File: crates/cli/src/utils/worker.rs:92-96
Timestamp: 2024-09-29T22:02:55.187Z
Learning: The behavior related to path handling in issue https://github.com/ast-grep/ast-grep/issues/1343 is not determined yet, so we should keep the existing code as is.
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1497
File: crates/cli/src/utils/worker.rs:92-96
Timestamp: 2024-10-08T18:41:57.037Z
Learning: The behavior related to path handling in issue https://github.com/ast-grep/ast-grep/issues/1343 is not determined yet, so we should keep the existing code as is.
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1497
File: crates/cli/src/lsp.rs:2-2
Timestamp: 2024-10-08T18:41:57.037Z
Learning: `ErrorContext` is exported from `crates/cli/src/utils/mod.rs` using `pub use`.
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1497
File: crates/cli/src/lsp.rs:2-2
Timestamp: 2024-09-29T21:21:57.113Z
Learning: `ErrorContext` is exported from `crates/cli/src/utils/mod.rs` using `pub use`.
📚 Learning: 2024-10-05T19:26:12.834Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1500
File: crates/cli/src/config.rs:60-60
Timestamp: 2024-10-05T19:26:12.834Z
Learning: When `find_rules` returns `(RuleCollection<SgLang>, RuleStats)`, we should handle both elements and add logging of `RuleStats` in the callers, such as in `crates/cli/src/verify.rs` and `crates/cli/src/lsp.rs`.

Applied to files:

  • crates/cli/src/verify.rs
📚 Learning: 2024-10-08T18:41:57.037Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1497
File: crates/cli/src/lsp.rs:2-2
Timestamp: 2024-10-08T18:41:57.037Z
Learning: `ErrorContext` is exported from `crates/cli/src/utils/mod.rs` using `pub use`.

Applied to files:

  • crates/cli/src/utils/error_context.rs
  • crates/cli/src/run.rs
  • crates/cli/src/scan.rs
📚 Learning: 2024-10-22T14:04:15.734Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1546
File: crates/cli/src/utils/rule_overwrite.rs:76-91
Timestamp: 2024-10-22T14:04:15.734Z
Learning: In the `ast-grep-cli` application code, avoid unnecessary abstractions; functions don't need to accept iterators instead of `Vec` if not required.

Applied to files:

  • crates/cli/tests/verify_test.rs
  • crates/cli/src/run.rs
  • crates/cli/tests/scan_test.rs
  • crates/cli/tests/run_test.rs
  • crates/cli/src/scan.rs
  • crates/cli/src/main.rs
  • crates/cli/src/utils/worker.rs
📚 Learning: 2024-09-29T21:59:50.675Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1497
File: crates/cli/src/utils/mod.rs:174-175
Timestamp: 2024-09-29T21:59:50.675Z
Learning: ast-grep requires Rust 1.65 or newer. It's acceptable to use syntax and features introduced in Rust 1.65 or newer in ast-grep code.

Applied to files:

  • crates/cli/tests/verify_test.rs
  • crates/cli/src/run.rs
  • crates/cli/tests/run_test.rs
  • crates/cli/src/scan.rs
  • crates/cli/src/utils/worker.rs
📚 Learning: 2024-10-28T03:46:27.850Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1560
File: crates/cli/src/scan.rs:405-407
Timestamp: 2024-10-28T03:46:27.850Z
Learning: `ProjectConfig::setup` returns a `Result<Result<ProjectConfig>>`, so wrapping the result in `Ok()` is unnecessary.

Applied to files:

  • crates/cli/src/lib.rs
  • crates/cli/src/scan.rs
📚 Learning: 2024-10-28T03:45:43.551Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1560
File: crates/cli/src/lib.rs:0-0
Timestamp: 2024-10-28T03:45:43.551Z
Learning: In the `sg` CLI application, the `-l` or `--lang` command argument depends on the configuration and project being set up, so the configuration cannot be parsed using clap's `App` struct at that point.

Applied to files:

  • crates/cli/src/lib.rs
📚 Learning: 2025-09-03T04:16:39.630Z
Learnt from: CR
Repo: ast-grep/ast-grep PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-03T04:16:39.630Z
Learning: Applies to **/*.rs : Rust code must pass Clippy with `-D clippy::all` (`cargo clippy --all-targets --all-features --workspace --release --locked -- -D clippy::all`)

Applied to files:

  • crates/cli/src/run.rs
  • crates/cli/tests/run_test.rs
📚 Learning: 2024-10-08T18:41:57.037Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1497
File: crates/cli/src/utils/worker.rs:69-77
Timestamp: 2024-10-08T18:41:57.037Z
Learning: In `crates/cli/src/utils/worker.rs`, implementing `From<T>` for `Items<T>` is considered over-abstraction and should be avoided.

Applied to files:

  • crates/cli/src/run.rs
  • crates/cli/src/scan.rs
  • crates/cli/src/utils/worker.rs
📚 Learning: 2024-11-30T01:59:37.083Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1630
File: crates/core/src/node.rs:710-718
Timestamp: 2024-11-30T01:59:37.083Z
Learning: In the `ast-grep` project, when writing tests for position calculations in `crates/core/src/node.rs`, positions should be calculated based on character counts rather than character widths.

Applied to files:

  • crates/cli/tests/run_test.rs
📚 Learning: 2024-10-08T18:41:57.037Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 831
File: crates/language/src/bash.rs:1-42
Timestamp: 2024-10-08T18:41:57.037Z
Learning: The user `HerringtonDarkholme` has indicated that the test cases for brace expansion pattern matching in `bash.rs` will be fixed in a separate commit.

Applied to files:

  • crates/cli/tests/run_test.rs
📚 Learning: 2025-09-03T04:16:39.630Z
Learnt from: CR
Repo: ast-grep/ast-grep PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-03T04:16:39.630Z
Learning: Applies to crates/napi/** : If touching NAPI (Node.js) bindings, run `yarn test` in crates/napi

Applied to files:

  • crates/cli/tests/run_test.rs
🧬 Code graph analysis (7)
crates/cli/src/completions.rs (1)
crates/cli/src/lib.rs (1)
  • run_shell_completion (142-142)
crates/cli/src/lib.rs (1)
crates/cli/src/lsp.rs (1)
  • run_language_server (31-37)
crates/cli/src/run.rs (2)
crates/cli/src/scan.rs (2)
  • consume_items (163-180)
  • consume_items (275-291)
crates/cli/src/utils/worker.rs (1)
  • consume_items (22-22)
crates/cli/tests/scan_test.rs (2)
crates/cli/tests/verify_test.rs (1)
  • sg (60-63)
crates/cli/src/scan.rs (1)
  • create_test_files (376-387)
crates/cli/tests/run_test.rs (3)
crates/cli/src/scan.rs (1)
  • create_test_files (376-387)
crates/core/src/tree_sitter/mod.rs (1)
  • str (346-348)
crates/config/src/rule/selector.rs (1)
  • is_empty (219-221)
crates/cli/src/main.rs (1)
crates/cli/src/lib.rs (1)
  • execute_main (68-73)
crates/cli/src/utils/worker.rs (2)
crates/cli/src/run.rs (2)
  • consume_items (187-202)
  • consume_items (283-301)
crates/cli/src/scan.rs (2)
  • consume_items (163-180)
  • consume_items (275-291)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: coverage
🔇 Additional comments (20)
crates/cli/tests/verify_test.rs (1)

3-4: LGTM! Clean type signature update.

The addition of ExitCode import and the updated sg helper signature correctly align with the broader refactoring to propagate exit codes through the CLI.

Also applies to: 60-63

crates/cli/tests/run_test.rs (2)

77-87: LGTM! Clear validation of exit-on-no-match behavior.

The new test properly validates that ast-grep run exits with a non-zero status when the pattern finds no matches, with empty stdout as expected.


129-131: Verify that --inspect=summary should fail on no match.

These tests now expect .failure() instead of .success() when running with --inspect=summary and no matches are found. Since --inspect is a diagnostic/tracing flag, please confirm this is the intended behavior—diagnostic modes sometimes use different exit conventions than regular matching modes.

Also applies to: 141-142, 147-148

crates/cli/src/main.rs (1)

1-2: LGTM! Straightforward entry point update.

The main function signature correctly updated to propagate ExitCode from execute_main.

Also applies to: 6-8

crates/cli/tests/scan_test.rs (2)

3-4: LGTM! Type signature update aligns with ExitCode refactoring.

The import and sg helper signature correctly updated to match main_with_args return type.

Also applies to: 48-51


402-412: LGTM! Correct validation of scan-with-no-match behavior.

This test properly validates that scan succeeds when no rules match (no violations found = success), which is the appropriate behavior for a linting/scanning tool. This intentionally differs from the run command, which fails on no matches.

crates/cli/src/utils/error_context.rs (1)

7-7: LGTM! Signature correctly updated for consistency.

The exit_with_error signature now returns Result<ExitCode> to align with the CLI's exit code propagation, even though the clap::Error and ErrorContext branches terminate via exit(). The fallback Err(error) path properly delegates to anyhow's error reporting.

Also applies to: 296-310

crates/cli/src/new.rs (1)

12-12: LGTM! Thorough and consistent ExitCode propagation.

All creation flow functions properly updated to return Result<ExitCode>, with success paths returning ExitCode::SUCCESS and error paths maintaining proper error context. The changes cascade cleanly through the entire call chain.

Also applies to: 148-154, 156-172, 174-182, 184-196, 198-230, 247-275, 288-319, 331-360

crates/cli/src/lib.rs (1)

14-14: LGTM! Core CLI orchestration correctly refactored.

The execute_main and main_with_args functions now properly propagate ExitCode through all command branches. The LSP command correctly maps its Result<()> to ExitCode::SUCCESS on success.

Also applies to: 68-73, 126-146

crates/cli/src/verify.rs (1)

19-19: LGTM! Test verification flow correctly updated.

The run_test_rule_impl and run_test_rule functions properly updated to return Result<ExitCode>, with the success branch returning ExitCode::SUCCESS and error branches maintaining appropriate error contexts for test failures and snapshot mismatches.

Also applies to: 57-112, 200-215

crates/cli/src/scan.rs (2)

2-2: LGTM!

Import of ExitCode is appropriate for the new return type semantics.


79-101: LGTM!

Function signature correctly updated to return Result<ExitCode>, and all code paths properly propagate the exit code from run_scan.

crates/cli/src/completions.rs (1)

34-34: LGTM!

The ExitCode integration is correct. Returning SUCCESS when shell completions are generated successfully is the expected behavior.

Also applies to: 44-46, 48-62

crates/cli/src/utils/worker.rs (2)

8-8: LGTM!

Trait signature updates for ExitCode propagation are consistent and well-structured.

Also applies to: 22-22, 43-48


110-113: LGTM!

Signature update for run_worker is correct, and exit code propagation from consume_items is properly handled.

crates/cli/src/run.rs (5)

2-2: LGTM!

Import of ExitCode aligns with the new return type requirements.


150-169: LGTM!

Function signature correctly updated, and all code paths properly propagate exit codes from run_pattern_with_printer.


171-179: LGTM!

Exit codes are properly propagated from all execution paths (stdin, specific lang, inferred lang).


187-202: LGTM!

The has_matches tracking and exit code logic correctly implements grep-like semantics: exit 0 when matches are found, exit 1 when no matches.


283-301: LGTM!

Consistent implementation with RunWithInferredLang. The pattern error check on line 296-297 is a good safeguard—if the pattern has errors and no matches were found, it reports the error rather than silently returning exit code 1.

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

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

⚠️ Outside diff range comments (1)
crates/cli/src/scan.rs (1)

275-291: Inconsistent exit code with ScanWithConfig.

ScanStdin::consume_items returns ExitCode::FAILURE when error_count == 0 (line 289), but ScanWithConfig::consume_items returns ExitCode::SUCCESS in the same condition (line 178). Based on the past review discussion, the scan command should exit with SUCCESS when scanning completes without ERROR-severity violations, regardless of whether it's reading from stdin or files.

Apply this diff to align with the established semantics:

     let error_count = self.error_count.load(Ordering::Acquire);
     if error_count > 0 {
       Err(anyhow::anyhow!(EC::DiagnosticError(error_count)))
     } else {
-      Ok(ExitCode::FAILURE)
+      Ok(ExitCode::SUCCESS)
     }
🧹 Nitpick comments (1)
crates/cli/src/scan.rs (1)

427-475: Consider verifying actual exit codes in tests.

The tests currently only check that run_with_config returns Ok(...), but don't verify the actual ExitCode value. Consider enhancing test coverage to assert the expected exit codes (SUCCESS vs FAILURE) to prevent regressions in exit code semantics.

Example enhancement:

let exit_code = run_with_config(arg, project_config).unwrap();
assert_eq!(exit_code, ExitCode::SUCCESS);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 08fb28e and 7855996.

📒 Files selected for processing (1)
  • crates/cli/src/scan.rs (7 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.rs: Rust code must be formatted with rustfmt (run cargo fmt --all -- --check before committing)
Rust code must pass Clippy with -D clippy::all (cargo clippy --all-targets --all-features --workspace --release --locked -- -D clippy::all)

Files:

  • crates/cli/src/scan.rs
🧠 Learnings (16)
📓 Common learnings
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1497
File: crates/cli/src/utils/worker.rs:92-96
Timestamp: 2024-09-29T22:02:55.187Z
Learning: The behavior related to path handling in issue https://github.com/ast-grep/ast-grep/issues/1343 is not determined yet, so we should keep the existing code as is.
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1497
File: crates/cli/src/utils/worker.rs:92-96
Timestamp: 2024-10-08T18:41:57.037Z
Learning: The behavior related to path handling in issue https://github.com/ast-grep/ast-grep/issues/1343 is not determined yet, so we should keep the existing code as is.
📚 Learning: 2024-10-21T07:16:14.836Z
Learnt from: philiptaron
Repo: ast-grep/ast-grep PR: 0
File: :0-0
Timestamp: 2024-10-21T07:16:14.836Z
Learning: In the `ast-grep` repository, the existence of the `sg` binary after the build process is guaranteed, making checks for its existence before installing shell completions unnecessary.

Applied to files:

  • crates/cli/src/scan.rs
📚 Learning: 2024-12-08T20:23:06.671Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1652
File: Cargo.toml:35-38
Timestamp: 2024-12-08T20:23:06.671Z
Learning: In the ast-grep project, `tree-sitter-native` is not updated because `tree-sitter-facade-sg` requires a special patch update.

Applied to files:

  • crates/cli/src/scan.rs
📚 Learning: 2025-07-27T19:36:20.176Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 2126
File: schemas/css_rule.json:571-572
Timestamp: 2025-07-27T19:36:20.176Z
Learning: Schema files in ast-grep (like schemas/css_rule.json) should not be manually edited since they are machine-generated. Any issues found in these files need to be addressed in the code generation logic, not through direct file modifications.

Applied to files:

  • crates/cli/src/scan.rs
📚 Learning: 2024-10-22T14:04:15.734Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1546
File: crates/cli/src/utils/rule_overwrite.rs:76-91
Timestamp: 2024-10-22T14:04:15.734Z
Learning: In the `ast-grep-cli` application code, avoid unnecessary abstractions; functions don't need to accept iterators instead of `Vec` if not required.

Applied to files:

  • crates/cli/src/scan.rs
📚 Learning: 2025-09-03T04:16:39.630Z
Learnt from: CR
Repo: ast-grep/ast-grep PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-03T04:16:39.630Z
Learning: Applies to **/sgconfig.yml : Use sgconfig.yml as the configuration file name for configuration-based ast-grep scans

Applied to files:

  • crates/cli/src/scan.rs
📚 Learning: 2024-09-29T22:02:55.187Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1497
File: crates/cli/src/utils/worker.rs:92-96
Timestamp: 2024-09-29T22:02:55.187Z
Learning: The behavior related to path handling in issue https://github.com/ast-grep/ast-grep/issues/1343 is not determined yet, so we should keep the existing code as is.

Applied to files:

  • crates/cli/src/scan.rs
📚 Learning: 2024-10-22T13:56:44.052Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1546
File: crates/cli/src/utils/rule_overwrite.rs:118-121
Timestamp: 2024-10-22T13:56:44.052Z
Learning: The `OverwriteResult` struct in `crates/cli/src/utils/rule_overwrite.rs` will have more override options added in the future, so it should be retained even if it currently only contains an `Option<Severity>`.

Applied to files:

  • crates/cli/src/scan.rs
📚 Learning: 2025-07-27T19:35:43.279Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 2126
File: schemas/elixir_rule.json:150-200
Timestamp: 2025-07-27T19:35:43.279Z
Learning: Schema files in the ast-grep project (like schemas/elixir_rule.json) are machine-generated, so duplication and manual maintenance concerns like DRY principles don't apply since humans don't manually edit these files.

Applied to files:

  • crates/cli/src/scan.rs
📚 Learning: 2024-10-05T19:26:12.834Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1500
File: crates/cli/src/config.rs:60-60
Timestamp: 2024-10-05T19:26:12.834Z
Learning: When `find_rules` returns `(RuleCollection<SgLang>, RuleStats)`, we should handle both elements and add logging of `RuleStats` in the callers, such as in `crates/cli/src/verify.rs` and `crates/cli/src/lsp.rs`.

Applied to files:

  • crates/cli/src/scan.rs
📚 Learning: 2024-10-08T18:41:57.037Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1500
File: crates/cli/src/config.rs:60-60
Timestamp: 2024-10-08T18:41:57.037Z
Learning: In the `ast-grep` codebase, it's acceptable for some callers of `find_rules` to intentionally ignore the `RuleStats` returned in its tuple `(RuleCollection<SgLang>, RuleStats)` when the statistics are not needed.

Applied to files:

  • crates/cli/src/scan.rs
📚 Learning: 2025-04-27T20:33:36.294Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1957
File: crates/core/src/node.rs:360-365
Timestamp: 2025-04-27T20:33:36.294Z
Learning: In ast-grep, the `field_children` method accepts an `Option<u16>` as its field_id parameter, allowing for direct passing of the result from `field_to_id` without unwrapping.

Applied to files:

  • crates/cli/src/scan.rs
📚 Learning: 2024-09-29T21:21:57.113Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1497
File: crates/cli/src/lsp.rs:2-2
Timestamp: 2024-09-29T21:21:57.113Z
Learning: `ErrorContext` is exported from `crates/cli/src/utils/mod.rs` using `pub use`.

Applied to files:

  • crates/cli/src/scan.rs
📚 Learning: 2024-09-29T21:59:50.675Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1497
File: crates/cli/src/utils/mod.rs:174-175
Timestamp: 2024-09-29T21:59:50.675Z
Learning: ast-grep requires Rust 1.65 or newer. It's acceptable to use syntax and features introduced in Rust 1.65 or newer in ast-grep code.

Applied to files:

  • crates/cli/src/scan.rs
📚 Learning: 2024-10-28T03:46:27.850Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1560
File: crates/cli/src/scan.rs:405-407
Timestamp: 2024-10-28T03:46:27.850Z
Learning: `ProjectConfig::setup` returns a `Result<Result<ProjectConfig>>`, so wrapping the result in `Ok()` is unnecessary.

Applied to files:

  • crates/cli/src/scan.rs
📚 Learning: 2024-09-29T21:58:00.508Z
Learnt from: HerringtonDarkholme
Repo: ast-grep/ast-grep PR: 1497
File: crates/cli/src/utils/worker.rs:69-77
Timestamp: 2024-09-29T21:58:00.508Z
Learning: In `crates/cli/src/utils/worker.rs`, implementing `From<T>` for `Items<T>` is considered over-abstraction and should be avoided.

Applied to files:

  • crates/cli/src/scan.rs
🧬 Code graph analysis (1)
crates/cli/src/scan.rs (2)
crates/cli/src/utils/worker.rs (1)
  • consume_items (22-22)
crates/cli/src/run.rs (2)
  • consume_items (187-202)
  • consume_items (283-301)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: coverage
🔇 Additional comments (3)
crates/cli/src/scan.rs (3)

2-2: LGTM: Required import for ExitCode propagation.

The import is necessary for the new return type signatures throughout the file.


79-79: LGTM: Function signatures updated to propagate ExitCode.

The signature changes for run_with_config and run_scan correctly align with the PR objective to propagate explicit exit codes through the CLI command handlers.

Also applies to: 108-108


163-180: LGTM: ScanWithConfig exit code logic is correct.

The implementation correctly returns ExitCode::SUCCESS when scanning completes without ERROR-severity rule violations, and propagates errors appropriately. This aligns with the agreed-upon semantics from the previous review discussion.

Copy link
Member
@HerringtonDarkholme HerringtonDarkholme left a comment

Choose a reason for hiding this comment

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

looks neat

@HerringtonDarkholme HerringtonDarkholme merged commit f3e211e into ast-grep:main Dec 14, 2025
6 checks passed
@Dsaquel
Copy link
Contributor Author
Dsaquel commented Dec 14, 2025

Thank you 🫡

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] ast-grep run exit with the status 0 if no match

2 participants

0