mirror of
https://github.com/denoland/deno.git
synced 2024-12-27 09:39:08 -05:00
upgrade: deno_lint v0.1.8 (#6208)
This commit is contained in:
parent
1e0808d501
commit
8366f36873
11 changed files with 100 additions and 25 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -506,9 +506,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "deno_lint"
|
||||
version = "0.1.7"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77a3ec96c92609aa121d085f3a1351d3836e55b78a4b8ce79ea771c2ad9bd80b"
|
||||
checksum = "0ca00aa150fff66457af99578360267a988b44b3dd0d7d503571b2e98b15094d"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"regex",
|
||||
|
|
|
@ -20,7 +20,7 @@ deno_typescript = { path = "../deno_typescript", version = "0.47.1" }
|
|||
|
||||
[dependencies]
|
||||
deno_core = { path = "../core", version = "0.47.1" }
|
||||
deno_lint = { version = "0.1.7" }
|
||||
deno_lint = { version = "0.1.8" }
|
||||
deno_typescript = { path = "../deno_typescript", version = "0.47.1" }
|
||||
|
||||
atty = "0.2.14"
|
||||
|
|
13
cli/flags.rs
13
cli/flags.rs
|
@ -911,10 +911,17 @@ fn lint_subcommand<'a, 'b>() -> App<'a, 'b> {
|
|||
.about("Lint source files")
|
||||
.long_about(
|
||||
"Lint JavaScript/TypeScript source code.
|
||||
deno lint myfile1.ts myfile2.js
|
||||
deno lint --unstable myfile1.ts myfile2.js
|
||||
|
||||
Ignore diagnostics on next line preceding it with an ignore comment and code:
|
||||
// deno-lint-ignore no-explicit-any",
|
||||
Ignore diagnostics on the next line by preceding it with an ignore comment and
|
||||
rule name:
|
||||
// deno-lint-ignore no-explicit-any
|
||||
|
||||
// deno-lint-ignore require-await no-empty
|
||||
|
||||
Ignore linting a file by adding an ignore comment at the top of the file:
|
||||
// deno-lint-ignore-file
|
||||
",
|
||||
)
|
||||
.arg(unstable_arg())
|
||||
.arg(
|
||||
|
|
|
@ -339,11 +339,13 @@ async fn lint_command(flags: Flags, files: Vec<String>) -> Result<(), ErrBox> {
|
|||
.fetch_source_file(&specifier, None, Permissions::allow_all())
|
||||
.await?;
|
||||
let source_code = String::from_utf8(source_file.source_code)?;
|
||||
let syntax = swc_util::get_syntax_for_media_type(source_file.media_type);
|
||||
|
||||
let mut linter = deno_lint::linter::Linter::default();
|
||||
let lint_rules = deno_lint::rules::get_all_rules();
|
||||
|
||||
let file_diagnostics = linter.lint(file, source_code, lint_rules)?;
|
||||
let file_diagnostics =
|
||||
linter.lint(file, source_code, syntax, lint_rules)?;
|
||||
|
||||
error_counts += file_diagnostics.len();
|
||||
for d in file_diagnostics.iter() {
|
||||
|
|
|
@ -52,6 +52,24 @@ fn get_default_ts_config() -> TsConfig {
|
|||
ts_config
|
||||
}
|
||||
|
||||
pub fn get_syntax_for_media_type(media_type: MediaType) -> Syntax {
|
||||
match media_type {
|
||||
MediaType::JavaScript => Syntax::Es(get_default_es_config()),
|
||||
MediaType::JSX => {
|
||||
let mut config = get_default_es_config();
|
||||
config.jsx = true;
|
||||
Syntax::Es(config)
|
||||
}
|
||||
MediaType::TypeScript => Syntax::Typescript(get_default_ts_config()),
|
||||
MediaType::TSX => {
|
||||
let mut config = get_default_ts_config();
|
||||
config.tsx = true;
|
||||
Syntax::Typescript(config)
|
||||
}
|
||||
_ => Syntax::Es(get_default_es_config()),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SwcDiagnosticBuffer {
|
||||
pub diagnostics: Vec<String>,
|
||||
|
@ -169,21 +187,7 @@ impl AstParser {
|
|||
handler: &self.handler,
|
||||
};
|
||||
|
||||
let syntax = match media_type {
|
||||
MediaType::JavaScript => Syntax::Es(get_default_es_config()),
|
||||
MediaType::JSX => {
|
||||
let mut config = get_default_es_config();
|
||||
config.jsx = true;
|
||||
Syntax::Es(config)
|
||||
}
|
||||
MediaType::TypeScript => Syntax::Typescript(get_default_ts_config()),
|
||||
MediaType::TSX => {
|
||||
let mut config = get_default_ts_config();
|
||||
config.tsx = true;
|
||||
Syntax::Typescript(config)
|
||||
}
|
||||
_ => Syntax::Es(get_default_es_config()),
|
||||
};
|
||||
let syntax = get_syntax_for_media_type(media_type);
|
||||
|
||||
let lexer = Lexer::new(
|
||||
session,
|
||||
|
|
|
@ -1939,6 +1939,12 @@ itest!(proto_exploit {
|
|||
output: "proto_exploit.js.out",
|
||||
});
|
||||
|
||||
itest!(deno_lint {
|
||||
args: "lint --unstable lint/file1.js lint/file2.ts lint/ignored_file.ts",
|
||||
output: "lint/expected.out",
|
||||
exit_code: 1,
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn cafile_fetch() {
|
||||
use url::Url;
|
||||
|
|
36
cli/tests/lint/expected.out
Normal file
36
cli/tests/lint/expected.out
Normal file
|
@ -0,0 +1,36 @@
|
|||
(no-var) `var` keyword is not allowed
|
||||
var a = 1,
|
||||
~~~~~~~~~~
|
||||
at [WILDCARD]file1.js:1:0
|
||||
|
||||
(single-var-declarator) Multiple variable declarators are not allowed
|
||||
var a = 1,
|
||||
~~~~~~~~~~
|
||||
at [WILDCARD]file1.js:1:0
|
||||
|
||||
(no-empty) Empty block statement
|
||||
} catch (e) {}
|
||||
~~
|
||||
at [WILDCARD]file2.ts:3:12
|
||||
|
||||
(ban-unused-ignore) Ignore for code "require-await" was not used.
|
||||
// deno-lint-ignore no-explicit-any require-await
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
at [WILDCARD]file2.ts:5:0
|
||||
|
||||
(no-empty-function) Empty functions are not allowed
|
||||
function foo(): any {}
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
at [WILDCARD]file2.ts:6:0
|
||||
|
||||
(ban-untagged-ignore) Ignore directive requires lint rule code
|
||||
// deno-lint-ignore
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
at [WILDCARD]file2.ts:8:0
|
||||
|
||||
(no-empty) Empty block statement
|
||||
while (false) {}
|
||||
~~
|
||||
at [WILDCARD]file2.ts:9:14
|
||||
|
||||
Found 7 problems
|
3
cli/tests/lint/file1.js
Normal file
3
cli/tests/lint/file1.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
var a = 1,
|
||||
b = 2,
|
||||
c = 3;
|
9
cli/tests/lint/file2.ts
Normal file
9
cli/tests/lint/file2.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
try {
|
||||
await Deno.open("./some/file.txt");
|
||||
} catch (e) {}
|
||||
|
||||
// deno-lint-ignore no-explicit-any require-await
|
||||
function foo(): any {}
|
||||
|
||||
// deno-lint-ignore
|
||||
while (false) {}
|
3
cli/tests/lint/ignored_file.ts
Normal file
3
cli/tests/lint/ignored_file.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
// deno-lint-ignore-file
|
||||
|
||||
function foo(): any {}
|
|
@ -61,9 +61,14 @@ def eslint():
|
|||
"eslint")
|
||||
# Find all *directories* in the main repo that contain .ts/.js files.
|
||||
source_files = get_sources(root_path, [
|
||||
"*.js", "*.ts", ":!:cli/tests/swc_syntax_error.ts",
|
||||
":!:std/**/testdata/*", ":!:std/**/node_modules/*",
|
||||
":!:cli/compilers/wasm_wrap.js", ":!:cli/tests/error_syntax.js"
|
||||
"*.js",
|
||||
"*.ts",
|
||||
":!:cli/tests/swc_syntax_error.ts",
|
||||
":!:std/**/testdata/*",
|
||||
":!:std/**/node_modules/*",
|
||||
":!:cli/compilers/wasm_wrap.js",
|
||||
":!:cli/tests/error_syntax.js",
|
||||
":!:cli/tests/lint/**",
|
||||
])
|
||||
if source_files:
|
||||
print_command("eslint", source_files)
|
||||
|
|
Loading…
Reference in a new issue