Skip to content

Commit 93e6c0b

Browse files
authoredMar 28, 2025··
refactor(linter): use FormalParameter::has_modifier to detect parameter properties (#10097)
By using this function, the code is shorter and the missing check for the `override` modifier is added. This PR is the result of splitting #10081 into smaller PRs.
1 parent 2c80858 commit 93e6c0b

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed
 

Diff for: ‎crates/oxc_linter/src/rules/eslint/no_useless_constructor.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use oxc_ast::{
22
AstKind,
33
ast::{
44
Argument, BindingPattern, BindingPatternKind, BindingRestElement, CallExpression,
5-
Expression, FormalParameters, FunctionBody, MethodDefinition, Statement, TSAccessibility,
5+
Expression, FormalParameter, FormalParameters, FunctionBody, MethodDefinition, Statement,
6+
TSAccessibility,
67
},
78
};
89
use oxc_diagnostics::OxcDiagnostic;
@@ -151,13 +152,7 @@ fn lint_empty_constructor<'a>(
151152

152153
// allow constructors with access modifiers since they actually declare
153154
// class members
154-
if constructor
155-
.value
156-
.params
157-
.items
158-
.iter()
159-
.any(|param| param.accessibility.is_some() || param.readonly)
160-
{
155+
if constructor.value.params.items.iter().any(FormalParameter::has_modifier) {
161156
return;
162157
}
163158

Diff for: ‎crates/oxc_linter/src/rules/typescript/no_unnecessary_parameter_property_assignment.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,8 @@ impl Rule for NoUnnecessaryParameterPropertyAssignment {
6666
return;
6767
}
6868

69-
let parameter_properties: Vec<_> = method
70-
.value
71-
.params
72-
.items
73-
.iter()
74-
.filter(|param| {
75-
// TypeScript offers special syntax for turning a constructor parameter into a class property with the same name and value.
76-
// These are called parameter properties and are created by prefixing a constructor argument with one of the visibility modifiers public, private, protected, or readonly
77-
// https://www.typescriptlang.org/docs/handbook/2/classes.html#parameter-properties
78-
param.accessibility.is_some() || param.readonly
79-
})
80-
.collect();
69+
let parameter_properties: Vec<_> =
70+
method.value.params.items.iter().filter(|param| param.has_modifier()).collect();
8171

8272
if parameter_properties.is_empty() {
8373
return;

0 commit comments

Comments
 (0)
Please sign in to comment.