summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-03-21 14:18:59 -0700
committerGitHub <noreply@github.com>2024-03-21 14:18:59 -0700
commitffbcad3800ef086bad791c1c640b62fd72d60172 (patch)
treef350a54862928e19ba93a75b71a4c4bebcc974f3 /tests
parent2166aa8fb6be5fdd6d607db587e236de11b6fb91 (diff)
feat(lint): `deno lint --fix` and lsp quick fixes (#22615)
Adds a `--fix` option to deno lint. This currently doesn't work for basically any rules, but we can add them over time to deno lint.
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/lsp_tests.rs98
-rw-r--r--tests/specs/lint/lint_fix/__test__.jsonc17
-rw-r--r--tests/specs/lint/lint_fix/a.ts4
-rw-r--r--tests/specs/lint/lint_fix/a_fixed.out4
-rw-r--r--tests/specs/lint/lint_fix/lint.out2
-rw-r--r--tests/specs/lint/lint_fix/lint_fixed.out1
-rw-r--r--tests/testdata/cat.ts12
-rw-r--r--tests/testdata/lint/expected_from_stdin.out2
-rw-r--r--tests/testdata/lint/expected_quiet.out4
-rw-r--r--tests/testdata/lint/with_config.out4
-rw-r--r--tests/testdata/lint/with_config_and_flags.out4
-rw-r--r--tests/testdata/lint/with_config_without_tags.out4
12 files changed, 138 insertions, 18 deletions
diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs
index 09178cd46..c5913e07b 100644
--- a/tests/integration/lsp_tests.rs
+++ b/tests/integration/lsp_tests.rs
@@ -10198,6 +10198,104 @@ console.log(snake_case);
}
#[test]
+fn lsp_code_actions_lint_fixes() {
+ let context = TestContextBuilder::new().use_temp_cwd().build();
+ let mut client = context.new_lsp_command().build();
+ client.initialize_default();
+ let diagnostics = client.did_open(json!({
+ "textDocument": {
+ "uri": "file:///a/file.ts",
+ "languageId": "typescript",
+ "version": 1,
+ "text": "window;",
+ }
+ }));
+ let diagnostics = diagnostics.all();
+ let diagnostic = &diagnostics[0];
+ let res = client.write_request(
+ "textDocument/codeAction",
+ json!({
+ "textDocument": {
+ "uri": "file:///a/file.ts"
+ },
+ "range": {
+ "start": { "line": 0, "character": 0 },
+ "end": { "line": 0, "character": 6 }
+ },
+ "context": {
+ "diagnostics": [diagnostic],
+ "only": ["quickfix"]
+ }
+ }),
+ );
+ assert_eq!(
+ res,
+ json!([{
+ "title": "Rename window to globalThis",
+ "kind": "quickfix",
+ "diagnostics": [diagnostic],
+ "edit": {
+ "changes": {
+ "file:///a/file.ts": [{
+ "range": {
+ "start": { "line": 0, "character": 0 },
+ "end": { "line": 0, "character": 6 }
+ },
+ "newText": "globalThis"
+ }]
+ }
+ }
+ }, {
+ "title": "Disable no-window for this line",
+ "kind": "quickfix",
+ "diagnostics": [diagnostic],
+ "edit": {
+ "changes": {
+ "file:///a/file.ts": [{
+ "range": {
+ "start": { "line": 0, "character": 0 },
+ "end": { "line": 0, "character": 0 }
+ },
+ "newText": "// deno-lint-ignore no-window\n"
+ }]
+ }
+ }
+ }, {
+ "title": "Disable no-window for the entire file",
+ "kind": "quickfix",
+ "diagnostics": [diagnostic],
+ "edit": {
+ "changes": {
+ "file:///a/file.ts": [{
+ "range": {
+ "start": { "line": 0, "character": 0 },
+ "end": { "line": 0, "character": 0 }
+ },
+ "newText": "// deno-lint-ignore-file no-window\n"
+ }]
+ }
+ }
+ }, {
+ "title": "Ignore lint errors for the entire file",
+ "kind": "quickfix",
+ "diagnostics": [diagnostic],
+ "edit": {
+ "changes": {
+ "file:///a/file.ts": [{
+ "range": {
+ "start": { "line": 0, "character": 0 },
+ "end": { "line": 0, "character": 0 }
+ },
+ "newText": "// deno-lint-ignore-file\n"
+ }]
+ }
+ }
+ }])
+ );
+ client.shutdown();
+}
+
+#[test]
fn lsp_lint_with_config() {
let context = TestContextBuilder::new().use_temp_cwd().build();
let temp_dir = context.temp_dir();
diff --git a/tests/specs/lint/lint_fix/__test__.jsonc b/tests/specs/lint/lint_fix/__test__.jsonc
new file mode 100644
index 000000000..53736586f
--- /dev/null
+++ b/tests/specs/lint/lint_fix/__test__.jsonc
@@ -0,0 +1,17 @@
+{
+ "tempDir": true,
+ "steps": [{
+ "args": "lint --rules-tags=recommended,jsr",
+ "output": "lint.out",
+ "exitCode": 1
+ }, {
+ "args": "lint --fix --rules-tags=recommended,jsr",
+ "output": "lint_fixed.out"
+ }, {
+ "args": "lint --rules-tags=recommended,jsr",
+ "output": "lint_fixed.out"
+ }, {
+ "args": "run --allow-read --quiet http://localhost:4545/cat.ts a.ts",
+ "output": "a_fixed.out"
+ }]
+}
diff --git a/tests/specs/lint/lint_fix/a.ts b/tests/specs/lint/lint_fix/a.ts
new file mode 100644
index 000000000..6a1b87bc4
--- /dev/null
+++ b/tests/specs/lint/lint_fix/a.ts
@@ -0,0 +1,4 @@
+import { Type } from "./test.ts";
+export type MyType = Type;
+console.log(window.value);
+window.fetch;
diff --git a/tests/specs/lint/lint_fix/a_fixed.out b/tests/specs/lint/lint_fix/a_fixed.out
new file mode 100644
index 000000000..5193be18e
--- /dev/null
+++ b/tests/specs/lint/lint_fix/a_fixed.out
@@ -0,0 +1,4 @@
+import type { Type } from "./test.ts";
+export type MyType = Type;
+console.log(globalThis.value);
+globalThis.fetch;
diff --git a/tests/specs/lint/lint_fix/lint.out b/tests/specs/lint/lint_fix/lint.out
new file mode 100644
index 000000000..e292c2881
--- /dev/null
+++ b/tests/specs/lint/lint_fix/lint.out
@@ -0,0 +1,2 @@
+[WILDCARD]Found 4 problems (4 fixable via --fix)
+Checked 1 file
diff --git a/tests/specs/lint/lint_fix/lint_fixed.out b/tests/specs/lint/lint_fix/lint_fixed.out
new file mode 100644
index 000000000..c05ac45a1
--- /dev/null
+++ b/tests/specs/lint/lint_fix/lint_fixed.out
@@ -0,0 +1 @@
+Checked 1 file
diff --git a/tests/testdata/cat.ts b/tests/testdata/cat.ts
index 39745da89..62c82ebca 100644
--- a/tests/testdata/cat.ts
+++ b/tests/testdata/cat.ts
@@ -1,10 +1,4 @@
-import { copy } from "../../tests/util/std/streams/copy.ts";
-async function main() {
- for (let i = 1; i < Deno.args.length; i++) {
- const filename = Deno.args[i];
- const file = await Deno.open(filename);
- await copy(file, Deno.stdout);
- }
-}
+const filename = Deno.args[0];
+using file = await Deno.open(filename);
-main();
+await file.readable.pipeTo(Deno.stdout.writable);
diff --git a/tests/testdata/lint/expected_from_stdin.out b/tests/testdata/lint/expected_from_stdin.out
index 59f32166f..735b271f5 100644
--- a/tests/testdata/lint/expected_from_stdin.out
+++ b/tests/testdata/lint/expected_from_stdin.out
@@ -5,7 +5,7 @@ error[no-explicit-any]: `any` type is not allowed
| ^^^
= hint: Use a specific type other than `any`
- docs: https://lint.deno.land/#no-explicit-any
+ docs: https://lint.deno.land/rules/no-explicit-any
Found 1 problem
diff --git a/tests/testdata/lint/expected_quiet.out b/tests/testdata/lint/expected_quiet.out
index e46a94a2d..91c1a29cf 100644
--- a/tests/testdata/lint/expected_quiet.out
+++ b/tests/testdata/lint/expected_quiet.out
@@ -5,7 +5,7 @@ error[ban-untagged-ignore]: Ignore directive requires lint rule name(s)
| ^^^^^^^^^^^^^^^^^^^
= hint: Add one or more lint rule names. E.g. // deno-lint-ignore adjacent-overload-signatures
- docs: https://lint.deno.land/#ban-untagged-ignore
+ docs: https://lint.deno.land/rules/ban-untagged-ignore
error[no-empty]: Empty block statement
@@ -15,6 +15,6 @@ error[no-empty]: Empty block statement
| ^^
= hint: Add code or comment to the empty block
- docs: https://lint.deno.land/#no-empty
+ docs: https://lint.deno.land/rules/no-empty
diff --git a/tests/testdata/lint/with_config.out b/tests/testdata/lint/with_config.out
index cffd6b9c7..f527bb712 100644
--- a/tests/testdata/lint/with_config.out
+++ b/tests/testdata/lint/with_config.out
@@ -5,7 +5,7 @@ error[ban-untagged-todo]: TODO should be tagged with (@username) or (#issue)
| ^^^^^^^^^^^^
= hint: Add a user tag or issue reference to the TODO comment, e.g. TODO(@djones), TODO(djones), TODO(#123)
- docs: https://lint.deno.land/#ban-untagged-todo
+ docs: https://lint.deno.land/rules/ban-untagged-todo
error[no-unused-vars]: `add` is never used
@@ -15,7 +15,7 @@ error[no-unused-vars]: `add` is never used
| ^^^
= hint: If this is intentional, prefix it with an underscore like `_add`
- docs: https://lint.deno.land/#no-unused-vars
+ docs: https://lint.deno.land/rules/no-unused-vars
Found 2 problems
diff --git a/tests/testdata/lint/with_config_and_flags.out b/tests/testdata/lint/with_config_and_flags.out
index f3ad3cafb..78e21ef8d 100644
--- a/tests/testdata/lint/with_config_and_flags.out
+++ b/tests/testdata/lint/with_config_and_flags.out
@@ -5,7 +5,7 @@ error[ban-untagged-todo]: TODO should be tagged with (@username) or (#issue)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= hint: Add a user tag or issue reference to the TODO comment, e.g. TODO(@djones), TODO(djones), TODO(#123)
- docs: https://lint.deno.land/#ban-untagged-todo
+ docs: https://lint.deno.land/rules/ban-untagged-todo
error[no-unused-vars]: `subtract` is never used
@@ -15,7 +15,7 @@ error[no-unused-vars]: `subtract` is never used
| ^^^^^^^^
= hint: If this is intentional, prefix it with an underscore like `_subtract`
- docs: https://lint.deno.land/#no-unused-vars
+ docs: https://lint.deno.land/rules/no-unused-vars
Found 2 problems
diff --git a/tests/testdata/lint/with_config_without_tags.out b/tests/testdata/lint/with_config_without_tags.out
index cffd6b9c7..f527bb712 100644
--- a/tests/testdata/lint/with_config_without_tags.out
+++ b/tests/testdata/lint/with_config_without_tags.out
@@ -5,7 +5,7 @@ error[ban-untagged-todo]: TODO should be tagged with (@username) or (#issue)
| ^^^^^^^^^^^^
= hint: Add a user tag or issue reference to the TODO comment, e.g. TODO(@djones), TODO(djones), TODO(#123)
- docs: https://lint.deno.land/#ban-untagged-todo
+ docs: https://lint.deno.land/rules/ban-untagged-todo
error[no-unused-vars]: `add` is never used
@@ -15,7 +15,7 @@ error[no-unused-vars]: `add` is never used
| ^^^
= hint: If this is intentional, prefix it with an underscore like `_add`
- docs: https://lint.deno.land/#no-unused-vars
+ docs: https://lint.deno.land/rules/no-unused-vars
Found 2 problems