summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/flags.rs32
-rw-r--r--cli/lint.rs13
-rw-r--r--cli/main.rs11
-rw-r--r--cli/tests/integration_tests.rs6
-rw-r--r--cli/tests/lint/expected_ignore.out2
5 files changed, 55 insertions, 9 deletions
diff --git a/cli/flags.rs b/cli/flags.rs
index 993f681b5..49b577696 100644
--- a/cli/flags.rs
+++ b/cli/flags.rs
@@ -55,6 +55,7 @@ pub enum DenoSubcommand {
},
Lint {
files: Vec<String>,
+ ignore: Vec<String>,
rules: bool,
},
Repl,
@@ -628,8 +629,16 @@ fn lint_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
Some(f) => f.map(String::from).collect(),
None => vec![],
};
+ let ignore = match matches.values_of("ignore") {
+ Some(f) => f.map(String::from).collect(),
+ None => vec![],
+ };
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> {
@@ -1020,6 +1029,15 @@ Ignore linting a file by adding an ignore comment at the top of the file:
.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::with_name("files")
.takes_value(true)
.multiple(true)
@@ -1739,19 +1757,26 @@ mod tests {
subcommand: DenoSubcommand::Lint {
files: vec!["script_1.ts".to_string(), "script_2.ts".to_string()],
rules: false,
+ ignore: vec![],
},
unstable: true,
..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!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Lint {
files: vec![],
rules: false,
+ ignore: svec!["script_1.ts", "script_2.ts"],
},
unstable: true,
..Flags::default()
@@ -1764,7 +1789,8 @@ mod tests {
Flags {
subcommand: DenoSubcommand::Lint {
files: vec![],
- rules: true
+ rules: true,
+ ignore: vec![],
},
unstable: true,
..Flags::default()
diff --git a/cli/lint.rs b/cli/lint.rs
index e3013f302..3e9380d9d 100644
--- a/cli/lint.rs
+++ b/cli/lint.rs
@@ -25,8 +25,17 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, Mutex};
use swc_ecmascript::parser::Syntax;
-pub async fn lint_files(args: Vec<String>) -> Result<(), ErrBox> {
- let target_files = collect_files(args)?;
+pub async fn lint_files(
+ 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());
let error_count = Arc::new(AtomicUsize::new(0));
diff --git a/cli/main.rs b/cli/main.rs
index 5400d3f65..27948e14f 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -345,6 +345,7 @@ async fn lint_command(
flags: Flags,
files: Vec<String>,
list_rules: bool,
+ ignore: Vec<String>,
) -> Result<(), ErrBox> {
if !flags.unstable {
exit_unstable("lint");
@@ -355,7 +356,7 @@ async fn lint_command(
return Ok(());
}
- lint::lint_files(files).await
+ lint::lint_files(files, ignore).await
}
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()
}
- DenoSubcommand::Lint { files, rules } => {
- lint_command(flags, files, rules).boxed_local()
- }
+ DenoSubcommand::Lint {
+ files,
+ rules,
+ ignore,
+ } => lint_command(flags, files, rules, ignore).boxed_local(),
DenoSubcommand::Repl => run_repl(flags).boxed_local(),
DenoSubcommand::Run { script } => run_command(flags, script).boxed_local(),
DenoSubcommand::Test {
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index 9ffcad184..bb7ba0d6f 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -2216,6 +2216,12 @@ itest!(deno_lint {
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 {
args: "lint --unstable lint/",
output: "lint/expected_glob.out",
diff --git a/cli/tests/lint/expected_ignore.out b/cli/tests/lint/expected_ignore.out
new file mode 100644
index 000000000..6041d1c6a
--- /dev/null
+++ b/cli/tests/lint/expected_ignore.out
@@ -0,0 +1,2 @@
+[WILDCARD]
+Found 1 problems