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 @@ -43,6 +43,7 @@
"typescript/prefer-regexp-exec": "error",
"typescript/prefer-reduce-type-parameter": "error",
"typescript/prefer-return-this-type": "error",
"typescript/prefer-string-starts-ends-with": "error",
"typescript/promise-function-async": "error",
"typescript/related-getter-setter-pairs": "error",
"typescript/require-array-sort-compare": "error",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Examples of incorrect code for prefer-string-starts-ends-with rule

function startsCase(s: string): boolean {
return s[0] === 'a';
}

function endsCase(s: string): boolean {
return s.slice(-3) === 'bar';
}
6 changes: 6 additions & 0 deletions apps/oxlint/fixtures/tsgolint_rule_options/.oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@
"onlyInlineLambdas": true
}
],
"typescript/prefer-string-starts-ends-with": [
"error",
{
"allowSingleElementEquality": "always"
}
],
"typescript/only-throw-error": [
"error",
{
Expand Down
7 changes: 7 additions & 0 deletions apps/oxlint/fixtures/tsgolint_rule_options/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ class PreferReadonlyOptionExample {
}
}

// Test prefer-string-starts-ends-with with allowSingleElementEquality option
declare const boundaryText: string;
// This should NOT error because single element equality is allowed
const boundaryCharMatch = boundaryText[0] === 'a';
// This SHOULD error because startsWith is preferred here
const boundarySliceMatch = boundaryText.slice(0, 3) === 'foo';

// 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 67 errors.
Finished in <variable>ms on 54 files with 53 rules using 1 threads.
Found 0 warnings and 69 errors.
Finished in <variable>ms on 55 files with 54 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 54 files with 1 rules using 1 threads.
Finished in <variable>ms on 55 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 53 rules using 1 threads.
Finished in <variable>ms on 1 file with 54 rules using 1 threads.
----------
CLI result: LintFoundErrors
----------
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,22 @@ working directory: fixtures/tsgolint
4 | this.value = value;
`----

x typescript-eslint(prefer-string-starts-ends-with): Use 'String#startsWith' method instead.
,-[prefer-string-starts-ends-with.ts:4:10]
3 | function startsCase(s: string): boolean {
4 | return s[0] === 'a';
: ^^^^^^^^^^^^
5 | }
`----

x typescript-eslint(prefer-string-starts-ends-with): Use 'String#endsWith' method instead.
,-[prefer-string-starts-ends-with.ts:8:10]
7 | function endsCase(s: string): boolean {
8 | return s.slice(-3) === 'bar';
: ^^^^^^^^^^^^^^^^^^^^^
9 | }
`----

x typescript-eslint(promise-function-async): Functions that return promises must be async.
,-[promise-function-async.ts:2:1]
1 | declare function fetch(url: string): Promise<Response>;
Expand Down Expand Up @@ -526,8 +542,8 @@ working directory: fixtures/tsgolint
`----
help: If your function does not access `this`, you can annotate it with `this: void`, or consider using an arrow function instead.

Found 0 warnings and 67 errors.
Finished in <variable>ms on 54 files with 53 rules using 1 threads.
Found 0 warnings and 69 errors.
Finished in <variable>ms on 55 files with 54 rules using 1 threads.
----------
CLI result: LintFoundErrors
----------
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,16 @@ working directory: fixtures/tsgolint_rule_options
108 | getValue() {
`----

Found 0 warnings and 10 errors.
Finished in <variable>ms on 1 file with 12 rules using 1 threads.
x typescript-eslint(prefer-string-starts-ends-with): Use 'String#startsWith' method instead.
,-[test.ts:118:28]
117 | // This SHOULD error because startsWith is preferred here
118 | const boundarySliceMatch = boundaryText.slice(0, 3) === 'foo';
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
119 |
`----

Found 0 warnings and 11 errors.
Finished in <variable>ms on 1 file with 13 rules using 1 threads.
----------
CLI result: LintFoundErrors
----------
7 changes: 7 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.

50 changes: 49 additions & 1 deletion crates/oxc_linter/src/generated/rules_enum.rs

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

1 change: 1 addition & 0 deletions crates/oxc_linter/src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ pub(crate) mod typescript {
pub mod prefer_reduce_type_parameter;
pub mod prefer_regexp_exec;
pub mod prefer_return_this_type;
pub mod prefer_string_starts_ends_with;
pub mod prefer_ts_expect_error;
pub mod promise_function_async;
pub mod related_getter_setter_pairs;
Expand Down
Loading
Loading