From bf898e59f1ffa86452105e649a654d1b3af92ebb Mon Sep 17 00:00:00 2001 From: camc314 <18101008+camc314@users.noreply.github.com> Date: Wed, 29 Oct 2025 09:20:31 +0000 Subject: [PATCH] test(linter): increase stability of tsgolint test cases (#15063) current test cases are unnecessarily complex. this results in unstable tests due to non-determinestic multi threaded behaviour when running tsgo. This PR improves the stability of these test cases by simplifying the test cases, reducing the variance when running type aware linting. --- .../fixtures/tsgolint/await-thenable.ts | 1 + .../fixtures/tsgolint/await-thenable/index.ts | 12 - .../fixtures/tsgolint/no-array-delete.ts | 2 + .../tsgolint/no-array-delete/index.ts | 4 - .../fixtures/tsgolint/no-base-to-string.ts | 1 + .../tsgolint/no-base-to-string/index.ts | 9 - .../tsgolint/no-confusing-void-expression.ts | 2 + .../no-confusing-void-expression/index.ts | 12 - .../no-duplicate-type-constituents.ts | 1 + .../no-duplicate-type-constituents/index.ts | 14 - .../fixtures/tsgolint/no-floating-promises.ts | 2 + .../tsgolint/no-floating-promises/index.ts | 14 - .../no-floating-promises/src/.oxlintrc.json | 16 - .../no-floating-promises/src/index.ts | 14 - .../no-floating-promises/src/overrides.ts | 4 - .../fixtures/tsgolint/no-for-in-array.ts | 4 + .../tsgolint/no-for-in-array/index.ts | 11 - .../fixtures/tsgolint/no-implied-eval.ts | 1 + .../tsgolint/no-implied-eval/index.ts | 13 - .../tsgolint/no-meaningless-void-operator.ts | 4 + .../no-meaningless-void-operator/index.ts | 13 - .../fixtures/tsgolint/no-misused-spread.ts | 2 + .../tsgolint/no-misused-spread/index.ts | 11 - .../fixtures/tsgolint/no-mixed-enums.ts | 4 + .../fixtures/tsgolint/no-mixed-enums/index.ts | 13 - .../no-redundant-type-constituents.ts | 1 + .../no-redundant-type-constituents/index.ts | 10 - .../no-unnecessary-boolean-literal-compare.ts | 3 + .../index.ts | 11 - .../no-unnecessary-template-expression.ts | 1 + .../index.ts | 10 - .../tsgolint/no-unnecessary-type-arguments.ts | 4 + .../no-unnecessary-type-arguments/index.ts | 12 - .../tsgolint/no-unnecessary-type-assertion.ts | 2 + .../no-unnecessary-type-assertion/index.ts | 12 - .../fixtures/tsgolint/no-unsafe-argument.ts | 3 + .../tsgolint/no-unsafe-argument/index.ts | 12 - .../fixtures/tsgolint/no-unsafe-assignment.ts | 2 + .../tsgolint/no-unsafe-assignment/index.ts | 12 - .../fixtures/tsgolint/no-unsafe-call.ts | 2 + .../fixtures/tsgolint/no-unsafe-call/index.ts | 12 - .../index.ts => no-unsafe-enum-comparison.ts} | 5 - .../tsgolint/no-unsafe-member-access.ts | 2 + .../tsgolint/no-unsafe-member-access/index.ts | 11 - .../fixtures/tsgolint/no-unsafe-return.ts | 4 + .../tsgolint/no-unsafe-return/index.ts | 13 - .../tsgolint/no-unsafe-type-assertion.ts | 2 + .../no-unsafe-type-assertion/index.ts | 12 - .../tsgolint/no-unsafe-unary-minus.ts | 2 + .../tsgolint/no-unsafe-unary-minus/index.ts | 13 - .../non-nullable-type-assertion-style.ts | 2 + .../index.ts | 9 - .../fixtures/tsgolint/only-throw-error.ts | 1 + .../tsgolint/only-throw-error/index.ts | 11 - .../tsgolint/prefer-promise-reject-errors.ts | 1 + .../prefer-promise-reject-errors/index.ts | 11 - .../tsgolint/prefer-reduce-type-parameter.ts | 2 + .../prefer-reduce-type-parameter/index.ts | 12 - .../tsgolint/prefer-return-this-type.ts | 7 + .../tsgolint/prefer-return-this-type/index.ts | 14 - .../tsgolint/promise-function-async.ts | 4 + .../tsgolint/promise-function-async/index.ts | 13 - .../tsgolint/related-getter-setter-pairs.ts | 9 + .../related-getter-setter-pairs/index.ts | 14 - .../tsgolint/require-array-sort-compare.ts | 2 + .../require-array-sort-compare/index.ts | 9 - .../oxlint/fixtures/tsgolint/require-await.ts | 4 + .../fixtures/tsgolint/require-await/index.ts | 11 - .../tsgolint/restrict-plus-operands.ts | 1 + .../tsgolint/restrict-plus-operands/index.ts | 2 - .../tsgolint/restrict-template-expressions.ts | 2 + .../restrict-template-expressions/index.ts | 18 - apps/oxlint/fixtures/tsgolint/return-await.ts | 5 + .../fixtures/tsgolint/return-await/index.ts | 32 - .../tsgolint/strict-boolean-expressions.ts | 3 + .../strict-boolean-expressions/index.ts | 67 - ...ndex.ts => switch-exhaustiveness-check.ts} | 4 - .../fixtures/tsgolint/unbound-method.ts | 9 + .../fixtures/tsgolint/unbound-method/index.ts | 31 - .../use-unknown-in-catch-callback-variable.ts | 5 + .../index.ts | 35 - apps/oxlint/src/lint.rs | 5 +- ...sgolint_--type-aware --silent@oxlint.snap} | 6 +- ...type-aware -c config-test.json@oxlint.snap | 112 +- ...ixtures__tsgolint_--type-aware@oxlint.snap | 1683 ++--------------- crates/oxc_linter/src/tsgolint.rs | 5 - 86 files changed, 303 insertions(+), 2215 deletions(-) create mode 100644 apps/oxlint/fixtures/tsgolint/await-thenable.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/await-thenable/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/no-array-delete.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-array-delete/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/no-base-to-string.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-base-to-string/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/no-confusing-void-expression.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-confusing-void-expression/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/no-duplicate-type-constituents.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-duplicate-type-constituents/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/no-floating-promises.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-floating-promises/index.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-floating-promises/src/.oxlintrc.json delete mode 100644 apps/oxlint/fixtures/tsgolint/no-floating-promises/src/index.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-floating-promises/src/overrides.ts create mode 100644 apps/oxlint/fixtures/tsgolint/no-for-in-array.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-for-in-array/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/no-implied-eval.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-implied-eval/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/no-meaningless-void-operator.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-meaningless-void-operator/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/no-misused-spread.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-misused-spread/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/no-mixed-enums.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-mixed-enums/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/no-redundant-type-constituents.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-redundant-type-constituents/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/no-unnecessary-boolean-literal-compare.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-unnecessary-boolean-literal-compare/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/no-unnecessary-template-expression.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-unnecessary-template-expression/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/no-unnecessary-type-arguments.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-unnecessary-type-arguments/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/no-unnecessary-type-assertion.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-unnecessary-type-assertion/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/no-unsafe-argument.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-unsafe-argument/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/no-unsafe-assignment.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-unsafe-assignment/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/no-unsafe-call.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-unsafe-call/index.ts rename apps/oxlint/fixtures/tsgolint/{no-unsafe-enum-comparison/index.ts => no-unsafe-enum-comparison.ts} (60%) create mode 100644 apps/oxlint/fixtures/tsgolint/no-unsafe-member-access.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-unsafe-member-access/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/no-unsafe-return.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-unsafe-return/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/no-unsafe-type-assertion.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-unsafe-type-assertion/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/no-unsafe-unary-minus.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/no-unsafe-unary-minus/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/non-nullable-type-assertion-style.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/non-nullable-type-assertion-style/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/only-throw-error.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/only-throw-error/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/prefer-promise-reject-errors.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/prefer-promise-reject-errors/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/prefer-reduce-type-parameter.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/prefer-reduce-type-parameter/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/prefer-return-this-type.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/prefer-return-this-type/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/promise-function-async.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/promise-function-async/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/related-getter-setter-pairs.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/related-getter-setter-pairs/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/require-array-sort-compare.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/require-array-sort-compare/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/require-await.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/require-await/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/restrict-plus-operands.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/restrict-plus-operands/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/restrict-template-expressions.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/restrict-template-expressions/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/return-await.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/return-await/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/strict-boolean-expressions.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/strict-boolean-expressions/index.ts rename apps/oxlint/fixtures/tsgolint/{switch-exhaustiveness-check/index.ts => switch-exhaustiveness-check.ts} (69%) create mode 100644 apps/oxlint/fixtures/tsgolint/unbound-method.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/unbound-method/index.ts create mode 100644 apps/oxlint/fixtures/tsgolint/use-unknown-in-catch-callback-variable.ts delete mode 100644 apps/oxlint/fixtures/tsgolint/use-unknown-in-catch-callback-variable/index.ts rename apps/oxlint/src/snapshots/{fixtures__tsgolint_--type-aware --silent no-floating-promises@oxlint.snap => fixtures__tsgolint_--type-aware --silent@oxlint.snap} (52%) diff --git a/apps/oxlint/fixtures/tsgolint/await-thenable.ts b/apps/oxlint/fixtures/tsgolint/await-thenable.ts new file mode 100644 index 0000000000000..c9aaf0a5bcdaf --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/await-thenable.ts @@ -0,0 +1 @@ +await 12; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/await-thenable/index.ts b/apps/oxlint/fixtures/tsgolint/await-thenable/index.ts deleted file mode 100644 index 032a8c1ee3080..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/await-thenable/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -// Examples of incorrect code for await-thenable rule - -await 12; -await (() => {}); - -// non-Promise values -await Math.random; -await { then() {} }; - -// this is not a Promise - it's a function that returns a Promise -declare const getPromise: () => Promise; -await getPromise; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-array-delete.ts b/apps/oxlint/fixtures/tsgolint/no-array-delete.ts new file mode 100644 index 0000000000000..a403fbe98f340 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-array-delete.ts @@ -0,0 +1,2 @@ +declare const arr: number[]; +delete arr[0]; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-array-delete/index.ts b/apps/oxlint/fixtures/tsgolint/no-array-delete/index.ts deleted file mode 100644 index 8b761a73ff952..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-array-delete/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -// Examples of incorrect code for no-array-delete rule - -declare const arr: number[]; -delete arr[0]; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-base-to-string.ts b/apps/oxlint/fixtures/tsgolint/no-base-to-string.ts new file mode 100644 index 0000000000000..e2d6d17e5c384 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-base-to-string.ts @@ -0,0 +1 @@ +({}).toString(); \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-base-to-string/index.ts b/apps/oxlint/fixtures/tsgolint/no-base-to-string/index.ts deleted file mode 100644 index 7eb8b1b32733f..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-base-to-string/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -// Examples of incorrect code for no-base-to-string rule - -// These will evaluate to '[object Object]' -({}).toString(); -({foo: 'bar'}).toString(); -({foo: 'bar'}).toLocaleString(); - -// This will evaluate to 'Symbol()' -Symbol('foo').toString(); \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-confusing-void-expression.ts b/apps/oxlint/fixtures/tsgolint/no-confusing-void-expression.ts new file mode 100644 index 0000000000000..532bc52c586e3 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-confusing-void-expression.ts @@ -0,0 +1,2 @@ +declare function bar(): void; +const foo = () => void bar(); \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-confusing-void-expression/index.ts b/apps/oxlint/fixtures/tsgolint/no-confusing-void-expression/index.ts deleted file mode 100644 index 784c28cfb4715..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-confusing-void-expression/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -// Examples of incorrect code for no-confusing-void-expression rule - -// arrow function returning void expression -const foo = () => void bar(); - -// conditional expression -const result = condition ? void foo() : bar(); - -// void in conditional -if (void foo()) { - // ... -} \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-duplicate-type-constituents.ts b/apps/oxlint/fixtures/tsgolint/no-duplicate-type-constituents.ts new file mode 100644 index 0000000000000..13c05bb83b979 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-duplicate-type-constituents.ts @@ -0,0 +1 @@ +type T1 = 'A' | 'A'; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-duplicate-type-constituents/index.ts b/apps/oxlint/fixtures/tsgolint/no-duplicate-type-constituents/index.ts deleted file mode 100644 index c06f80ed62e2f..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-duplicate-type-constituents/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -// Examples of incorrect code for no-duplicate-type-constituents rule - -type T1 = 'A' | 'A'; - -type T2 = A | A | B; - -type T3 = { a: string } & { a: string }; - -type T4 = [A, A]; - -type T5 = - | 'foo' - | 'bar' - | 'foo'; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-floating-promises.ts b/apps/oxlint/fixtures/tsgolint/no-floating-promises.ts new file mode 100644 index 0000000000000..28edcf1287400 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-floating-promises.ts @@ -0,0 +1,2 @@ +const promise = new Promise((resolve, _reject) => resolve("value")); +promise; diff --git a/apps/oxlint/fixtures/tsgolint/no-floating-promises/index.ts b/apps/oxlint/fixtures/tsgolint/no-floating-promises/index.ts deleted file mode 100644 index d72280a5103e4..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-floating-promises/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -const promise = new Promise((resolve, _reject) => resolve("value")); -promise; - -async function returnsPromise() { - return "value"; -} - -returnsPromise().then(() => {}); - -Promise.reject("value").catch(); - -Promise.reject("value").finally(); - -[1, 2, 3].map(async (x) => x + 1); \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-floating-promises/src/.oxlintrc.json b/apps/oxlint/fixtures/tsgolint/no-floating-promises/src/.oxlintrc.json deleted file mode 100644 index 25f96058c7232..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-floating-promises/src/.oxlintrc.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "categories": { - "correctness": "off" - }, - "rules": { - "typescript/no-floating-promises": "warn" - }, - "overrides": [ - { - "files": ["overrides.ts"], - "rules": { - "typescript/no-floating-promises": "error" - } - } - ] -} diff --git a/apps/oxlint/fixtures/tsgolint/no-floating-promises/src/index.ts b/apps/oxlint/fixtures/tsgolint/no-floating-promises/src/index.ts deleted file mode 100644 index d72280a5103e4..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-floating-promises/src/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -const promise = new Promise((resolve, _reject) => resolve("value")); -promise; - -async function returnsPromise() { - return "value"; -} - -returnsPromise().then(() => {}); - -Promise.reject("value").catch(); - -Promise.reject("value").finally(); - -[1, 2, 3].map(async (x) => x + 1); \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-floating-promises/src/overrides.ts b/apps/oxlint/fixtures/tsgolint/no-floating-promises/src/overrides.ts deleted file mode 100644 index 14e1da248de6a..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-floating-promises/src/overrides.ts +++ /dev/null @@ -1,4 +0,0 @@ -async function returnsPromise() { - return "value"; -} -returnsPromise().then(() => {}); diff --git a/apps/oxlint/fixtures/tsgolint/no-for-in-array.ts b/apps/oxlint/fixtures/tsgolint/no-for-in-array.ts new file mode 100644 index 0000000000000..52c0599ab19d2 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-for-in-array.ts @@ -0,0 +1,4 @@ +const arr = [1, 2, 3]; +for (const i in arr) { + console.log(arr[i]); +} \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-for-in-array/index.ts b/apps/oxlint/fixtures/tsgolint/no-for-in-array/index.ts deleted file mode 100644 index 5c1c131bc70a3..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-for-in-array/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -// Examples of incorrect code for no-for-in-array rule - -const arr = [1, 2, 3]; - -for (const i in arr) { - console.log(arr[i]); -} - -for (const i in arr) { - console.log(i, arr[i]); -} \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-implied-eval.ts b/apps/oxlint/fixtures/tsgolint/no-implied-eval.ts new file mode 100644 index 0000000000000..cc866733f0691 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-implied-eval.ts @@ -0,0 +1 @@ +setTimeout('alert("Hi!");', 100); \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-implied-eval/index.ts b/apps/oxlint/fixtures/tsgolint/no-implied-eval/index.ts deleted file mode 100644 index 91cd01580d930..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-implied-eval/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Examples of incorrect code for no-implied-eval rule - -setTimeout('alert("Hi!");', 100); - -setInterval('alert("Hi!");', 100); - -setImmediate('alert("Hi!")'); - -window.setTimeout('count = 5', 10); - -window.setInterval('foo = bar', 10); - -const fn = new Function('a', 'b', 'return a + b'); \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-meaningless-void-operator.ts b/apps/oxlint/fixtures/tsgolint/no-meaningless-void-operator.ts new file mode 100644 index 0000000000000..45f2ed0a8b93f --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-meaningless-void-operator.ts @@ -0,0 +1,4 @@ +function foo(): void { + return; +} +void foo(); \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-meaningless-void-operator/index.ts b/apps/oxlint/fixtures/tsgolint/no-meaningless-void-operator/index.ts deleted file mode 100644 index 9a85b893c00ab..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-meaningless-void-operator/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Examples of incorrect code for no-meaningless-void-operator rule - -function foo(): void { - return; -} - -void foo(); // meaningless, foo() already returns void - -void undefined; // meaningless, undefined is already undefined - -async function bar() { - void (await somePromise); // meaningless if somePromise resolves to void -} \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-misused-spread.ts b/apps/oxlint/fixtures/tsgolint/no-misused-spread.ts new file mode 100644 index 0000000000000..756675e7a3c40 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-misused-spread.ts @@ -0,0 +1,2 @@ +declare const promise: Promise; +const spreadPromise = { ...promise }; diff --git a/apps/oxlint/fixtures/tsgolint/no-misused-spread/index.ts b/apps/oxlint/fixtures/tsgolint/no-misused-spread/index.ts deleted file mode 100644 index 336f9cd0c5c58..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-misused-spread/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -declare const promise: Promise; -const spreadPromise = { ...promise }; - -declare function getObject(): Record; -const getObjectSpread = { ...getObject }; - -declare const map: Map; -const mapSpread = { ...map }; - -declare const userName: string; -const characters = [...userName]; diff --git a/apps/oxlint/fixtures/tsgolint/no-mixed-enums.ts b/apps/oxlint/fixtures/tsgolint/no-mixed-enums.ts new file mode 100644 index 0000000000000..ebe572748a58f --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-mixed-enums.ts @@ -0,0 +1,4 @@ +enum Status { + Open = 1, + Closed = 'closed', +} \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-mixed-enums/index.ts b/apps/oxlint/fixtures/tsgolint/no-mixed-enums/index.ts deleted file mode 100644 index 83480d502510a..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-mixed-enums/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Examples of incorrect code for no-mixed-enums rule - -enum Status { - Open = 1, - Closed = 'closed', -} - -enum Direction { - Up = 'up', - Down = 2, - Left = 'left', - Right = 4, -} \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-redundant-type-constituents.ts b/apps/oxlint/fixtures/tsgolint/no-redundant-type-constituents.ts new file mode 100644 index 0000000000000..27e9a275b5907 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-redundant-type-constituents.ts @@ -0,0 +1 @@ +type T1 = string | unknown; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-redundant-type-constituents/index.ts b/apps/oxlint/fixtures/tsgolint/no-redundant-type-constituents/index.ts deleted file mode 100644 index 17d1eea47dd39..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-redundant-type-constituents/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -// Examples of incorrect code for no-redundant-type-constituents rule - -// unknown is redundant in unions -type T1 = string | unknown; - -// any is redundant in unions -type T2 = string | any; - -// never is redundant in unions -type T3 = string | never; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unnecessary-boolean-literal-compare.ts b/apps/oxlint/fixtures/tsgolint/no-unnecessary-boolean-literal-compare.ts new file mode 100644 index 0000000000000..485c37e78e199 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-unnecessary-boolean-literal-compare.ts @@ -0,0 +1,3 @@ +declare const someCondition: boolean; +if (someCondition === true) { +} \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unnecessary-boolean-literal-compare/index.ts b/apps/oxlint/fixtures/tsgolint/no-unnecessary-boolean-literal-compare/index.ts deleted file mode 100644 index 0bf6cc1b919f2..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-unnecessary-boolean-literal-compare/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -// Examples of incorrect code for no-unnecessary-boolean-literal-compare rule - -declare const someCondition: boolean; - -if (someCondition === true) { - // ... -} - -if (someCondition === false) { - // ... -} \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unnecessary-template-expression.ts b/apps/oxlint/fixtures/tsgolint/no-unnecessary-template-expression.ts new file mode 100644 index 0000000000000..bb1fccb784e59 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-unnecessary-template-expression.ts @@ -0,0 +1 @@ +const str1 = `Hello world`; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unnecessary-template-expression/index.ts b/apps/oxlint/fixtures/tsgolint/no-unnecessary-template-expression/index.ts deleted file mode 100644 index 157f6537dd2a9..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-unnecessary-template-expression/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -// Examples of incorrect code for no-unnecessary-template-expression rule - -const str1 = `Hello world`; - -const str2 = `42`; - -const str3 = `true`; - -// Template with only literal expressions -const str4 = `${'Hello'} ${'world'}`; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unnecessary-type-arguments.ts b/apps/oxlint/fixtures/tsgolint/no-unnecessary-type-arguments.ts new file mode 100644 index 0000000000000..043c53842a257 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-unnecessary-type-arguments.ts @@ -0,0 +1,4 @@ +function identity(arg: T): T { + return arg; +} +const result = identity('hello'); \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unnecessary-type-arguments/index.ts b/apps/oxlint/fixtures/tsgolint/no-unnecessary-type-arguments/index.ts deleted file mode 100644 index 5823f8cbb7045..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-unnecessary-type-arguments/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -// Examples of incorrect code for no-unnecessary-type-arguments rule - -function identity(arg: T): T { - return arg; -} - -// Unnecessary type argument - string is the default -const result = identity('hello'); - -interface Container { - value: T; -} \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unnecessary-type-assertion.ts b/apps/oxlint/fixtures/tsgolint/no-unnecessary-type-assertion.ts new file mode 100644 index 0000000000000..18c3219b9e9a2 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-unnecessary-type-assertion.ts @@ -0,0 +1,2 @@ +const str: string = 'hello'; +const redundant = str as string; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unnecessary-type-assertion/index.ts b/apps/oxlint/fixtures/tsgolint/no-unnecessary-type-assertion/index.ts deleted file mode 100644 index 826adad2e694d..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-unnecessary-type-assertion/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -// Examples of incorrect code for no-unnecessary-type-assertion rule - -const str: string = 'hello'; -const redundant = str as string; // unnecessary, str is already string - -function getString(): string { - return 'hello'; -} -const result = getString() as string; // unnecessary, getString() already returns string - -const num = 42; -const alsoRedundant = num as 42; // unnecessary if TypeScript can infer literal type \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unsafe-argument.ts b/apps/oxlint/fixtures/tsgolint/no-unsafe-argument.ts new file mode 100644 index 0000000000000..d4705ae251ec9 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-unsafe-argument.ts @@ -0,0 +1,3 @@ +declare const anyValue: any; +function takesString(str: string): void {} +takesString(anyValue); \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unsafe-argument/index.ts b/apps/oxlint/fixtures/tsgolint/no-unsafe-argument/index.ts deleted file mode 100644 index ab91796b9af43..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-unsafe-argument/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -// Examples of incorrect code for no-unsafe-argument rule - -declare const anyValue: any; - -function takesString(str: string): void { - console.log(str.length); -} - -takesString(anyValue); // unsafe - -declare function takesNumber(num: number): number; -const result = takesNumber(anyValue); // unsafe \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unsafe-assignment.ts b/apps/oxlint/fixtures/tsgolint/no-unsafe-assignment.ts new file mode 100644 index 0000000000000..8d2b51c96c536 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-unsafe-assignment.ts @@ -0,0 +1,2 @@ +declare const anyValue: any; +const str: string = anyValue; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unsafe-assignment/index.ts b/apps/oxlint/fixtures/tsgolint/no-unsafe-assignment/index.ts deleted file mode 100644 index bd0aeb322cc32..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-unsafe-assignment/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -// Examples of incorrect code for no-unsafe-assignment rule - -declare const anyValue: any; - -const str: string = anyValue; // unsafe assignment - -let num: number; -num = anyValue; // unsafe assignment - -const obj = { - prop: anyValue as any, // unsafe assignment -}; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unsafe-call.ts b/apps/oxlint/fixtures/tsgolint/no-unsafe-call.ts new file mode 100644 index 0000000000000..a21cd9d82137a --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-unsafe-call.ts @@ -0,0 +1,2 @@ +declare const anyValue: any; +anyValue(); \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unsafe-call/index.ts b/apps/oxlint/fixtures/tsgolint/no-unsafe-call/index.ts deleted file mode 100644 index 700c4695f2c18..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-unsafe-call/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -// Examples of incorrect code for no-unsafe-call rule - -declare const anyValue: any; - -anyValue(); // unsafe call - -anyValue(1, 2, 3); // unsafe call - -const result = anyValue('hello'); // unsafe call - -// Chained unsafe calls -anyValue().then().catch(); // unsafe \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unsafe-enum-comparison/index.ts b/apps/oxlint/fixtures/tsgolint/no-unsafe-enum-comparison.ts similarity index 60% rename from apps/oxlint/fixtures/tsgolint/no-unsafe-enum-comparison/index.ts rename to apps/oxlint/fixtures/tsgolint/no-unsafe-enum-comparison.ts index 8886517588684..d7759e215434e 100644 --- a/apps/oxlint/fixtures/tsgolint/no-unsafe-enum-comparison/index.ts +++ b/apps/oxlint/fixtures/tsgolint/no-unsafe-enum-comparison.ts @@ -1,14 +1,9 @@ -// Examples of incorrect code for no-unsafe-enum-comparison rule - enum Status { Open = 'open', Closed = 'closed', } - enum Color { Red = 'red', Blue = 'blue', } - -// Comparing different enums const comparison = Status.Open === Color.Red; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unsafe-member-access.ts b/apps/oxlint/fixtures/tsgolint/no-unsafe-member-access.ts new file mode 100644 index 0000000000000..2dc3a11874694 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-unsafe-member-access.ts @@ -0,0 +1,2 @@ +declare const anyValue: any; +anyValue.foo; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unsafe-member-access/index.ts b/apps/oxlint/fixtures/tsgolint/no-unsafe-member-access/index.ts deleted file mode 100644 index b44a4ac7501ca..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-unsafe-member-access/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -// Examples of incorrect code for no-unsafe-member-access rule - -declare const anyValue: any; - -anyValue.foo; // unsafe member access - -anyValue.bar.baz; // unsafe nested member access - -anyValue['key']; // unsafe computed member access - -const result = anyValue.method(); // unsafe method access \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unsafe-return.ts b/apps/oxlint/fixtures/tsgolint/no-unsafe-return.ts new file mode 100644 index 0000000000000..b4900b1f6ec90 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-unsafe-return.ts @@ -0,0 +1,4 @@ +declare const anyValue: any; +function getString(): string { + return anyValue; +} \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unsafe-return/index.ts b/apps/oxlint/fixtures/tsgolint/no-unsafe-return/index.ts deleted file mode 100644 index fff32c0f9f923..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-unsafe-return/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Examples of incorrect code for no-unsafe-return rule - -declare const anyValue: any; - -function getString(): string { - return anyValue; // unsafe return -} - -const getNumber = (): number => anyValue; // unsafe return - -function processData(): { name: string; age: number } { - return anyValue; // unsafe return -} \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unsafe-type-assertion.ts b/apps/oxlint/fixtures/tsgolint/no-unsafe-type-assertion.ts new file mode 100644 index 0000000000000..93e3573261751 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-unsafe-type-assertion.ts @@ -0,0 +1,2 @@ +declare const value: unknown; +const str = value as any; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unsafe-type-assertion/index.ts b/apps/oxlint/fixtures/tsgolint/no-unsafe-type-assertion/index.ts deleted file mode 100644 index 292ba321b0fa5..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-unsafe-type-assertion/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -// Examples of incorrect code for no-unsafe-type-assertion rule - -declare const value: unknown; - -const str = value as any; // unsafe type assertion - -const obj = value as any as string; // double assertion through any - -function processValue(input: unknown) { - const processed = input as any; // unsafe - return processed.someProperty; -} \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unsafe-unary-minus.ts b/apps/oxlint/fixtures/tsgolint/no-unsafe-unary-minus.ts new file mode 100644 index 0000000000000..e22acab0110b8 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/no-unsafe-unary-minus.ts @@ -0,0 +1,2 @@ +declare const value: any; +const result1 = -value; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/no-unsafe-unary-minus/index.ts b/apps/oxlint/fixtures/tsgolint/no-unsafe-unary-minus/index.ts deleted file mode 100644 index bb4c89cff47da..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/no-unsafe-unary-minus/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Examples of incorrect code for no-unsafe-unary-minus rule - -declare const value: any; -const result1 = -value; // unsafe on any - -declare const str: string; -const result2 = -str; // unsafe on string - -declare const bool: boolean; -const result3 = -bool; // unsafe on boolean - -declare const obj: object; -const result4 = -obj; // unsafe on object \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/non-nullable-type-assertion-style.ts b/apps/oxlint/fixtures/tsgolint/non-nullable-type-assertion-style.ts new file mode 100644 index 0000000000000..1a1a94ab142f0 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/non-nullable-type-assertion-style.ts @@ -0,0 +1,2 @@ +declare const value: string | null; +const result1 = value as string; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/non-nullable-type-assertion-style/index.ts b/apps/oxlint/fixtures/tsgolint/non-nullable-type-assertion-style/index.ts deleted file mode 100644 index 7de408660945c..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/non-nullable-type-assertion-style/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -// Examples of incorrect code for non-nullable-type-assertion-style rule - -declare const value: string | null; - -// Type assertion when non-null assertion would be clearer -const result1 = value as string; - -declare const maybe: number | undefined; -const result2 = maybe as number; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/only-throw-error.ts b/apps/oxlint/fixtures/tsgolint/only-throw-error.ts new file mode 100644 index 0000000000000..9224d17d2ae31 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/only-throw-error.ts @@ -0,0 +1 @@ +throw 'error'; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/only-throw-error/index.ts b/apps/oxlint/fixtures/tsgolint/only-throw-error/index.ts deleted file mode 100644 index 1f47a8f24fa4a..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/only-throw-error/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -// Examples of incorrect code for only-throw-error rule - -throw 'error'; // throwing string - -throw 42; // throwing number - -throw true; // throwing boolean - -throw { message: 'error' }; // throwing plain object - -throw null; // throwing null \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/prefer-promise-reject-errors.ts b/apps/oxlint/fixtures/tsgolint/prefer-promise-reject-errors.ts new file mode 100644 index 0000000000000..c3227c51e38eb --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/prefer-promise-reject-errors.ts @@ -0,0 +1 @@ +Promise.reject('error'); \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/prefer-promise-reject-errors/index.ts b/apps/oxlint/fixtures/tsgolint/prefer-promise-reject-errors/index.ts deleted file mode 100644 index 0bb99b8c1497d..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/prefer-promise-reject-errors/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -// Examples of incorrect code for prefer-promise-reject-errors rule - -Promise.reject('error'); // rejecting with string - -Promise.reject(42); // rejecting with number - -Promise.reject(true); // rejecting with boolean - -Promise.reject({ message: 'error' }); // rejecting with plain object - -Promise.reject(null); // rejecting with null \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/prefer-reduce-type-parameter.ts b/apps/oxlint/fixtures/tsgolint/prefer-reduce-type-parameter.ts new file mode 100644 index 0000000000000..298a86ec9886a --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/prefer-reduce-type-parameter.ts @@ -0,0 +1,2 @@ +const numbers = [1, 2, 3]; +const sum = numbers.reduce((acc, val) => acc + val, 0) as number; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/prefer-reduce-type-parameter/index.ts b/apps/oxlint/fixtures/tsgolint/prefer-reduce-type-parameter/index.ts deleted file mode 100644 index e77da0b789017..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/prefer-reduce-type-parameter/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -// Examples of incorrect code for prefer-reduce-type-parameter rule - -const numbers = [1, 2, 3]; - -// Casting the result -const sum = numbers.reduce((acc, val) => acc + val, 0) as number; - -// Using type assertion on accumulator -const result = [1, 2, 3].reduce((acc: string[], curr) => { - acc.push(curr.toString()); - return acc; -}, [] as string[]); \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/prefer-return-this-type.ts b/apps/oxlint/fixtures/tsgolint/prefer-return-this-type.ts new file mode 100644 index 0000000000000..da11bbdaa4f1c --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/prefer-return-this-type.ts @@ -0,0 +1,7 @@ +class Builder { + private value: string = ''; + setValue(value: string): Builder { + this.value = value; + return this; + } +} \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/prefer-return-this-type/index.ts b/apps/oxlint/fixtures/tsgolint/prefer-return-this-type/index.ts deleted file mode 100644 index 5823eff7cc532..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/prefer-return-this-type/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -// Examples of incorrect code for prefer-return-this-type rule - -class Builder { - private value: string = ''; - - setValue(value: string): Builder { // Should return 'this' - this.value = value; - return this; - } - - build(): string { - return this.value; - } -} \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/promise-function-async.ts b/apps/oxlint/fixtures/tsgolint/promise-function-async.ts new file mode 100644 index 0000000000000..28831dd1eb811 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/promise-function-async.ts @@ -0,0 +1,4 @@ +declare function fetch(url: string): Promise; +function fetchData(): Promise { + return fetch('/api/data').then(res => res.text()); +} \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/promise-function-async/index.ts b/apps/oxlint/fixtures/tsgolint/promise-function-async/index.ts deleted file mode 100644 index f464367d7ba31..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/promise-function-async/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Examples of incorrect code for promise-function-async rule - -// Function returning Promise without async -function fetchData(): Promise { - return fetch('/api/data').then(res => res.text()); -} - -// Method returning Promise without async -class DataService { - getData(): Promise { - return fetch('/api/data').then(res => res.json()); - } -} \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/related-getter-setter-pairs.ts b/apps/oxlint/fixtures/tsgolint/related-getter-setter-pairs.ts new file mode 100644 index 0000000000000..eaab1ca0a12f0 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/related-getter-setter-pairs.ts @@ -0,0 +1,9 @@ +class Example { + private _value: number = 0; + get value(): string { + return this._value.toString(); + } + set value(val: number) { + this._value = val; + } +} \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/related-getter-setter-pairs/index.ts b/apps/oxlint/fixtures/tsgolint/related-getter-setter-pairs/index.ts deleted file mode 100644 index 6756fa89497c3..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/related-getter-setter-pairs/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -// Examples of incorrect code for related-getter-setter-pairs rule - -class Example { - private _value: number = 0; - - // Getter and setter with incompatible types - get value(): string { - return this._value.toString(); - } - - set value(val: number) { // Incompatible with getter - this._value = val; - } -} \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/require-array-sort-compare.ts b/apps/oxlint/fixtures/tsgolint/require-array-sort-compare.ts new file mode 100644 index 0000000000000..3835219a7a68a --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/require-array-sort-compare.ts @@ -0,0 +1,2 @@ +const numbers = [3, 1, 4, 1, 5]; +numbers.sort(); \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/require-array-sort-compare/index.ts b/apps/oxlint/fixtures/tsgolint/require-array-sort-compare/index.ts deleted file mode 100644 index 25bafd3f6babf..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/require-array-sort-compare/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -// Examples of incorrect code for require-array-sort-compare rule - -const numbers = [3, 1, 4, 1, 5]; -numbers.sort(); // Lexicographic sort, not numeric - -const mixedArray = ['10', '2', '1']; -mixedArray.sort(); // Might be intended, but explicit compareFn is clearer - -[3, 1, 4].sort(); // Will sort as strings: ['1', '3', '4'] \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/require-await.ts b/apps/oxlint/fixtures/tsgolint/require-await.ts new file mode 100644 index 0000000000000..8f663a635d178 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/require-await.ts @@ -0,0 +1,4 @@ +declare function fetch(url: string): Promise; +async function fetchData() { + return fetch('/api/data'); +} \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/require-await/index.ts b/apps/oxlint/fixtures/tsgolint/require-await/index.ts deleted file mode 100644 index d342696721bfe..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/require-await/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -// Examples of incorrect code for require-await rule - -// Async function without await -async function fetchData() { - return fetch('/api/data'); -} - -// Async arrow function without await -const processData = async () => { - return someData.map(x => x * 2); -}; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/restrict-plus-operands.ts b/apps/oxlint/fixtures/tsgolint/restrict-plus-operands.ts new file mode 100644 index 0000000000000..2636da4d8eb6e --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/restrict-plus-operands.ts @@ -0,0 +1 @@ +let foo = 1n + 1; diff --git a/apps/oxlint/fixtures/tsgolint/restrict-plus-operands/index.ts b/apps/oxlint/fixtures/tsgolint/restrict-plus-operands/index.ts deleted file mode 100644 index 8960e470652df..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/restrict-plus-operands/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -let foo = 1n + 1; -let fn = (a: string, b: never) => a + b; diff --git a/apps/oxlint/fixtures/tsgolint/restrict-template-expressions.ts b/apps/oxlint/fixtures/tsgolint/restrict-template-expressions.ts new file mode 100644 index 0000000000000..e71f014eb1a35 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/restrict-template-expressions.ts @@ -0,0 +1,2 @@ +declare const obj: object; +const str1 = `Value: ${obj}`; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/restrict-template-expressions/index.ts b/apps/oxlint/fixtures/tsgolint/restrict-template-expressions/index.ts deleted file mode 100644 index e057e69e5fd69..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/restrict-template-expressions/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -// Examples of incorrect code for restrict-template-expressions rule - -declare const obj: object; -declare const sym: symbol; -declare const fn: () => void; -declare const arr: unknown[]; - -// Objects become "[object Object]" -const str1 = `Value: ${obj}`; - -// Symbols might not be what you expect -const str2 = `Symbol: ${sym}`; - -// Functions become their string representation -const str3 = `Function: ${fn}`; - -// Arrays of unknown might be unsafe -const str4 = `Array: ${arr}`; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/return-await.ts b/apps/oxlint/fixtures/tsgolint/return-await.ts new file mode 100644 index 0000000000000..1c1181ee743a4 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/return-await.ts @@ -0,0 +1,5 @@ +declare interface User { id: number; } +declare function getUser(): Promise; +async function fetchUser(): Promise { + return getUser(); +} \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/return-await/index.ts b/apps/oxlint/fixtures/tsgolint/return-await/index.ts deleted file mode 100644 index 15df03418bc92..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/return-await/index.ts +++ /dev/null @@ -1,32 +0,0 @@ -// Examples of incorrect code for return-await rule -// This rule requires consistent return await usage - -async function fetchUser(): Promise { - // Should be: return await getUser(); - return getUser(); // Missing await -} - -async function processData(): Promise { - try { - // Should be: return await fetchData(); - return fetchData(); // Missing await in try block - } catch (error) { - throw new Error('Failed to process'); - } -} - -// In try-catch, return await is recommended for proper stack traces -async function handleRequest(): Promise { - try { - return handleAsync(); // Should use await - } catch (error) { - console.error(error); - throw error; - } -} - -declare function getUser(): Promise; -declare function fetchData(): Promise; -declare function handleAsync(): Promise; -declare interface User { id: number; } -declare interface Response { data: any; } \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/strict-boolean-expressions.ts b/apps/oxlint/fixtures/tsgolint/strict-boolean-expressions.ts new file mode 100644 index 0000000000000..2a35004d68e4c --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/strict-boolean-expressions.ts @@ -0,0 +1,3 @@ +const str = 'hello'; +if (str) { +} diff --git a/apps/oxlint/fixtures/tsgolint/strict-boolean-expressions/index.ts b/apps/oxlint/fixtures/tsgolint/strict-boolean-expressions/index.ts deleted file mode 100644 index 88f8ef4ae3f7a..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/strict-boolean-expressions/index.ts +++ /dev/null @@ -1,67 +0,0 @@ -// Examples of incorrect code for strict-boolean-expressions rule - -// Non-boolean values in conditions -const str = 'hello'; -if (str) { // string is not a boolean - console.log('string'); -} - -const num = 42; -if (num) { // number is not a boolean - console.log('number'); -} - -const obj = { foo: 'bar' }; -if (obj) { // object is not a boolean - console.log('object'); -} - -// Nullable booleans -declare const maybeBool: boolean | null; -if (maybeBool) { // nullable boolean - console.log('maybe'); -} - -// Undefined checks -declare const maybeString: string | undefined; -if (maybeString) { // should explicitly check !== undefined - console.log(maybeString); -} - -// Logical operators with non-booleans -const result1 = str && num; -const result2 = obj || num; - -// While loops with non-boolean -while (num) { - console.log('loop'); - break; -} - -// Do-while with non-boolean -do { - console.log('do'); -} while (str); - -// For loop with non-boolean -for (let i = 0; i; i++) { - console.log('for'); -} - -// Ternary with non-boolean -const ternary = str ? 'yes' : 'no'; - -// Logical NOT on non-boolean -const negated = !str; - -// Mixed types in logical expressions -declare const mixed: string | number; -if (mixed) { - console.log('mixed'); -} - -// any type (should allow or warn depending on config) -declare const anyValue: any; -if (anyValue) { - console.log('any'); -} diff --git a/apps/oxlint/fixtures/tsgolint/switch-exhaustiveness-check/index.ts b/apps/oxlint/fixtures/tsgolint/switch-exhaustiveness-check.ts similarity index 69% rename from apps/oxlint/fixtures/tsgolint/switch-exhaustiveness-check/index.ts rename to apps/oxlint/fixtures/tsgolint/switch-exhaustiveness-check.ts index ec8f613b22c8e..016b0c2c88f02 100644 --- a/apps/oxlint/fixtures/tsgolint/switch-exhaustiveness-check/index.ts +++ b/apps/oxlint/fixtures/tsgolint/switch-exhaustiveness-check.ts @@ -1,13 +1,9 @@ -// Examples of incorrect code for switch-exhaustiveness-check rule - type Status = 'pending' | 'approved' | 'rejected'; - function handleStatus(status: Status) { switch (status) { case 'pending': return 'Waiting for approval'; case 'approved': return 'Request approved'; - // Missing 'rejected' case } } \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/unbound-method.ts b/apps/oxlint/fixtures/tsgolint/unbound-method.ts new file mode 100644 index 0000000000000..9aa988154ea3a --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/unbound-method.ts @@ -0,0 +1,9 @@ +class Calculator { + private value: number = 0; + add(num: number): number { + this.value += num; + return this.value; + } +} +const calc = new Calculator(); +const addMethod = calc.add; \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/unbound-method/index.ts b/apps/oxlint/fixtures/tsgolint/unbound-method/index.ts deleted file mode 100644 index fa332dd94e6e1..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/unbound-method/index.ts +++ /dev/null @@ -1,31 +0,0 @@ -// Examples of incorrect code for unbound-method rule - -class Calculator { - private value: number = 0; - - add(num: number): number { - this.value += num; - return this.value; - } - - getValue(): number { - return this.value; - } -} - -const calc = new Calculator(); - -// Unbound method - loses 'this' context -const addMethod = calc.add; -addMethod(5); // Error: 'this' is undefined - -// Array method callback loses context -const getValue = calc.getValue; -[1, 2, 3].map(getValue); // Error: each call loses 'this' - -// Unbound method in setTimeout -setTimeout(calc.add, 1000, 10); // Error: 'this' context lost - -// Class method destructuring -const { getValue: getVal } = calc; -getVal(); // Error: 'this' context lost \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/use-unknown-in-catch-callback-variable.ts b/apps/oxlint/fixtures/tsgolint/use-unknown-in-catch-callback-variable.ts new file mode 100644 index 0000000000000..b727fb4d589a1 --- /dev/null +++ b/apps/oxlint/fixtures/tsgolint/use-unknown-in-catch-callback-variable.ts @@ -0,0 +1,5 @@ +declare function riskyOperation(): void; +try { + riskyOperation(); +} catch (error: any) { +} \ No newline at end of file diff --git a/apps/oxlint/fixtures/tsgolint/use-unknown-in-catch-callback-variable/index.ts b/apps/oxlint/fixtures/tsgolint/use-unknown-in-catch-callback-variable/index.ts deleted file mode 100644 index 770255fce7a2d..0000000000000 --- a/apps/oxlint/fixtures/tsgolint/use-unknown-in-catch-callback-variable/index.ts +++ /dev/null @@ -1,35 +0,0 @@ -// Examples of incorrect code for use-unknown-in-catch-callback-variable rule - -// Should use 'unknown' instead of 'any' -try { - riskyOperation(); -} catch (error: any) { // Should be: error: unknown - console.log(error.message); -} - -// Implicit 'any' in catch clause -try { - riskyOperation(); -} catch (error) { // Implicitly 'any', should be: error: unknown - handleError(error); -} - -// Promise catch with explicit any -promise.catch((error: any) => { // Should be: error: unknown - console.error(error.message); -}); - -// Callback with any error type -function handleAsync(callback: (error: any) => void) { // Should be: error: unknown - try { - performOperation(); - callback(null); - } catch (err) { - callback(err); - } -} - -declare function riskyOperation(): void; -declare function handleError(error: unknown): void; -declare const promise: Promise; -declare function performOperation(): void; \ No newline at end of file diff --git a/apps/oxlint/src/lint.rs b/apps/oxlint/src/lint.rs index e4d257b74ac75..c3bd7f85b682c 100644 --- a/apps/oxlint/src/lint.rs +++ b/apps/oxlint/src/lint.rs @@ -1283,8 +1283,7 @@ mod test { #[test] #[cfg(not(target_endian = "big"))] fn test_tsgolint_silent() { - // TODO: test with other rules as well once diagnostics are more stable - let args = &["--type-aware", "--silent", "no-floating-promises"]; + let args = &["--type-aware", "--silent"]; Tester::new().with_cwd("fixtures/tsgolint".into()).test_and_snapshot(args); } @@ -1292,7 +1291,7 @@ mod test { #[cfg(not(target_endian = "big"))] fn test_tsgolint_config() { // TODO: test with other rules as well once diagnostics are more stable - let args = &["--type-aware", "no-floating-promises", "-c", "config-test.json"]; + let args = &["--type-aware", "-c", "config-test.json"]; Tester::new().with_cwd("fixtures/tsgolint".into()).test_and_snapshot(args); } diff --git a/apps/oxlint/src/snapshots/fixtures__tsgolint_--type-aware --silent no-floating-promises@oxlint.snap b/apps/oxlint/src/snapshots/fixtures__tsgolint_--type-aware --silent@oxlint.snap similarity index 52% rename from apps/oxlint/src/snapshots/fixtures__tsgolint_--type-aware --silent no-floating-promises@oxlint.snap rename to apps/oxlint/src/snapshots/fixtures__tsgolint_--type-aware --silent@oxlint.snap index 05319905d1daa..81f852b5fc45f 100644 --- a/apps/oxlint/src/snapshots/fixtures__tsgolint_--type-aware --silent no-floating-promises@oxlint.snap +++ b/apps/oxlint/src/snapshots/fixtures__tsgolint_--type-aware --silent@oxlint.snap @@ -2,12 +2,12 @@ source: apps/oxlint/src/tester.rs --- ########## -arguments: --type-aware --silent no-floating-promises +arguments: --type-aware --silent working directory: fixtures/tsgolint ---------- -Found 5 warnings and 11 errors. -Finished in ms on 3 files using 1 threads. +Found 0 warnings and 53 errors. +Finished in ms on 42 files using 1 threads. ---------- CLI result: LintFoundErrors ---------- diff --git a/apps/oxlint/src/snapshots/fixtures__tsgolint_--type-aware -c config-test.json@oxlint.snap b/apps/oxlint/src/snapshots/fixtures__tsgolint_--type-aware -c config-test.json@oxlint.snap index 422151d271304..91f22e2e67ce4 100644 --- a/apps/oxlint/src/snapshots/fixtures__tsgolint_--type-aware -c config-test.json@oxlint.snap +++ b/apps/oxlint/src/snapshots/fixtures__tsgolint_--type-aware -c config-test.json@oxlint.snap @@ -6,111 +6,39 @@ arguments: --type-aware -c config-test.json working directory: fixtures/tsgolint ---------- - ! typescript-eslint(no-floating-promises): Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` - | operator. - ,-[no-floating-promises/index.ts:2:1] + ! typescript-eslint(no-floating-promises): Promises must be awaited. + ,-[no-floating-promises.ts:2:1] 1 | const promise = new Promise((resolve, _reject) => resolve("value")); 2 | promise; : ^^^^^^^^ - 3 | - `---- - - ! typescript-eslint(no-floating-promises): Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` - | operator. - ,-[no-floating-promises/index.ts:8:1] - 7 | - 8 | returnsPromise().then(() => {}); - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 9 | - `---- - - ! typescript-eslint(no-floating-promises): Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` - | operator. - ,-[no-floating-promises/index.ts:10:1] - 9 | - 10 | Promise.reject("value").catch(); - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 11 | - `---- - - ! typescript-eslint(no-floating-promises): Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` - | operator. - ,-[no-floating-promises/index.ts:12:1] - 11 | - 12 | Promise.reject("value").finally(); - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 13 | - `---- - - ! typescript-eslint(no-floating-promises): An array of Promises may be unintentional. Consider handling the promises' fulfillment or rejection with Promise.all or similar, or explicitly marking - | the expression as ignored with the `void` operator. - ,-[no-floating-promises/index.ts:14:1] - 13 | - 14 | [1, 2, 3].map(async (x) => x + 1); - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - `---- - - ! typescript-eslint(no-floating-promises): Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` - | operator. - ,-[no-floating-promises/src/index.ts:2:1] - 1 | const promise = new Promise((resolve, _reject) => resolve("value")); - 2 | promise; - : ^^^^^^^^ - 3 | `---- + help: The promise must end with a call to .catch, or end with a call to .then with a rejection handler, or be explicitly marked as ignored with the `void` operator. - ! typescript-eslint(no-floating-promises): Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` - | operator. - ,-[no-floating-promises/src/index.ts:8:1] - 7 | - 8 | returnsPromise().then(() => {}); - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 9 | + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed + ,-[non-tsgolint.ts:1:1] + 1 | debugger; + : ^^^^^^^^^ `---- + help: Remove the debugger statement - ! typescript-eslint(no-floating-promises): Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` - | operator. - ,-[no-floating-promises/src/index.ts:10:1] - 9 | - 10 | Promise.reject("value").catch(); - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 11 | - `---- - - ! typescript-eslint(no-floating-promises): Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` - | operator. - ,-[no-floating-promises/src/index.ts:12:1] - 11 | - 12 | Promise.reject("value").finally(); - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 13 | - `---- - - ! typescript-eslint(no-floating-promises): An array of Promises may be unintentional. Consider handling the promises' fulfillment or rejection with Promise.all or similar, or explicitly marking - | the expression as ignored with the `void` operator. - ,-[no-floating-promises/src/index.ts:14:1] - 13 | - 14 | [1, 2, 3].map(async (x) => x + 1); - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - `---- - - ! typescript-eslint(no-floating-promises): Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` - | operator. - ,-[no-floating-promises/src/overrides.ts:4:1] - 3 | } - 4 | returnsPromise().then(() => {}); - : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + ! typescript-eslint(no-floating-promises): Promises must be awaited. + ,-[prefer-promise-reject-errors.ts:1:1] + 1 | Promise.reject('error'); + : ^^^^^^^^^^^^^^^^^^^^^^^^ `---- + help: The promise must end with a call to .catch, or end with a call to .then with a rejection handler, or be explicitly marked as ignored with the `void` operator. x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed - ,-[non-tsgolint.ts:1:1] - 1 | debugger; - : ^^^^^^^^^ + ,-[test.svelte:2:2] + 1 |