Skip to content

Commit 9ef42dc

Browse files
feat: rename SeverityArg
1 parent 863838a commit 9ef42dc

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

crates/cli/src/scan.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use ast_grep_config::{
88
use ast_grep_core::{NodeMatch, StrDoc};
99
use clap::Args;
1010
use ignore::WalkParallel;
11-
use regex::Regex;
1211

1312
use crate::config::{find_rules, read_rule_file, register_custom_language};
1413
use crate::lang::SgLang;
@@ -18,7 +17,7 @@ use crate::print::{
1817
};
1918
use crate::utils::ErrorContext as EC;
2019
use crate::utils::RuleOverwrite;
21-
use crate::utils::{filter_file_interactive, ContextArgs, InputArgs, OutputArgs, SeverityArg};
20+
use crate::utils::{filter_file_interactive, ContextArgs, InputArgs, OutputArgs, OverwriteArgs};
2221
use crate::utils::{FileTrace, RuleTrace, ScanTrace};
2322
use crate::utils::{Items, PathWorker, StdInWorker, Worker};
2423

@@ -44,13 +43,6 @@ pub struct ScanArg {
4443
#[clap(long, conflicts_with = "rule", value_name = "RULE_TEXT")]
4544
inline_rules: Option<String>,
4645

47-
/// Scan the codebase with rules with ids matching REGEX.
48-
///
49-
/// This flags conflicts with --rule. It is useful to scan with a subset of rules from a large
50-
/// set of rule definitions within a project.
51-
#[clap(long, conflicts_with = "rule", value_name = "REGEX")]
52-
filter: Option<Regex>,
53-
5446
/// Output warning/error messages in GitHub Action format.
5547
///
5648
/// Currently, only GitHub is supported.
@@ -62,7 +54,7 @@ pub struct ScanArg {
6254

6355
/// severity related options
6456
#[clap(flatten)]
65-
severity: SeverityArg,
57+
overwrite: OverwriteArgs,
6658

6759
/// input related options
6860
#[clap(flatten)]
@@ -127,7 +119,7 @@ impl<P: Printer> ScanWithConfig<P> {
127119
.with_context(|| EC::ParseRule("INLINE_RULES".into()))?;
128120
RuleCollection::try_new(rules).context(EC::GlobPattern)?
129121
} else {
130-
let overwrite = RuleOverwrite::new(&arg.severity, &arg.filter)?;
122+
let overwrite = RuleOverwrite::new(&arg.overwrite)?;
131123
let (configs, r_stats) = find_rules(arg.config.take(), overwrite)?;
132124
rule_trace = r_stats;
133125
configs
@@ -364,7 +356,6 @@ rule:
364356
fn default_scan_arg() -> ScanArg {
365357
ScanArg {
366358
config: None,
367-
filter: None,
368359
rule: None,
369360
inline_rules: None,
370361
report_style: ReportStyle::Rich,
@@ -376,7 +367,8 @@ rule:
376367
globs: vec![],
377368
threads: 0,
378369
},
379-
severity: SeverityArg {
370+
overwrite: OverwriteArgs {
371+
filter: None,
380372
error: None,
381373
warning: None,
382374
info: None,

crates/cli/src/utils/args.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use ignore::{
99
overrides::{Override, OverrideBuilder},
1010
WalkBuilder, WalkParallel,
1111
};
12+
use regex::Regex;
1213
use serde::{Deserialize, Serialize};
1314

1415
use std::path::PathBuf;
@@ -275,7 +276,13 @@ impl NoIgnore {
275276
}
276277

277278
#[derive(Args, Debug)]
278-
pub struct SeverityArg {
279+
pub struct OverwriteArgs {
280+
/// Scan the codebase with rules with ids matching REGEX.
281+
///
282+
/// This flags conflicts with --rule. It is useful to scan with a subset of rules from a large
283+
/// set of rule definitions within a project.
284+
#[clap(long, conflicts_with = "rule", value_name = "REGEX")]
285+
pub filter: Option<Regex>,
279286
/// Set rule severity to error
280287
///
281288
/// This flag sets the specified RULE_ID's severity to error. You can specify multiple rules by using the flag multiple times,

crates/cli/src/utils/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod rule_overwrite;
55
mod tracing;
66
mod worker;
77

8-
pub use args::{ContextArgs, InputArgs, OutputArgs, SeverityArg};
8+
pub use args::{ContextArgs, InputArgs, OutputArgs, OverwriteArgs};
99
pub use debug_query::DebugFormat;
1010
pub use error_context::{exit_with_error, ErrorContext};
1111
pub use rule_overwrite::RuleOverwrite;

crates/cli/src/utils/rule_overwrite.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::SeverityArg;
1+
use super::OverwriteArgs;
22
use crate::lang::SgLang;
33
use crate::utils::ErrorContext as EC;
44

@@ -33,7 +33,7 @@ fn read_severity(
3333
}
3434

3535
impl RuleOverwrite {
36-
pub fn new(cli: &SeverityArg, filter: &Option<Regex>) -> Result<Self> {
36+
pub fn new(cli: &OverwriteArgs) -> Result<Self> {
3737
let mut default_severity = None;
3838
let mut by_rule_id = HashMap::new();
3939
read_severity(
@@ -69,7 +69,7 @@ impl RuleOverwrite {
6969
Ok(Self {
7070
default_severity,
7171
by_rule_id,
72-
rule_filter: filter.clone(),
72+
rule_filter: cli.filter.clone(),
7373
})
7474
}
7575

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy