mirror of
https://github.com/denoland/deno.git
synced 2024-11-26 16:09:27 -05:00
feat: add "--ignore" to deno lint (#6934)
This commit is contained in:
parent
fed70c9903
commit
6706eb5515
5 changed files with 55 additions and 9 deletions
32
cli/flags.rs
32
cli/flags.rs
|
@ -55,6 +55,7 @@ pub enum DenoSubcommand {
|
||||||
},
|
},
|
||||||
Lint {
|
Lint {
|
||||||
files: Vec<String>,
|
files: Vec<String>,
|
||||||
|
ignore: Vec<String>,
|
||||||
rules: bool,
|
rules: bool,
|
||||||
},
|
},
|
||||||
Repl,
|
Repl,
|
||||||
|
@ -628,8 +629,16 @@ fn lint_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
||||||
Some(f) => f.map(String::from).collect(),
|
Some(f) => f.map(String::from).collect(),
|
||||||
None => vec![],
|
None => vec![],
|
||||||
};
|
};
|
||||||
|
let ignore = match matches.values_of("ignore") {
|
||||||
|
Some(f) => f.map(String::from).collect(),
|
||||||
|
None => vec![],
|
||||||
|
};
|
||||||
let rules = matches.is_present("rules");
|
let rules = matches.is_present("rules");
|
||||||
flags.subcommand = DenoSubcommand::Lint { files, rules };
|
flags.subcommand = DenoSubcommand::Lint {
|
||||||
|
files,
|
||||||
|
rules,
|
||||||
|
ignore,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn types_subcommand<'a, 'b>() -> App<'a, 'b> {
|
fn types_subcommand<'a, 'b>() -> App<'a, 'b> {
|
||||||
|
@ -1019,6 +1028,15 @@ Ignore linting a file by adding an ignore comment at the top of the file:
|
||||||
.long("rules")
|
.long("rules")
|
||||||
.help("List available rules"),
|
.help("List available rules"),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("ignore")
|
||||||
|
.long("ignore")
|
||||||
|
.requires("unstable")
|
||||||
|
.takes_value(true)
|
||||||
|
.use_delimiter(true)
|
||||||
|
.require_equals(true)
|
||||||
|
.help("Ignore linting particular source files."),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("files")
|
Arg::with_name("files")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
|
@ -1739,19 +1757,26 @@ mod tests {
|
||||||
subcommand: DenoSubcommand::Lint {
|
subcommand: DenoSubcommand::Lint {
|
||||||
files: vec!["script_1.ts".to_string(), "script_2.ts".to_string()],
|
files: vec!["script_1.ts".to_string(), "script_2.ts".to_string()],
|
||||||
rules: false,
|
rules: false,
|
||||||
|
ignore: vec![],
|
||||||
},
|
},
|
||||||
unstable: true,
|
unstable: true,
|
||||||
..Flags::default()
|
..Flags::default()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
let r = flags_from_vec_safe(svec!["deno", "lint", "--unstable"]);
|
let r = flags_from_vec_safe(svec![
|
||||||
|
"deno",
|
||||||
|
"lint",
|
||||||
|
"--unstable",
|
||||||
|
"--ignore=script_1.ts,script_2.ts"
|
||||||
|
]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
r.unwrap(),
|
r.unwrap(),
|
||||||
Flags {
|
Flags {
|
||||||
subcommand: DenoSubcommand::Lint {
|
subcommand: DenoSubcommand::Lint {
|
||||||
files: vec![],
|
files: vec![],
|
||||||
rules: false,
|
rules: false,
|
||||||
|
ignore: svec!["script_1.ts", "script_2.ts"],
|
||||||
},
|
},
|
||||||
unstable: true,
|
unstable: true,
|
||||||
..Flags::default()
|
..Flags::default()
|
||||||
|
@ -1764,7 +1789,8 @@ mod tests {
|
||||||
Flags {
|
Flags {
|
||||||
subcommand: DenoSubcommand::Lint {
|
subcommand: DenoSubcommand::Lint {
|
||||||
files: vec![],
|
files: vec![],
|
||||||
rules: true
|
rules: true,
|
||||||
|
ignore: vec![],
|
||||||
},
|
},
|
||||||
unstable: true,
|
unstable: true,
|
||||||
..Flags::default()
|
..Flags::default()
|
||||||
|
|
13
cli/lint.rs
13
cli/lint.rs
|
@ -25,8 +25,17 @@ use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use swc_ecmascript::parser::Syntax;
|
use swc_ecmascript::parser::Syntax;
|
||||||
|
|
||||||
pub async fn lint_files(args: Vec<String>) -> Result<(), ErrBox> {
|
pub async fn lint_files(
|
||||||
let target_files = collect_files(args)?;
|
args: Vec<String>,
|
||||||
|
ignore: Vec<String>,
|
||||||
|
) -> Result<(), ErrBox> {
|
||||||
|
let mut target_files = collect_files(args)?;
|
||||||
|
if !ignore.is_empty() {
|
||||||
|
// collect all files to be ignored
|
||||||
|
// and retain only files that should be linted.
|
||||||
|
let ignore_files = collect_files(ignore)?;
|
||||||
|
target_files.retain(|f| !ignore_files.contains(&f));
|
||||||
|
}
|
||||||
debug!("Found {} files", target_files.len());
|
debug!("Found {} files", target_files.len());
|
||||||
|
|
||||||
let error_count = Arc::new(AtomicUsize::new(0));
|
let error_count = Arc::new(AtomicUsize::new(0));
|
||||||
|
|
11
cli/main.rs
11
cli/main.rs
|
@ -345,6 +345,7 @@ async fn lint_command(
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
files: Vec<String>,
|
files: Vec<String>,
|
||||||
list_rules: bool,
|
list_rules: bool,
|
||||||
|
ignore: Vec<String>,
|
||||||
) -> Result<(), ErrBox> {
|
) -> Result<(), ErrBox> {
|
||||||
if !flags.unstable {
|
if !flags.unstable {
|
||||||
exit_unstable("lint");
|
exit_unstable("lint");
|
||||||
|
@ -355,7 +356,7 @@ async fn lint_command(
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
lint::lint_files(files).await
|
lint::lint_files(files, ignore).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn cache_command(flags: Flags, files: Vec<String>) -> Result<(), ErrBox> {
|
async fn cache_command(flags: Flags, files: Vec<String>) -> Result<(), ErrBox> {
|
||||||
|
@ -733,9 +734,11 @@ pub fn main() {
|
||||||
} => {
|
} => {
|
||||||
install_command(flags, module_url, args, name, root, force).boxed_local()
|
install_command(flags, module_url, args, name, root, force).boxed_local()
|
||||||
}
|
}
|
||||||
DenoSubcommand::Lint { files, rules } => {
|
DenoSubcommand::Lint {
|
||||||
lint_command(flags, files, rules).boxed_local()
|
files,
|
||||||
}
|
rules,
|
||||||
|
ignore,
|
||||||
|
} => lint_command(flags, files, rules, ignore).boxed_local(),
|
||||||
DenoSubcommand::Repl => run_repl(flags).boxed_local(),
|
DenoSubcommand::Repl => run_repl(flags).boxed_local(),
|
||||||
DenoSubcommand::Run { script } => run_command(flags, script).boxed_local(),
|
DenoSubcommand::Run { script } => run_command(flags, script).boxed_local(),
|
||||||
DenoSubcommand::Test {
|
DenoSubcommand::Test {
|
||||||
|
|
|
@ -2216,6 +2216,12 @@ itest!(deno_lint {
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
itest!(deno_lint_ignore {
|
||||||
|
args: "lint --unstable --ignore=lint/file1.js lint/",
|
||||||
|
output: "lint/expected_ignore.out",
|
||||||
|
exit_code: 1,
|
||||||
|
});
|
||||||
|
|
||||||
itest!(deno_lint_glob {
|
itest!(deno_lint_glob {
|
||||||
args: "lint --unstable lint/",
|
args: "lint --unstable lint/",
|
||||||
output: "lint/expected_glob.out",
|
output: "lint/expected_glob.out",
|
||||||
|
|
2
cli/tests/lint/expected_ignore.out
Normal file
2
cli/tests/lint/expected_ignore.out
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[WILDCARD]
|
||||||
|
Found 1 problems
|
Loading…
Reference in a new issue