1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

upgrade: deno_lint v0.1.8 (#6208)

This commit is contained in:
Bartek Iwańczuk 2020-06-09 18:40:08 +02:00 committed by GitHub
parent 1e0808d501
commit 8366f36873
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 100 additions and 25 deletions

4
Cargo.lock generated
View file

@ -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",

View file

@ -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"

View file

@ -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(

View file

@ -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() {

View file

@ -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,

View file

@ -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;

View 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
View file

@ -0,0 +1,3 @@
var a = 1,
b = 2,
c = 3;

9
cli/tests/lint/file2.ts Normal file
View 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) {}

View file

@ -0,0 +1,3 @@
// deno-lint-ignore-file
function foo(): any {}

View file

@ -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)