@@ -7,8 +7,7 @@ import 'package:analyzer/error/error.dart';
77import 'package:riverpod_analyzer_utils/riverpod_analyzer_utils.dart' ;
88
99class OnlyUseKeepAliveInsideKeepAlive extends AnalysisRule {
10- OnlyUseKeepAliveInsideKeepAlive ()
11- : super (name: code.name, description: code.problemMessage);
10+ OnlyUseKeepAliveInsideKeepAlive () : super (name: code.name, description: code.problemMessage);
1211
1312 static const code = LintCode (
1413 'only_use_keep_alive_inside_keep_alive' ,
@@ -23,10 +22,7 @@ class OnlyUseKeepAliveInsideKeepAlive extends AnalysisRule {
2322 DiagnosticCode get diagnosticCode => code;
2423
2524 @override
26- void registerNodeProcessors (
27- RuleVisitorRegistry registry,
28- RuleContext context,
29- ) {
25+ void registerNodeProcessors (RuleVisitorRegistry registry, RuleContext context) {
3026 final visitor = _Visitor (this , context);
3127 registry.addMethodInvocation (this , visitor);
3228 }
@@ -42,15 +38,15 @@ class _Visitor extends SimpleAstVisitor<void> {
4238 void visitMethodInvocation (MethodInvocation node) {
4339 final refInvocation = node.refInvocation;
4440 if (refInvocation is ! RefDependencyInvocation ) return ;
41+ // Only check ref.watch and ref.listen, not ref.read
42+ if (refInvocation is RefReadInvocation ) return ;
4543
46- final dependencyElement =
47- refInvocation.listenable.provider? .providerElement;
44+ final dependencyElement = refInvocation.listenable.provider? .providerElement;
4845 // This only applies if the watched provider is a generated one.
4946 if (dependencyElement is ! GeneratorProviderDeclarationElement ) return ;
5047 if (! dependencyElement.isAutoDispose) return ;
5148
52- final provider =
53- node.thisOrAncestorOfType <NamedCompilationUnitMember >()? .provider;
49+ final provider = node.thisOrAncestorOfType <NamedCompilationUnitMember >()? .provider;
5450 if (provider == null ) return ;
5551
5652 // The enclosing provider is "autoDispose", so it is allowed to use other "autoDispose" providers
0 commit comments