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
9 changes: 9 additions & 0 deletions crates/oxc_linter/src/rules/eslint/no_unused_vars/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,15 @@ impl NoUnusedVars {
return true;
}

let node_id = symbol.declaration().id();
if flags.intersects(SymbolFlags::FunctionScopedVariable)
&& let AstKind::FormalParameters(formal_parameters) =
symbol.nodes().parent_node(node_id).kind()
&& formal_parameters.kind.is_signature()
{
return true;
}

// In some cases (e.g. "jsx": "react" in tsconfig.json), React imports
// get used in generated code. We don't have a way to detect
// "jsxPragmas" or whether TSX files are using "jsx": "react-jsx", so we
Expand Down
10 changes: 1 addition & 9 deletions crates/oxc_semantic/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,10 @@ impl<'a> Binder<'a> for BindingRestElement<'a> {
// Binds the FormalParameters's rest of a function or method.
fn bind(&self, builder: &mut SemanticBuilder) {
let parent_kind = builder.nodes.parent_kind(builder.current_node_id);
let AstKind::FormalParameters(parameters) = parent_kind else {
let AstKind::FormalParameters(_) = parent_kind else {
return;
};

if parameters.kind.is_signature() {
return;
}

let includes = SymbolFlags::FunctionScopedVariable;
let excludes =
SymbolFlags::FunctionScopedVariable | SymbolFlags::FunctionScopedVariableExcludes;
Expand All @@ -209,10 +205,6 @@ impl<'a> Binder<'a> for FormalParameter<'a> {
let parent_kind = builder.nodes.parent_kind(builder.current_node_id);
let AstKind::FormalParameters(parameters) = parent_kind else { unreachable!() };

if parameters.kind.is_signature() {
return;
}

let includes = SymbolFlags::FunctionScopedVariable;

let is_not_allowed_duplicate_parameters = matches!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/decorators/clas
"flags": "ScopeFlags(StrictMode)",
"id": 2,
"node": "TSFunctionType",
"symbols": []
"symbols": [
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 2,
"name": "param",
"node": "BindingRestElement",
"references": []
}
]
}
],
"flags": "ScopeFlags(StrictMode | Function)",
Expand Down Expand Up @@ -56,7 +64,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/decorators/clas
},
{
"flags": "SymbolFlags(Class)",
"id": 2,
"id": 3,
"name": "Foo",
"node": "Class(Foo)",
"references": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ScopeFlags(StrictMode)",
"id": 3,
"node": "TSFunctionType",
"symbols": []
"symbols": [
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 2,
"name": "k",
"node": "FormalParameter(k)",
"references": []
}
]
}
],
"flags": "ScopeFlags(StrictMode | TsConditional)",
Expand All @@ -23,7 +31,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"symbols": [
{
"flags": "SymbolFlags(TypeParameter)",
"id": 2,
"id": 3,
"name": "I",
"node": "TSTypeParameter(I)",
"references": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,29 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ScopeFlags(StrictMode)",
"id": 4,
"node": "TSFunctionType",
"symbols": []
"symbols": [
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 3,
"name": "arg2",
"node": "FormalParameter(arg2)",
"references": []
}
]
}
],
"flags": "ScopeFlags(StrictMode)",
"id": 3,
"node": "TSFunctionType",
"symbols": []
"symbols": [
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 2,
"name": "arg",
"node": "FormalParameter(arg)",
"references": []
}
]
}
],
"flags": "ScopeFlags(StrictMode | TsConditional)",
Expand All @@ -31,7 +47,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"symbols": [
{
"flags": "SymbolFlags(TypeParameter)",
"id": 2,
"id": 4,
"name": "I",
"node": "TSTypeParameter(I)",
"references": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ScopeFlags(StrictMode)",
"id": 3,
"node": "TSConstructorType",
"symbols": []
"symbols": [
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 3,
"name": "arg",
"node": "FormalParameter(arg)",
"references": []
}
]
}
],
"flags": "ScopeFlags(StrictMode)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"node_id": 16
}
]
},
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 3,
"name": "arg",
"node": "FormalParameter(arg)",
"references": []
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ScopeFlags(StrictMode)",
"id": 3,
"node": "TSConstructorType",
"symbols": []
"symbols": [
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 2,
"name": "arg",
"node": "FormalParameter(arg)",
"references": []
}
]
}
],
"flags": "ScopeFlags(StrictMode)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ScopeFlags(StrictMode)",
"id": 3,
"node": "TSFunctionType",
"symbols": []
"symbols": [
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 3,
"name": "arg",
"node": "FormalParameter(arg)",
"references": []
}
]
}
],
"flags": "ScopeFlags(StrictMode)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"node_id": 16
}
]
},
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 3,
"name": "arg",
"node": "FormalParameter(arg)",
"references": []
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ScopeFlags(StrictMode)",
"id": 3,
"node": "TSFunctionType",
"symbols": []
"symbols": [
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 2,
"name": "arg",
"node": "FormalParameter(arg)",
"references": []
}
]
}
],
"flags": "ScopeFlags(StrictMode)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,22 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ScopeFlags(StrictMode)",
"id": 2,
"node": "TSFunctionType",
"symbols": []
"symbols": [
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 2,
"name": "arg",
"node": "FormalParameter(arg)",
"references": [
{
"flags": "ReferenceFlags(Type)",
"id": 0,
"name": "arg",
"node_id": 15
}
]
}
]
}
],
"flags": "ScopeFlags(StrictMode)",
Expand All @@ -30,14 +45,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"id": 0,
"name": "arg",
"node": "VariableDeclarator(arg)",
"references": [
{
"flags": "ReferenceFlags(Type)",
"id": 0,
"name": "arg",
"node_id": 15
}
]
"references": []
},
{
"flags": "SymbolFlags(TypeAlias)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ScopeFlags(StrictMode)",
"id": 2,
"node": "TSFunctionType",
"symbols": []
"symbols": [
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 2,
"name": "a",
"node": "FormalParameter(<destructure>)",
"references": []
}
]
}
],
"flags": "ScopeFlags(StrictMode)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ScopeFlags(StrictMode)",
"id": 2,
"node": "TSFunctionType",
"symbols": []
"symbols": [
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 2,
"name": "a",
"node": "FormalParameter(<destructure>)",
"references": []
}
]
}
],
"flags": "ScopeFlags(StrictMode)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ScopeFlags(StrictMode)",
"id": 2,
"node": "TSFunctionType",
"symbols": []
"symbols": [
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 2,
"name": "a",
"node": "BindingRestElement",
"references": []
}
]
}
],
"flags": "ScopeFlags(StrictMode)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"node_id": 17
}
]
},
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 3,
"name": "arg",
"node": "FormalParameter(arg)",
"references": []
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ScopeFlags(StrictMode)",
"id": 3,
"node": "TSCallSignatureDeclaration",
"symbols": []
"symbols": [
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 2,
"name": "arg",
"node": "FormalParameter(arg)",
"references": []
}
]
}
],
"flags": "ScopeFlags(StrictMode)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"node_id": 17
}
]
},
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 3,
"name": "arg",
"node": "FormalParameter(arg)",
"references": []
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ScopeFlags(StrictMode)",
"id": 3,
"node": "TSConstructSignatureDeclaration",
"symbols": []
"symbols": [
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 2,
"name": "arg",
"node": "FormalParameter(arg)",
"references": []
}
]
}
],
"flags": "ScopeFlags(StrictMode)",
Expand Down
Loading
Loading