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
1 change: 1 addition & 0 deletions apps/oxlint/fixtures/tsgolint/.oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"typescript/no-mixed-enums": "error",
"typescript/no-redundant-type-constituents": "error",
"typescript/no-unnecessary-boolean-literal-compare": "error",
"typescript/no-unnecessary-condition": "error",
"typescript/no-unnecessary-template-expression": "error",
"typescript/no-unnecessary-type-arguments": "error",
"typescript/no-unnecessary-type-assertion": "error",
Expand Down
3 changes: 3 additions & 0 deletions apps/oxlint/fixtures/tsgolint/no-unnecessary-condition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare const b1: object;
declare const b2: boolean;
export const t1 = b1 && b2;
8 changes: 8 additions & 0 deletions apps/oxlint/fixtures/tsgolint_rule_options/.oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
"allowOptionalChaining": true
}
],
"typescript/no-unnecessary-condition": [
"error",
{
"allowConstantLoopConditions": true,
"checkTypePredicates": false,
"allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing": false
}
],
"typescript/only-throw-error": [
"error",
{
Expand Down
12 changes: 12 additions & 0 deletions apps/oxlint/fixtures/tsgolint_rule_options/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ declare const unknownValue: unknown;
// This SHOULD error because checkUnknown is true
const unknownStr = unknownValue.toString();

// Test no-unnecessary-condition with allowConstantLoopConditions option
declare const alwaysTruthyObject: object;
// This SHOULD error because this object is always truthy
if (alwaysTruthyObject) {
result += 1;
}

// This should NOT error because allowConstantLoopConditions is true
while (true) {
break;
}

// Test only-throw-error with allowRethrowing option
// When allowRethrowing is false, rethrowing a caught error SHOULD error
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ arguments: --type-aware --silent
working directory: fixtures/tsgolint
----------

Found 0 warnings and 52 errors.
Finished in <variable>ms on 46 files with 45 rules using 1 threads.
Found 0 warnings and 57 errors.
Finished in <variable>ms on 47 files with 46 rules using 1 threads.
----------
CLI result: LintFoundErrors
----------
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ working directory: fixtures/tsgolint
help: Remove the debugger statement

Found 2 warnings and 2 errors.
Finished in <variable>ms on 46 files with 1 rules using 1 threads.
Finished in <variable>ms on 47 files with 1 rules using 1 threads.
----------
CLI result: LintFoundErrors
----------
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ working directory: fixtures/tsgolint
help: Remove the debugger statement

Found 0 warnings and 1 error.
Finished in <variable>ms on 1 file with 45 rules using 1 threads.
Finished in <variable>ms on 1 file with 46 rules using 1 threads.
----------
CLI result: LintFoundErrors
----------
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ working directory: fixtures/tsgolint
3 | }
`----

x typescript-eslint(no-unnecessary-condition): Unnecessary conditional, value is always truthy.
,-[no-unnecessary-condition.ts:3:19]
2 | declare const b2: boolean;
3 | export const t1 = b1 && b2;
: ^^
`----

x typescript-eslint(strict-boolean-expressions): Unexpected object value in conditional. An object is always truthy.
,-[no-unnecessary-condition.ts:3:19]
2 | declare const b2: boolean;
3 | export const t1 = b1 && b2;
: ^^
`----

x typescript-eslint(no-unnecessary-template-expression): Template literal expression is unnecessary and can be simplified.
,-[no-unnecessary-template-expression.ts:2:18]
1 | const text = 'hello';
Expand Down Expand Up @@ -181,6 +195,14 @@ working directory: fixtures/tsgolint
3 |
`----

x typescript-eslint(no-unnecessary-condition): Unnecessary comparison between literal values.
,-[no-unsafe-enum-comparison.ts:9:20]
8 | }
9 | const comparison = Status.Open === Color.Red;
: ^^^^^^^^^^^^^^^^^^^^^^^^^
10 |
`----

x typescript-eslint(no-unsafe-enum-comparison): The two values in this comparison do not have a shared enum type.
,-[no-unsafe-enum-comparison.ts:9:20]
8 | }
Expand Down Expand Up @@ -283,6 +305,13 @@ working directory: fixtures/tsgolint
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----

x typescript-eslint(no-unnecessary-condition): This condition will always return the same value since the types have no overlap.
,-[prefer-nullish-coalescing.ts:2:50]
1 | declare const nullableString: string | null;
2 | const nullishResult = nullableString !== null && nullableString !== undefined ? nullableString : 'default';
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----

x typescript-eslint(prefer-optional-chain): Prefer using an optional chain expression instead, as it's more concise and easier to read.
,-[prefer-optional-chain.ts:3:1]
2 | declare const fooOptC: { bar: number } | null | undefined;
Expand Down Expand Up @@ -381,6 +410,14 @@ working directory: fixtures/tsgolint
3 |
`----

x typescript-eslint(no-unnecessary-condition): Unnecessary conditional, value is always truthy.
,-[strict-boolean-expressions.ts:2:5]
1 | const str = 'hello';
2 | if (str) {
: ^^^
3 | }
`----

x typescript-eslint(switch-exhaustiveness-check): Switch is not exhaustive
,-[switch-exhaustiveness-check.ts:3:11]
2 | function handleStatus(status: Status) {
Expand All @@ -406,8 +443,8 @@ working directory: fixtures/tsgolint
: ^^^^^^^^
`----

Found 0 warnings and 52 errors.
Finished in <variable>ms on 46 files with 45 rules using 1 threads.
Found 0 warnings and 57 errors.
Finished in <variable>ms on 47 files with 46 rules using 1 threads.
----------
CLI result: LintFoundErrors
----------
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@ working directory: fixtures/tsgolint_rule_options
`----
help: Consider picking a property (e.g. `user.name`), using a formatter (or `JSON.stringify`), or implementing a custom `toString()`/`toLocaleString()` on the type.

Found 0 warnings and 4 errors.
Finished in <variable>ms on 1 file with 7 rules using 1 threads.
x typescript-eslint(no-unnecessary-condition): Unnecessary conditional, value is always truthy.
,-[test.ts:68:5]
67 | // This SHOULD error because this object is always truthy
68 | if (alwaysTruthyObject) {
: ^^^^^^^^^^^^^^^^^^
69 | result += 1;
`----

Found 0 warnings and 5 errors.
Finished in <variable>ms on 1 file with 8 rules using 1 threads.
----------
CLI result: LintFoundErrors
----------
5 changes: 5 additions & 0 deletions crates/oxc_linter/src/generated/rule_runner_impls.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading