From ffbcad3800ef086bad791c1c640b62fd72d60172 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 21 Mar 2024 14:18:59 -0700 Subject: 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. --- tests/integration/lsp_tests.rs | 98 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) (limited to 'tests/integration') 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 @@ -10197,6 +10197,104 @@ console.log(snake_case); client.shutdown(); } +#[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(); -- cgit v1.2.3