Skip to content

Commit

Permalink
Take into account the constructor initializer in the avoid_unused_par…
Browse files Browse the repository at this point in the history
…ameters rule (#67)

Co-authored-by: vladimir-beloded <[email protected]>
  • Loading branch information
solid-vovabeloded and vova-beloded-solid committed Nov 10, 2023
1 parent b8e7659 commit 069ef6c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class AvoidUnusedParametersVisitor extends RecursiveAstVisitor<void> {
_getUnusedParameters(
node.body,
parameters.parameters,
initializers: node.initializers,
).whereNot(nameConsistsOfUnderscoresOnly),
);
}
Expand Down Expand Up @@ -104,11 +105,13 @@ class AvoidUnusedParametersVisitor extends RecursiveAstVisitor<void> {

Set<FormalParameter> _getUnusedParameters(
AstNode body,
Iterable<FormalParameter> parameters,
) {
Iterable<FormalParameter> parameters, {
NodeList<AstNode>? initializers,
}) {
final result = <FormalParameter>{};
final visitor = _IdentifiersVisitor();
body.visitChildren(visitor);
initializers?.accept(visitor);

final allIdentifierElements = visitor.elements;

Expand Down
10 changes: 10 additions & 0 deletions lint_test/avoid_unused_parameters_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,13 @@ class TestWidget extends StatelessWidget {
return const Placeholder();
}
}

class UsingConstructorParameterInInitializer {
final int _value;

UsingConstructorParameterInInitializer(int value) : _value = value;

void printValue() {
print(_value);
}
}

0 comments on commit 069ef6c

Please sign in to comment.