summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-06-09 18:40:08 +0200
committerGitHub <noreply@github.com>2020-06-09 18:40:08 +0200
commit8366f36873bb7311f533e5e49d9ad13581b0b5c1 (patch)
treeee7beb3895d7ec1e3e1bc237627ecfff7c265438
parent1e0808d501cf9adea65e7cacd123ea4fea06a13a (diff)
upgrade: deno_lint v0.1.8 (#6208)
-rw-r--r--Cargo.lock4
-rw-r--r--cli/Cargo.toml2
-rw-r--r--cli/flags.rs13
-rw-r--r--cli/main.rs4
-rw-r--r--cli/swc_util.rs34
-rw-r--r--cli/tests/integration_tests.rs6
-rw-r--r--cli/tests/lint/expected.out36
-rw-r--r--cli/tests/lint/file1.js3
-rw-r--r--cli/tests/lint/file2.ts9
-rw-r--r--cli/tests/lint/ignored_file.ts3
-rwxr-xr-xtools/lint.py11
11 files changed, 100 insertions, 25 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 9eb1e6122..eb3349c1f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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",
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
index 01a240d3a..667a6e2c3 100644
--- a/cli/Cargo.toml
+++ b/cli/Cargo.toml
@@ -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"
diff --git a/cli/flags.rs b/cli/flags.rs
index fc16d378d..f630f4bbf 100644
--- a/cli/flags.rs
+++ b/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(
diff --git a/cli/main.rs b/cli/main.rs
index 909295439..d3be3bdbe 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -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() {
diff --git a/cli/swc_util.rs b/cli/swc_util.rs
index 0d75877bf..eb41fbc34 100644
--- a/cli/swc_util.rs
+++ b/cli/swc_util.rs
@@ -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,
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index 2da5eebcb..d70527881 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -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;
diff --git a/cli/tests/lint/expected.out b/cli/tests/lint/expected.out
new file mode 100644
index 000000000..0b0654298
--- /dev/null
+++ b/cli/tests/lint/expected.out
@@ -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
diff --git a/cli/tests/lint/file1.js b/cli/tests/lint/file1.js
new file mode 100644
index 000000000..d74b6f47a
--- /dev/null
+++ b/cli/tests/lint/file1.js
@@ -0,0 +1,3 @@
+var a = 1,
+ b = 2,
+ c = 3;
diff --git a/cli/tests/lint/file2.ts b/cli/tests/lint/file2.ts
new file mode 100644
index 000000000..f0f3a3ba3
--- /dev/null
+++ b/cli/tests/lint/file2.ts
@@ -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) {}
diff --git a/cli/tests/lint/ignored_file.ts b/cli/tests/lint/ignored_file.ts
new file mode 100644
index 000000000..97befafa3
--- /dev/null
+++ b/cli/tests/lint/ignored_file.ts
@@ -0,0 +1,3 @@
+// deno-lint-ignore-file
+
+function foo(): any {}
diff --git a/tools/lint.py b/tools/lint.py
index 0e71fa946..0ff0b16d7 100755
--- a/tools/lint.py
+++ b/tools/lint.py
@@ -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)