diff --git a/lib/lints/avoid_unused_parameters/avoid_unused_parameters_visitor.dart b/lib/lints/avoid_unused_parameters/avoid_unused_parameters_visitor.dart index 21760e13..7283cad2 100644 --- a/lib/lints/avoid_unused_parameters/avoid_unused_parameters_visitor.dart +++ b/lib/lints/avoid_unused_parameters/avoid_unused_parameters_visitor.dart @@ -53,6 +53,7 @@ class AvoidUnusedParametersVisitor extends RecursiveAstVisitor { _getUnusedParameters( node.body, parameters.parameters, + initializers: node.initializers, ).whereNot(nameConsistsOfUnderscoresOnly), ); } @@ -104,11 +105,13 @@ class AvoidUnusedParametersVisitor extends RecursiveAstVisitor { Set _getUnusedParameters( AstNode body, - Iterable parameters, - ) { + Iterable parameters, { + NodeList? initializers, + }) { final result = {}; final visitor = _IdentifiersVisitor(); body.visitChildren(visitor); + initializers?.accept(visitor); final allIdentifierElements = visitor.elements; diff --git a/lint_test/avoid_unused_parameters_test.dart b/lint_test/avoid_unused_parameters_test.dart index e54d6499..4d3950f1 100644 --- a/lint_test/avoid_unused_parameters_test.dart +++ b/lint_test/avoid_unused_parameters_test.dart @@ -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); + } +}