mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 04:48:52 -05:00
This reverts commit c5c48f845a
.
This commit is contained in:
parent
78429496e0
commit
aebbdd5cc2
4 changed files with 39 additions and 21 deletions
25
cli/flags.rs
25
cli/flags.rs
|
@ -1000,18 +1000,18 @@ fn lint_subcommand<'a, 'b>() -> App<'a, 'b> {
|
||||||
.about("Lint source files")
|
.about("Lint source files")
|
||||||
.long_about(
|
.long_about(
|
||||||
"Lint JavaScript/TypeScript source code.
|
"Lint JavaScript/TypeScript source code.
|
||||||
deno lint
|
deno lint --unstable
|
||||||
deno lint myfile1.ts myfile2.js
|
deno lint --unstable myfile1.ts myfile2.js
|
||||||
|
|
||||||
Print result as JSON:
|
Print result as JSON:
|
||||||
deno lint --unstable --json
|
deno lint --unstable --json
|
||||||
|
|
||||||
Read from stdin:
|
Read from stdin:
|
||||||
cat file.ts | deno lint -
|
cat file.ts | deno lint --unstable -
|
||||||
cat file.ts | deno lint --unstable --json -
|
cat file.ts | deno lint --unstable --json -
|
||||||
|
|
||||||
List available rules:
|
List available rules:
|
||||||
deno lint --rules
|
deno lint --unstable --rules
|
||||||
|
|
||||||
Ignore diagnostics on the next line by preceding it with an ignore comment and
|
Ignore diagnostics on the next line by preceding it with an ignore comment and
|
||||||
rule name:
|
rule name:
|
||||||
|
@ -1036,6 +1036,7 @@ Ignore linting a file by adding an ignore comment at the top of the file:
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("ignore")
|
Arg::with_name("ignore")
|
||||||
.long("ignore")
|
.long("ignore")
|
||||||
|
.requires("unstable")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.use_delimiter(true)
|
.use_delimiter(true)
|
||||||
.require_equals(true)
|
.require_equals(true)
|
||||||
|
@ -1045,7 +1046,6 @@ Ignore linting a file by adding an ignore comment at the top of the file:
|
||||||
Arg::with_name("json")
|
Arg::with_name("json")
|
||||||
.long("json")
|
.long("json")
|
||||||
.help("Output lint result in JSON format")
|
.help("Output lint result in JSON format")
|
||||||
.requires("unstable")
|
|
||||||
.takes_value(false),
|
.takes_value(false),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
|
@ -1834,8 +1834,13 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lint() {
|
fn lint() {
|
||||||
let r =
|
let r = flags_from_vec_safe(svec![
|
||||||
flags_from_vec_safe(svec!["deno", "lint", "script_1.ts", "script_2.ts"]);
|
"deno",
|
||||||
|
"lint",
|
||||||
|
"--unstable",
|
||||||
|
"script_1.ts",
|
||||||
|
"script_2.ts"
|
||||||
|
]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
r.unwrap(),
|
r.unwrap(),
|
||||||
Flags {
|
Flags {
|
||||||
|
@ -1848,6 +1853,7 @@ mod tests {
|
||||||
json: false,
|
json: false,
|
||||||
ignore: vec![],
|
ignore: vec![],
|
||||||
},
|
},
|
||||||
|
unstable: true,
|
||||||
..Flags::default()
|
..Flags::default()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -1855,6 +1861,7 @@ mod tests {
|
||||||
let r = flags_from_vec_safe(svec![
|
let r = flags_from_vec_safe(svec![
|
||||||
"deno",
|
"deno",
|
||||||
"lint",
|
"lint",
|
||||||
|
"--unstable",
|
||||||
"--ignore=script_1.ts,script_2.ts"
|
"--ignore=script_1.ts,script_2.ts"
|
||||||
]);
|
]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -1869,11 +1876,12 @@ mod tests {
|
||||||
PathBuf::from("script_2.ts")
|
PathBuf::from("script_2.ts")
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
unstable: true,
|
||||||
..Flags::default()
|
..Flags::default()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
let r = flags_from_vec_safe(svec!["deno", "lint", "--rules"]);
|
let r = flags_from_vec_safe(svec!["deno", "lint", "--unstable", "--rules"]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
r.unwrap(),
|
r.unwrap(),
|
||||||
Flags {
|
Flags {
|
||||||
|
@ -1883,6 +1891,7 @@ mod tests {
|
||||||
json: false,
|
json: false,
|
||||||
ignore: vec![],
|
ignore: vec![],
|
||||||
},
|
},
|
||||||
|
unstable: true,
|
||||||
..Flags::default()
|
..Flags::default()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -220,12 +220,16 @@ async fn install_command(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn lint_command(
|
async fn lint_command(
|
||||||
_flags: Flags,
|
flags: Flags,
|
||||||
files: Vec<PathBuf>,
|
files: Vec<PathBuf>,
|
||||||
list_rules: bool,
|
list_rules: bool,
|
||||||
ignore: Vec<PathBuf>,
|
ignore: Vec<PathBuf>,
|
||||||
json: bool,
|
json: bool,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
|
if !flags.unstable {
|
||||||
|
exit_unstable("lint");
|
||||||
|
}
|
||||||
|
|
||||||
if list_rules {
|
if list_rules {
|
||||||
lint::print_rules_list();
|
lint::print_rules_list();
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|
|
@ -33,6 +33,7 @@ fn std_tests() {
|
||||||
fn std_lint() {
|
fn std_lint() {
|
||||||
let status = util::deno_cmd()
|
let status = util::deno_cmd()
|
||||||
.arg("lint")
|
.arg("lint")
|
||||||
|
.arg("--unstable")
|
||||||
.arg(format!(
|
.arg(format!(
|
||||||
"--ignore={}",
|
"--ignore={}",
|
||||||
util::root_path().join("std/node/tests").to_string_lossy()
|
util::root_path().join("std/node/tests").to_string_lossy()
|
||||||
|
@ -2847,13 +2848,13 @@ itest!(deno_test_coverage {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(deno_lint {
|
itest!(deno_lint {
|
||||||
args: "lint lint/file1.js lint/file2.ts lint/ignored_file.ts",
|
args: "lint --unstable lint/file1.js lint/file2.ts lint/ignored_file.ts",
|
||||||
output: "lint/expected.out",
|
output: "lint/expected.out",
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(deno_lint_quiet {
|
itest!(deno_lint_quiet {
|
||||||
args: "lint --quiet lint/file1.js",
|
args: "lint --unstable --quiet lint/file1.js",
|
||||||
output: "lint/expected_quiet.out",
|
output: "lint/expected_quiet.out",
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
});
|
});
|
||||||
|
@ -2866,19 +2867,19 @@ itest!(deno_lint_json {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(deno_lint_ignore {
|
itest!(deno_lint_ignore {
|
||||||
args: "lint --ignore=lint/file1.js,lint/malformed.js lint/",
|
args: "lint --unstable --ignore=lint/file1.js,lint/malformed.js lint/",
|
||||||
output: "lint/expected_ignore.out",
|
output: "lint/expected_ignore.out",
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(deno_lint_glob {
|
itest!(deno_lint_glob {
|
||||||
args: "lint --ignore=lint/malformed.js lint/",
|
args: "lint --unstable --ignore=lint/malformed.js lint/",
|
||||||
output: "lint/expected_glob.out",
|
output: "lint/expected_glob.out",
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(deno_lint_from_stdin {
|
itest!(deno_lint_from_stdin {
|
||||||
args: "lint -",
|
args: "lint --unstable -",
|
||||||
input: Some("let a: any;"),
|
input: Some("let a: any;"),
|
||||||
output: "lint/expected_from_stdin.out",
|
output: "lint/expected_from_stdin.out",
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
|
@ -2892,14 +2893,14 @@ itest!(deno_lint_from_stdin_json {
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(deno_lint_rules {
|
itest!(deno_lint_rules {
|
||||||
args: "lint --rules",
|
args: "lint --unstable --rules",
|
||||||
output: "lint/expected_rules.out",
|
output: "lint/expected_rules.out",
|
||||||
exit_code: 0,
|
exit_code: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Make sure that the rules are printed if quiet option is enabled.
|
// Make sure that the rules are printed if quiet option is enabled.
|
||||||
itest!(deno_lint_rules_quiet {
|
itest!(deno_lint_rules_quiet {
|
||||||
args: "lint --rules -q",
|
args: "lint --unstable --rules -q",
|
||||||
output: "lint/expected_rules.out",
|
output: "lint/expected_rules.out",
|
||||||
exit_code: 0,
|
exit_code: 0,
|
||||||
});
|
});
|
||||||
|
@ -4060,6 +4061,7 @@ fn lint_ignore_unexplicit_files() {
|
||||||
let output = util::deno_cmd()
|
let output = util::deno_cmd()
|
||||||
.current_dir(util::root_path())
|
.current_dir(util::root_path())
|
||||||
.arg("lint")
|
.arg("lint")
|
||||||
|
.arg("--unstable")
|
||||||
.arg("--ignore=./")
|
.arg("--ignore=./")
|
||||||
.stderr(std::process::Stdio::piped())
|
.stderr(std::process::Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
|
|
|
@ -2,15 +2,18 @@
|
||||||
|
|
||||||
Deno ships with a built in code linter for JavaScript and TypeScript.
|
Deno ships with a built in code linter for JavaScript and TypeScript.
|
||||||
|
|
||||||
|
**Note: linter is a new feature and still unstable thus it requires `--unstable`
|
||||||
|
flag**
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
# lint all JS/TS files in the current directory and subdirectories
|
# lint all JS/TS files in the current directory and subdirectories
|
||||||
deno lint
|
deno lint --unstable
|
||||||
# lint specific files
|
# lint specific files
|
||||||
deno lint myfile1.ts myfile2.ts
|
deno lint --unstable myfile1.ts myfile2.ts
|
||||||
# read from stdin
|
# print result as JSON
|
||||||
cat file.ts | deno lint -
|
|
||||||
# print result as JSON (output is subject to change hence --unstable flag)
|
|
||||||
deno lint --unstable --json
|
deno lint --unstable --json
|
||||||
|
# read from stdin
|
||||||
|
cat file.ts | deno lint --unstable -
|
||||||
```
|
```
|
||||||
|
|
||||||
For more detail, run `deno lint --help`.
|
For more detail, run `deno lint --help`.
|
||||||
|
|
Loading…
Reference in a new issue