Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions apps/oxlint/fixtures/tsgolint/.oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,45 @@
"correctness": "off"
},
"rules": {
"typescript/await-thenable": "error",
"typescript/no-array-delete": "error",
"typescript/no-base-to-string": "error",
"typescript/no-confusing-void-expression": "error",
"typescript/no-duplicate-type-constituents": "error",
"typescript/no-floating-promises": "error",
"typescript/no-for-in-array": "error",
"typescript/no-implied-eval": "error",
"typescript/no-meaningless-void-operator": "error",
"typescript/no-misused-spread": "error",
"typescript/no-mixed-enums": "error",
"typescript/no-redundant-type-constituents": "error",
"typescript/no-unnecessary-boolean-literal-compare": "error",
"typescript/no-unnecessary-template-expression": "error",
"typescript/no-unnecessary-type-arguments": "error",
"typescript/no-unnecessary-type-assertion": "error",
"typescript/no-unsafe-argument": "error",
"typescript/no-unsafe-assignment": "error",
"typescript/no-unsafe-call": "error",
"typescript/no-unsafe-enum-comparison": "error",
"typescript/no-unsafe-member-access": "error",
"typescript/no-unsafe-return": "error",
"typescript/no-unsafe-type-assertion": "error",
"typescript/no-unsafe-unary-minus": "error",
"typescript/non-nullable-type-assertion-style": "error",
"typescript/only-throw-error": "error",
"typescript/prefer-promise-reject-errors": "error",
"typescript/prefer-reduce-type-parameter": "error",
"typescript/prefer-return-this-type": "error",
"typescript/promise-function-async": "error",
"typescript/related-getter-setter-pairs": "error",
"typescript/require-array-sort-compare": "error",
"typescript/require-await": "error",
"typescript/restrict-plus-operands": "error",
"typescript/restrict-template-expressions": "error",
"typescript/return-await": "error",
"typescript/switch-exhaustiveness-check": "error",
"typescript/unbound-method": "error",
"typescript/use-unknown-in-catch-callback-variable": "error",
"no-debugger": "error"
}
}
12 changes: 12 additions & 0 deletions apps/oxlint/fixtures/tsgolint/await-thenable/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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<string>;
await getPromise;
4 changes: 4 additions & 0 deletions apps/oxlint/fixtures/tsgolint/no-array-delete/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Examples of incorrect code for no-array-delete rule

declare const arr: number[];
delete arr[0];
9 changes: 9 additions & 0 deletions apps/oxlint/fixtures/tsgolint/no-base-to-string/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// 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();
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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()) {
// ...
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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';
11 changes: 11 additions & 0 deletions apps/oxlint/fixtures/tsgolint/no-for-in-array/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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]);
}
13 changes: 13 additions & 0 deletions apps/oxlint/fixtures/tsgolint/no-implied-eval/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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');
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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
}
11 changes: 11 additions & 0 deletions apps/oxlint/fixtures/tsgolint/no-misused-spread/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare const promise: Promise<number>;
const spreadPromise = { ...promise };

declare function getObject(): Record<string, strings>;
const getObjectSpread = { ...getObject };

declare const map: Map<string, number>;
const mapSpread = { ...map };

declare const userName: string;
const characters = [...userName];
13 changes: 13 additions & 0 deletions apps/oxlint/fixtures/tsgolint/no-mixed-enums/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// 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;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Examples of incorrect code for no-unnecessary-boolean-literal-compare rule

declare const someCondition: boolean;

if (someCondition === true) {
// ...
}

if (someCondition === false) {
// ...
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// 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'}`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Examples of incorrect code for no-unnecessary-type-arguments rule

function identity<T = string>(arg: T): T {
return arg;
}

// Unnecessary type argument - string is the default
const result = identity<string>('hello');

interface Container<T = number> {
value: T;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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
12 changes: 12 additions & 0 deletions apps/oxlint/fixtures/tsgolint/no-unsafe-argument/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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
12 changes: 12 additions & 0 deletions apps/oxlint/fixtures/tsgolint/no-unsafe-assignment/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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
};
12 changes: 12 additions & 0 deletions apps/oxlint/fixtures/tsgolint/no-unsafe-call/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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;
11 changes: 11 additions & 0 deletions apps/oxlint/fixtures/tsgolint/no-unsafe-member-access/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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
13 changes: 13 additions & 0 deletions apps/oxlint/fixtures/tsgolint/no-unsafe-return/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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
}
12 changes: 12 additions & 0 deletions apps/oxlint/fixtures/tsgolint/no-unsafe-type-assertion/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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;
}
13 changes: 13 additions & 0 deletions apps/oxlint/fixtures/tsgolint/no-unsafe-unary-minus/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// 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;
11 changes: 11 additions & 0 deletions apps/oxlint/fixtures/tsgolint/only-throw-error/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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
Loading
Loading