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
fix(linter): use FormalParameter::has_modifier to detect parameter …
…properties
  • Loading branch information
ulrichstark committed Mar 28, 2025
commit 0a97221cbb5620679b33a936f73bcf1b66d773e4
11 changes: 3 additions & 8 deletions crates/oxc_linter/src/rules/eslint/no_useless_constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use oxc_ast::{
AstKind,
ast::{
Argument, BindingPattern, BindingPatternKind, BindingRestElement, CallExpression,
Expression, FormalParameters, FunctionBody, MethodDefinition, Statement, TSAccessibility,
Expression, FormalParameter, FormalParameters, FunctionBody, MethodDefinition, Statement,
TSAccessibility,
},
};
use oxc_diagnostics::OxcDiagnostic;
Expand Down Expand Up @@ -151,13 +152,7 @@ fn lint_empty_constructor<'a>(

// allow constructors with access modifiers since they actually declare
// class members
if constructor
.value
.params
.items
.iter()
.any(|param| param.accessibility.is_some() || param.readonly)
{
if constructor.value.params.items.iter().any(FormalParameter::has_modifier) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,8 @@ impl Rule for NoUnnecessaryParameterPropertyAssignment {
return;
}

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

if parameter_properties.is_empty() {
return;
Expand Down