diff options
Diffstat (limited to 'tests/testdata/lint')
48 files changed, 392 insertions, 0 deletions
diff --git a/tests/testdata/lint/Deno.compact.format.jsonc b/tests/testdata/lint/Deno.compact.format.jsonc new file mode 100644 index 000000000..f3487501a --- /dev/null +++ b/tests/testdata/lint/Deno.compact.format.jsonc @@ -0,0 +1,11 @@ +{ + "lint": { + "include": ["with_config/"], + "exclude": ["with_config/b.ts"], + "rules": { + "tags": ["recommended"], + "include": ["ban-untagged-todo"] + }, + "report": "compact" + } +} diff --git a/tests/testdata/lint/Deno.jsonc b/tests/testdata/lint/Deno.jsonc new file mode 100644 index 000000000..e9c03cca4 --- /dev/null +++ b/tests/testdata/lint/Deno.jsonc @@ -0,0 +1,10 @@ +{ + "lint": { + "include": ["with_config/"], + "exclude": ["with_config/b.ts"], + "rules": { + "tags": ["recommended"], + "include": ["ban-untagged-todo"] + } + } +} diff --git a/tests/testdata/lint/Deno.malformed.jsonc b/tests/testdata/lint/Deno.malformed.jsonc new file mode 100644 index 000000000..fa71cd851 --- /dev/null +++ b/tests/testdata/lint/Deno.malformed.jsonc @@ -0,0 +1,11 @@ +{ + "lint": { + "include": ["with_config/"], + "exclude": ["with_config/b.ts"], + "dont_know_this_field": {}, + "rules": { + "tags": ["recommended"], + "include": ["ban-untagged-todo"] + } + } +} diff --git a/tests/testdata/lint/Deno.malformed2.jsonc b/tests/testdata/lint/Deno.malformed2.jsonc new file mode 100644 index 000000000..fa71cd851 --- /dev/null +++ b/tests/testdata/lint/Deno.malformed2.jsonc @@ -0,0 +1,11 @@ +{ + "lint": { + "include": ["with_config/"], + "exclude": ["with_config/b.ts"], + "dont_know_this_field": {}, + "rules": { + "tags": ["recommended"], + "include": ["ban-untagged-todo"] + } + } +} diff --git a/tests/testdata/lint/Deno.no_tags.jsonc b/tests/testdata/lint/Deno.no_tags.jsonc new file mode 100644 index 000000000..b63600a90 --- /dev/null +++ b/tests/testdata/lint/Deno.no_tags.jsonc @@ -0,0 +1,15 @@ +{ + "lint": { + "include": [ + "with_config/" + ], + "exclude": [ + "with_config/b.ts" + ], + "rules": { + "include": [ + "ban-untagged-todo" + ] + } + } +} diff --git a/tests/testdata/lint/deno.glob.json b/tests/testdata/lint/deno.glob.json new file mode 100644 index 000000000..f6781b0d8 --- /dev/null +++ b/tests/testdata/lint/deno.glob.json @@ -0,0 +1,11 @@ +{ + "lint": { + "include": [ + "glob/data/test1.?s", + "glob/nested/foo/*.ts", + "glob/nested/fizz/*.ts", + "glob/pages/[id].ts" + ], + "exclude": ["glob/nested/**/*bazz.ts"] + } +} diff --git a/tests/testdata/lint/expected.out b/tests/testdata/lint/expected.out new file mode 100644 index 000000000..eb8a2651a --- /dev/null +++ b/tests/testdata/lint/expected.out @@ -0,0 +1,3 @@ +[WILDCARD] +Found 3 problems +Checked 3 files diff --git a/tests/testdata/lint/expected_compact.out b/tests/testdata/lint/expected_compact.out new file mode 100644 index 000000000..d1b2b922b --- /dev/null +++ b/tests/testdata/lint/expected_compact.out @@ -0,0 +1,4 @@ +[WILDCARD]file1.js: line 1, col 1 - Ignore directive requires lint rule name(s) (ban-untagged-ignore) +[WILDCARD]file1.js: line 2, col 15 - Empty block statement (no-empty) +Found 2 problems +Checked 1 file diff --git a/tests/testdata/lint/expected_from_stdin.out b/tests/testdata/lint/expected_from_stdin.out new file mode 100644 index 000000000..59f32166f --- /dev/null +++ b/tests/testdata/lint/expected_from_stdin.out @@ -0,0 +1,12 @@ +error[no-explicit-any]: `any` type is not allowed + --> [WILDCARD]$deno$stdin.ts:1:9 + | +1 | let _a: any; + | ^^^ + = hint: Use a specific type other than `any` + + docs: https://lint.deno.land/#no-explicit-any + + +Found 1 problem +Checked 1 file diff --git a/tests/testdata/lint/expected_from_stdin_json.out b/tests/testdata/lint/expected_from_stdin_json.out new file mode 100644 index 000000000..9e1188bcd --- /dev/null +++ b/tests/testdata/lint/expected_from_stdin_json.out @@ -0,0 +1,23 @@ +{ + "diagnostics": [ + { + "filename": "[WILDCARD]$deno$stdin.ts", + "range": { + "start": { + "line": 1, + "col": 8, + "bytePos": 8 + }, + "end": { + "line": 1, + "col": 11, + "bytePos": 11 + } + }, + "message": "`any` type is not allowed", + "code": "no-explicit-any", + "hint": [WILDCARD] + } + ], + "errors": [] +} diff --git a/tests/testdata/lint/expected_glob.out b/tests/testdata/lint/expected_glob.out new file mode 100644 index 000000000..eb8a2651a --- /dev/null +++ b/tests/testdata/lint/expected_glob.out @@ -0,0 +1,3 @@ +[WILDCARD] +Found 3 problems +Checked 3 files diff --git a/tests/testdata/lint/expected_ignore.out b/tests/testdata/lint/expected_ignore.out new file mode 100644 index 000000000..b5f78ee04 --- /dev/null +++ b/tests/testdata/lint/expected_ignore.out @@ -0,0 +1,3 @@ +[WILDCARD] +Found 1 problem +Checked 2 files diff --git a/tests/testdata/lint/expected_json.out b/tests/testdata/lint/expected_json.out new file mode 100644 index 000000000..95c3d30ba --- /dev/null +++ b/tests/testdata/lint/expected_json.out @@ -0,0 +1,64 @@ +{ + "diagnostics": [ + { + "filename": "[WILDCARD]file1.js", + "range": { + "start": { + "line": 1, + "col": 0, + "bytePos": 0 + }, + "end": { + "line": 1, + "col": 19, + "bytePos": 19 + } + }, + "message": "Ignore directive requires lint rule name(s)", + "code": "ban-untagged-ignore", + "hint": [WILDCARD] + }, + { + "filename": "[WILDCARD]file1.js", + "range": { + "start": { + "line": 2, + "col": 14, + "bytePos": 34 + }, + "end": { + "line": 2, + "col": 16, + "bytePos": 36 + } + }, + "message": "Empty block statement", + "code": "no-empty", + "hint": [WILDCARD] + }, + { + "filename": "[WILDCARD]file2.ts", + "range": { + "start": { + "line": 3, + "col": 13, + "bytePos": 57 + }, + "end": { + "line": 3, + "col": 15, + "bytePos": 59 + } + }, + "message": "Empty block statement", + "code": "no-empty", + "hint": [WILDCARD] + } + ], + "errors": [ + { + "file_path": "[WILDCARD]malformed.js", + "message": "Expected '{', got 'B' at [WILDCARD]malformed.js:4:16\n\n export class A B C\n ~" + } + ] +} diff --git a/tests/testdata/lint/expected_quiet.out b/tests/testdata/lint/expected_quiet.out new file mode 100644 index 000000000..e46a94a2d --- /dev/null +++ b/tests/testdata/lint/expected_quiet.out @@ -0,0 +1,20 @@ +error[ban-untagged-ignore]: Ignore directive requires lint rule name(s) + --> [WILDCARD]file1.js:1:1 + | +1 | // deno-lint-ignore + | ^^^^^^^^^^^^^^^^^^^ + = hint: Add one or more lint rule names. E.g. // deno-lint-ignore adjacent-overload-signatures + + docs: https://lint.deno.land/#ban-untagged-ignore + + +error[no-empty]: Empty block statement + --> [WILDCARD]file1.js:2:15 + | +2 | while (false) {} + | ^^ + = hint: Add code or comment to the empty block + + docs: https://lint.deno.land/#no-empty + + diff --git a/tests/testdata/lint/expected_rules.out b/tests/testdata/lint/expected_rules.out new file mode 100644 index 000000000..4afab7b9b --- /dev/null +++ b/tests/testdata/lint/expected_rules.out @@ -0,0 +1,2 @@ +Available rules: +[WILDCARD] diff --git a/tests/testdata/lint/expected_verbose.out b/tests/testdata/lint/expected_verbose.out new file mode 100644 index 000000000..eb8a2651a --- /dev/null +++ b/tests/testdata/lint/expected_verbose.out @@ -0,0 +1,3 @@ +[WILDCARD] +Found 3 problems +Checked 3 files diff --git a/tests/testdata/lint/glob/data/tes.ts b/tests/testdata/lint/glob/data/tes.ts new file mode 100644 index 000000000..26f07fba5 --- /dev/null +++ b/tests/testdata/lint/glob/data/tes.ts @@ -0,0 +1,3 @@ +function foo() { + +}
\ No newline at end of file diff --git a/tests/testdata/lint/glob/data/test1.js b/tests/testdata/lint/glob/data/test1.js new file mode 100644 index 000000000..26f07fba5 --- /dev/null +++ b/tests/testdata/lint/glob/data/test1.js @@ -0,0 +1,3 @@ +function foo() { + +}
\ No newline at end of file diff --git a/tests/testdata/lint/glob/data/test1.ts b/tests/testdata/lint/glob/data/test1.ts new file mode 100644 index 000000000..26f07fba5 --- /dev/null +++ b/tests/testdata/lint/glob/data/test1.ts @@ -0,0 +1,3 @@ +function foo() { + +}
\ No newline at end of file diff --git a/tests/testdata/lint/glob/data/test12.ts b/tests/testdata/lint/glob/data/test12.ts new file mode 100644 index 000000000..26f07fba5 --- /dev/null +++ b/tests/testdata/lint/glob/data/test12.ts @@ -0,0 +1,3 @@ +function foo() { + +}
\ No newline at end of file diff --git a/tests/testdata/lint/glob/nested/fizz/bar.ts b/tests/testdata/lint/glob/nested/fizz/bar.ts new file mode 100644 index 000000000..26f07fba5 --- /dev/null +++ b/tests/testdata/lint/glob/nested/fizz/bar.ts @@ -0,0 +1,3 @@ +function foo() { + +}
\ No newline at end of file diff --git a/tests/testdata/lint/glob/nested/fizz/bazz.ts b/tests/testdata/lint/glob/nested/fizz/bazz.ts new file mode 100644 index 000000000..26f07fba5 --- /dev/null +++ b/tests/testdata/lint/glob/nested/fizz/bazz.ts @@ -0,0 +1,3 @@ +function foo() { + +}
\ No newline at end of file diff --git a/tests/testdata/lint/glob/nested/fizz/fizz.ts b/tests/testdata/lint/glob/nested/fizz/fizz.ts new file mode 100644 index 000000000..6940729e9 --- /dev/null +++ b/tests/testdata/lint/glob/nested/fizz/fizz.ts @@ -0,0 +1,2 @@ +function foo() { +} diff --git a/tests/testdata/lint/glob/nested/fizz/foo.ts b/tests/testdata/lint/glob/nested/fizz/foo.ts new file mode 100644 index 000000000..26f07fba5 --- /dev/null +++ b/tests/testdata/lint/glob/nested/fizz/foo.ts @@ -0,0 +1,3 @@ +function foo() { + +}
\ No newline at end of file diff --git a/tests/testdata/lint/glob/nested/foo/bar.ts b/tests/testdata/lint/glob/nested/foo/bar.ts new file mode 100644 index 000000000..26f07fba5 --- /dev/null +++ b/tests/testdata/lint/glob/nested/foo/bar.ts @@ -0,0 +1,3 @@ +function foo() { + +}
\ No newline at end of file diff --git a/tests/testdata/lint/glob/nested/foo/bazz.ts b/tests/testdata/lint/glob/nested/foo/bazz.ts new file mode 100644 index 000000000..26f07fba5 --- /dev/null +++ b/tests/testdata/lint/glob/nested/foo/bazz.ts @@ -0,0 +1,3 @@ +function foo() { + +}
\ No newline at end of file diff --git a/tests/testdata/lint/glob/nested/foo/fizz.ts b/tests/testdata/lint/glob/nested/foo/fizz.ts new file mode 100644 index 000000000..26f07fba5 --- /dev/null +++ b/tests/testdata/lint/glob/nested/foo/fizz.ts @@ -0,0 +1,3 @@ +function foo() { + +}
\ No newline at end of file diff --git a/tests/testdata/lint/glob/nested/foo/foo.ts b/tests/testdata/lint/glob/nested/foo/foo.ts new file mode 100644 index 000000000..26f07fba5 --- /dev/null +++ b/tests/testdata/lint/glob/nested/foo/foo.ts @@ -0,0 +1,3 @@ +function foo() { + +}
\ No newline at end of file diff --git a/tests/testdata/lint/glob/pages/[id].ts b/tests/testdata/lint/glob/pages/[id].ts new file mode 100644 index 000000000..26f07fba5 --- /dev/null +++ b/tests/testdata/lint/glob/pages/[id].ts @@ -0,0 +1,3 @@ +function foo() { + +}
\ No newline at end of file diff --git a/tests/testdata/lint/watch/badly_linted.js b/tests/testdata/lint/watch/badly_linted.js new file mode 100644 index 000000000..8d1c1fe79 --- /dev/null +++ b/tests/testdata/lint/watch/badly_linted.js @@ -0,0 +1 @@ +let a = 5; diff --git a/tests/testdata/lint/watch/badly_linted.js.out b/tests/testdata/lint/watch/badly_linted.js.out new file mode 100644 index 000000000..07ae031c3 --- /dev/null +++ b/tests/testdata/lint/watch/badly_linted.js.out @@ -0,0 +1,2 @@ +error[no-unused-vars]: `a` is never used +error[prefer-const]: `a` is never reassigned diff --git a/tests/testdata/lint/watch/badly_linted_fixed1.js b/tests/testdata/lint/watch/badly_linted_fixed1.js new file mode 100644 index 000000000..bfccee47d --- /dev/null +++ b/tests/testdata/lint/watch/badly_linted_fixed1.js @@ -0,0 +1 @@ +let _a = 5; diff --git a/tests/testdata/lint/watch/badly_linted_fixed1.js.out b/tests/testdata/lint/watch/badly_linted_fixed1.js.out new file mode 100644 index 000000000..67e3c9dd8 --- /dev/null +++ b/tests/testdata/lint/watch/badly_linted_fixed1.js.out @@ -0,0 +1 @@ +error[prefer-const]: `_a` is never reassigned diff --git a/tests/testdata/lint/watch/badly_linted_fixed2.js b/tests/testdata/lint/watch/badly_linted_fixed2.js new file mode 100644 index 000000000..94fe8701b --- /dev/null +++ b/tests/testdata/lint/watch/badly_linted_fixed2.js @@ -0,0 +1 @@ +const _a = 5; diff --git a/tests/testdata/lint/watch/badly_linted_fixed2.js.out b/tests/testdata/lint/watch/badly_linted_fixed2.js.out new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/testdata/lint/watch/badly_linted_fixed2.js.out diff --git a/tests/testdata/lint/with_config.out b/tests/testdata/lint/with_config.out new file mode 100644 index 000000000..cffd6b9c7 --- /dev/null +++ b/tests/testdata/lint/with_config.out @@ -0,0 +1,22 @@ +error[ban-untagged-todo]: TODO should be tagged with (@username) or (#issue) + --> [WILDCARD]a.ts:1:1 + | +1 | // TODO: foo + | ^^^^^^^^^^^^ + = 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 + + +error[no-unused-vars]: `add` is never used + --> [WILDCARD]a.ts:2:10 + | +2 | function add(a: number, b: number): number { + | ^^^ + = hint: If this is intentional, prefix it with an underscore like `_add` + + docs: https://lint.deno.land/#no-unused-vars + + +Found 2 problems +Checked 1 file diff --git a/tests/testdata/lint/with_config/a.ts b/tests/testdata/lint/with_config/a.ts new file mode 100644 index 000000000..c378218a3 --- /dev/null +++ b/tests/testdata/lint/with_config/a.ts @@ -0,0 +1,4 @@ +// TODO: foo +function add(a: number, b: number): number { + return a + b; +} diff --git a/tests/testdata/lint/with_config/b.ts b/tests/testdata/lint/with_config/b.ts new file mode 100644 index 000000000..d5647067e --- /dev/null +++ b/tests/testdata/lint/with_config/b.ts @@ -0,0 +1,4 @@ +// TODO: this file should be ignored +function subtract(a: number, b: number): number { + return a - b; +} diff --git a/tests/testdata/lint/with_config_and_flags.out b/tests/testdata/lint/with_config_and_flags.out new file mode 100644 index 000000000..f3ad3cafb --- /dev/null +++ b/tests/testdata/lint/with_config_and_flags.out @@ -0,0 +1,22 @@ +error[ban-untagged-todo]: TODO should be tagged with (@username) or (#issue) + --> [WILDCARD]b.ts:1:1 + | +1 | // TODO: this file should be ignored + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = 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 + + +error[no-unused-vars]: `subtract` is never used + --> [WILDCARD]b.ts:2:10 + | +2 | function subtract(a: number, b: number): number { + | ^^^^^^^^ + = hint: If this is intentional, prefix it with an underscore like `_subtract` + + docs: https://lint.deno.land/#no-unused-vars + + +Found 2 problems +Checked 1 file diff --git a/tests/testdata/lint/with_config_without_tags.out b/tests/testdata/lint/with_config_without_tags.out new file mode 100644 index 000000000..cffd6b9c7 --- /dev/null +++ b/tests/testdata/lint/with_config_without_tags.out @@ -0,0 +1,22 @@ +error[ban-untagged-todo]: TODO should be tagged with (@username) or (#issue) + --> [WILDCARD]a.ts:1:1 + | +1 | // TODO: foo + | ^^^^^^^^^^^^ + = 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 + + +error[no-unused-vars]: `add` is never used + --> [WILDCARD]a.ts:2:10 + | +2 | function add(a: number, b: number): number { + | ^^^ + = hint: If this is intentional, prefix it with an underscore like `_add` + + docs: https://lint.deno.land/#no-unused-vars + + +Found 2 problems +Checked 1 file diff --git a/tests/testdata/lint/with_malformed_config.out b/tests/testdata/lint/with_malformed_config.out new file mode 100644 index 000000000..1c0f0fff6 --- /dev/null +++ b/tests/testdata/lint/with_malformed_config.out @@ -0,0 +1,4 @@ +error: Failed to parse "lint" configuration + +Caused by: + unknown field `dont_know_this_field`, expected one of `rules`, `include`, `exclude`, `files`, `report` diff --git a/tests/testdata/lint/with_malformed_config2.out b/tests/testdata/lint/with_malformed_config2.out new file mode 100644 index 000000000..1c0f0fff6 --- /dev/null +++ b/tests/testdata/lint/with_malformed_config2.out @@ -0,0 +1,4 @@ +error: Failed to parse "lint" configuration + +Caused by: + unknown field `dont_know_this_field`, expected one of `rules`, `include`, `exclude`, `files`, `report` diff --git a/tests/testdata/lint/with_report_config_compact.out b/tests/testdata/lint/with_report_config_compact.out new file mode 100644 index 000000000..fe1241264 --- /dev/null +++ b/tests/testdata/lint/with_report_config_compact.out @@ -0,0 +1,4 @@ +[WILDCARD]a.ts: line 1, col 1 - TODO should be tagged with (@username) or (#issue) (ban-untagged-todo) +[WILDCARD]a.ts: line 2, col 10 - `add` is never used (no-unused-vars) +Found 2 problems +Checked 1 file diff --git a/tests/testdata/lint/with_report_config_override.out b/tests/testdata/lint/with_report_config_override.out new file mode 100644 index 000000000..7ca748158 --- /dev/null +++ b/tests/testdata/lint/with_report_config_override.out @@ -0,0 +1,41 @@ +{ + "diagnostics": [ + { + "filename": "[WILDCARD]a.ts", + "range": { + "start": { + "line": 1, + "col": 0, + "bytePos": 0 + }, + "end": { + "line": 1, + "col": 12, + "bytePos": 12 + } + }, + "message": "TODO should be tagged with (@username) or (#issue)", + "code": "ban-untagged-todo", + "hint": "Add a user tag or issue reference to the TODO comment, e.g. TODO(@djones), TODO(djones), TODO(#123)" + }, + { + "filename": "[WILDCARD]a.ts", + "range": { + "start": { + "line": 2, + "col": 9, + "bytePos": 22 + }, + "end": { + "line": 2, + "col": 12, + "bytePos": 25 + } + }, + "message": "`add` is never used", + "code": "no-unused-vars", + "hint": "If this is intentional, prefix it with an underscore like `_add`" + } + ], + "errors": [] +} diff --git a/tests/testdata/lint/without_config/file1.js b/tests/testdata/lint/without_config/file1.js new file mode 100644 index 000000000..737f26818 --- /dev/null +++ b/tests/testdata/lint/without_config/file1.js @@ -0,0 +1,2 @@ +// deno-lint-ignore +while (false) {} diff --git a/tests/testdata/lint/without_config/file2.ts b/tests/testdata/lint/without_config/file2.ts new file mode 100644 index 000000000..73c612c35 --- /dev/null +++ b/tests/testdata/lint/without_config/file2.ts @@ -0,0 +1,6 @@ +try { + await Deno.open("./some/file.txt"); +} catch (_e) {} + +// deno-lint-ignore no-explicit-any +function _foo(): any {} diff --git a/tests/testdata/lint/without_config/ignored_file.ts b/tests/testdata/lint/without_config/ignored_file.ts new file mode 100644 index 000000000..97befafa3 --- /dev/null +++ b/tests/testdata/lint/without_config/ignored_file.ts @@ -0,0 +1,3 @@ +// deno-lint-ignore-file + +function foo(): any {} diff --git a/tests/testdata/lint/without_config/malformed.js b/tests/testdata/lint/without_config/malformed.js new file mode 100644 index 000000000..9b64da898 --- /dev/null +++ b/tests/testdata/lint/without_config/malformed.js @@ -0,0 +1,4 @@ +// deno-fmt-ignore-file + +// intentionally malformed file +export class A B C
\ No newline at end of file |