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 @@ -24,6 +24,7 @@
"typescript/no-unnecessary-template-expression": "error",
"typescript/no-unnecessary-type-arguments": "error",
"typescript/no-unnecessary-type-assertion": "error",
"typescript/no-unnecessary-type-parameters": "error",
"typescript/no-unsafe-argument": "error",
"typescript/no-unsafe-assignment": "error",
"typescript/no-unsafe-call": "error",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Examples of incorrect code for no-unnecessary-type-parameters rule

function parseYAML<T>(input: string): T {
return input as any as T;
}
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 71 errors.
Finished in <variable>ms on 56 files with 55 rules using 1 threads.
Found 0 warnings and 74 errors.
Finished in <variable>ms on 57 files with 56 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 56 files with 1 rules using 1 threads.
Finished in <variable>ms on 57 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 55 rules using 1 threads.
Finished in <variable>ms on 1 file with 56 rules using 1 threads.
----------
CLI result: LintFoundErrors
----------
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,31 @@ working directory: fixtures/tsgolint
3 |
`----

x typescript-eslint(no-unnecessary-type-parameters): Type parameter T is used only once in the function signature.
,-[no-unnecessary-type-parameters.ts:3:20]
2 |
3 | function parseYAML<T>(input: string): T {
: ^ |
: | `-- This is the only usage of type parameter T in the signature.
4 | return input as any as T;
`----

x typescript-eslint(no-unsafe-type-assertion): Unsafe assertion to `any` detected: consider using a more specific type to ensure safety.
,-[no-unnecessary-type-parameters.ts:4:10]
3 | function parseYAML<T>(input: string): T {
4 | return input as any as T;
: ^^^^^^^^^^^^
5 | }
`----

x typescript-eslint(no-unsafe-type-assertion): Unsafe assertion from `any` detected: consider using type guards or a safer assertion.
,-[no-unnecessary-type-parameters.ts:4:10]
3 | function parseYAML<T>(input: string): T {
4 | return input as any as T;
: ^^^^^^^^^^^^^^^^^
5 | }
`----

x typescript-eslint(no-unsafe-argument): Unsafe argument of type any assigned to a parameter of type string.
,-[no-unsafe-argument.ts:3:13]
2 | function takesString(str: string): void {}
Expand Down Expand Up @@ -564,8 +589,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 71 errors.
Finished in <variable>ms on 56 files with 55 rules using 1 threads.
Found 0 warnings and 74 errors.
Finished in <variable>ms on 57 files with 56 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.

49 changes: 48 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 @@ -268,6 +268,7 @@ pub(crate) mod typescript {
pub mod no_unnecessary_type_arguments;
pub mod no_unnecessary_type_assertion;
pub mod no_unnecessary_type_constraint;
pub mod no_unnecessary_type_parameters;
pub mod no_unsafe_argument;
pub mod no_unsafe_assignment;
pub mod no_unsafe_call;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use oxc_macros::declare_oxc_lint;

use crate::rule::Rule;

#[derive(Debug, Default, Clone)]
pub struct NoUnnecessaryTypeParameters;

declare_oxc_lint!(
/// ### What it does
///
/// Disallow type parameters that are declared but not meaningfully used.
///
/// ### Why is this bad?
///
/// Unnecessary type parameters make signatures noisier and harder to understand, and they
/// often hide opportunities to simplify APIs.
///
/// ### Examples
///
/// Examples of **incorrect** code for this rule:
/// ```ts
/// function parseYAML<T>(input: string): T {
/// return input as any as T;
/// }
/// ```
///
/// Examples of **correct** code for this rule:
/// ```ts
/// function parseYAML(input: string): unknown {
/// return input;
/// }
///
/// function identity<T>(value: T): T {
/// return value;
/// }
/// ```
NoUnnecessaryTypeParameters(tsgolint),
typescript,
nursery,
);

impl Rule for NoUnnecessaryTypeParameters {}
Loading