fix: override severity on rule & inline-rules flags#2505
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughScan rule loading now always applies RuleOverwrite processing: file-based, inline, and stdin-loaded rule configurations are passed through Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2505 +/- ##
==========================================
+ Coverage 84.40% 84.42% +0.01%
==========================================
Files 113 113
Lines 18665 18669 +4
==========================================
+ Hits 15755 15761 +6
+ Misses 2910 2908 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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)
297-311:⚠️ Potential issue | 🟡 MinorThe
--stdinpath doesn't apply severity overrides.
ScanStdin::try_newhas the same rule-loading pattern but doesn't applyRuleOverwrite.process_configs. This means severity overrides via--error,--warning, etc. won't work when combined with--stdin.Consider applying the same fix here for consistency:
Proposed fix
fn try_new(arg: ScanArg) -> Result<Self> { + let overwrite = RuleOverwrite::new(&arg.overwrite)?; let rules = if let Some(path) = &arg.rule { - read_rule_file(path, None)? + read_rule_file(path, None).and_then(|configs| overwrite.process_configs(configs))? } else if let Some(text) = &arg.inline_rules { - from_yaml_string(text, &Default::default()) + let configs = from_yaml_string(text, &Default::default()) .with_context(|| EC::ParseRule("INLINE_RULES".into()))?; + overwrite.process_configs(configs)? } else { return Err(anyhow::anyhow!(EC::RuleNotSpecified)); };🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/cli/src/scan.rs` around lines 297 - 311, ScanStdin::try_new loads rules the same way as Scan::try_new but currently skips applying severity overrides, so modify ScanStdin::try_new to call RuleOverwrite::process_configs on the loaded rules (the same way Scan::try_new does) after rules are created and before returning; locate the rules variable in ScanStdin::try_new and invoke RuleOverwrite::process_configs(&mut rules, &arg.overwrites or equivalent) and propagate any error, ensuring --error/--warning overrides are honored for --stdin.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@crates/cli/src/scan.rs`:
- Around line 297-311: ScanStdin::try_new loads rules the same way as
Scan::try_new but currently skips applying severity overrides, so modify
ScanStdin::try_new to call RuleOverwrite::process_configs on the loaded rules
(the same way Scan::try_new does) after rules are created and before returning;
locate the rules variable in ScanStdin::try_new and invoke
RuleOverwrite::process_configs(&mut rules, &arg.overwrites or equivalent) and
propagate any error, ensuring --error/--warning overrides are honored for
--stdin.
5bff8a5 to
eb82275
Compare
test: handle --stdin
eb82275 to
2761737
Compare
##### [\`v0.42.0\`](https://github.com/ast-grep/ast-grep/blob/HEAD/CHANGELOG.md#0420) - chore(deps): update dependency dprint to v0.53.0 [`#2547`](ast-grep/ast-grep#2547) - chore(deps): update rust crate tree-sitter to v0.26.7 [`#2541`](ast-grep/ast-grep#2541) - chore(deps): update dependency web-tree-sitter to v0.26.7 [`#2540`](ast-grep/ast-grep#2540) - chore(deps): update dependency [@types/node](https://github.com/types/node) to v24.12.0 [`#2518`](ast-grep/ast-grep#2518) - fix(deps): update rust crate tree-sitter-lua to 0.5.0 [`#2506`](ast-grep/ast-grep#2506) - chore(deps): update rust crate clap to v4.6.0 [`#2538`](ast-grep/ast-grep#2538) - fix(deps): update rust crate tree-sitter-scala to 0.25.0 [`#2536`](ast-grep/ast-grep#2536) - chore(deps): update dependency oxlint to v1.55.0 [`#2533`](ast-grep/ast-grep#2533) - chore(deps): update rust crate clap\_complete to v4.6.0 [`#2539`](ast-grep/ast-grep#2539) - chore(deps): update rust crate bit-set to v0.9.1 [`#2537`](ast-grep/ast-grep#2537) - chore(deps): update rust crate bit-set to 0.9.0 [`#2527`](ast-grep/ast-grep#2527) - chore(deps): update rust crate assert\_cmd to v2.2.0 [`#2529`](ast-grep/ast-grep#2529) - chore(deps): update rust crate tempfile to v3.27.0 [`#2531`](ast-grep/ast-grep#2531) - fix(lsp): scan injected languages for diagnostics [`#2528`](ast-grep/ast-grep#2528) - chore(deps): update dependency [@ast-grep/napi](https://github.com/ast-grep/napi) to v0.41.1 [`#2526`](ast-grep/ast-grep#2526) - chore(deps): update dependency oxlint to v1.52.0 [`#2524`](ast-grep/ast-grep#2524) - feat: support nth-child esquery [`#2546`](ast-grep/ast-grep#2546) - feat: support :is selector [`#2545`](ast-grep/ast-grep#2545) - feat: support :not selector [`#2544`](ast-grep/ast-grep#2544) - feat: support :has rule [`#2543`](ast-grep/ast-grep#2543) - fix(lsp): scan injected languages for diagnostics ([#2528](ast-grep/ast-grep#2528)) [`#2522`](ast-grep/ast-grep#2522) - feat: add parameterized util [`3d90372`](ast-grep/ast-grep@3d90372) - refactor: limit parameterized utils to globals [`2d69a34`](ast-grep/ast-grep@2d69a34) - refactor: move parameterized\_util [`c77e38d`](ast-grep/ast-grep@c77e38d) ##### [\`v0.41.1\`](https://github.com/ast-grep/ast-grep/blob/HEAD/CHANGELOG.md#0411) > 10 March 2026 - fix: lsp on change encounter deadlock [`#2511`](ast-grep/ast-grep#2511) - chore(deps): update dependency oxlint to v1.51.0 [`#2512`](ast-grep/ast-grep#2512) - chore(deps): update rust crate tempfile to v3.26.0 [`#2497`](ast-grep/ast-grep#2497) - chore(deps): update rust crate inquire to v0.9.4 [`#2498`](ast-grep/ast-grep#2498) - chore(deps): update dependency [@types/node](https://github.com/types/node) to v24.11.0 [`#2502`](ast-grep/ast-grep#2502) - chore(deps): update dependency dprint to v0.52.0 [`#2499`](ast-grep/ast-grep#2499) - fix: override severity on `rule` & `inline-rules` flags [`#2505`](ast-grep/ast-grep#2505) - chore(deps): update github artifact actions [`#2507`](ast-grep/ast-grep#2507) - chore(deps): update rust crate tree-sitter to v0.26.6 [`#2501`](ast-grep/ast-grep#2501) - chore(deps): update dependency web-tree-sitter to v0.26.6 [`#2500`](ast-grep/ast-grep#2500) - chore(deps): update dependency ava to v7 [`#2508`](ast-grep/ast-grep#2508) - chore(deps): update dependency oxlint to v1.50.0 [`#2495`](ast-grep/ast-grep#2495) - chore(deps): update dependency [@ast-grep/napi](https://github.com/ast-grep/napi) to v0.41.0 [`#2494`](ast-grep/ast-grep#2494) - fix: bump ls-types version [`#2525`](ast-grep/ast-grep#2525) - refactor: change versioned ast work [`a86b2ab`](ast-grep/ast-grep@a86b2ab) - fix: bump wasm-bindgen [`d23e334`](ast-grep/ast-grep@d23e334) - fix: fix wasm package [`0b92e94`](ast-grep/ast-grep@0b92e94) Renovate-Branch: renovate/2024.6-ast-grep-cli-0.x Change-Id: I91bcfa93167c7af0833afeb42df774621bad595c Priv-Id: ef06dc14816a639036bb167212251f765ce38ad8
The severity override doesn't work for the commands:
ast-grep scan --rule myRule.yml --errorast-grep scan --error --inline-rules <my rule>Summary by CodeRabbit
Bug Fixes
Tests