From bc3e0ad5a8211ea1bb36b4f4af058fa35d4c251e Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Fri, 16 May 2025 20:17:16 -0700 Subject: [PATCH] Remove deprecated elements of AnalysisRule * All callers are migrated off of `AbstractAnalysisRule.lintCodes` and `.reporter`. * All callers are migrated off of `AnalysisRule.lintCode`. Change-Id: I4123250c33ff1d0a488bd4457cfe5fc13160e829 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429121 Reviewed-by: Konstantin Shcheglov Commit-Queue: Samuel Rawlins --- pkg/analyzer/lib/src/lint/linter.dart | 29 +++++++-------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/pkg/analyzer/lib/src/lint/linter.dart b/pkg/analyzer/lib/src/lint/linter.dart index 052d0113908..665c94cf06d 100644 --- a/pkg/analyzer/lib/src/lint/linter.dart +++ b/pkg/analyzer/lib/src/lint/linter.dart @@ -59,24 +59,13 @@ sealed class AbstractAnalysisRule { /// A list of incompatible rule ids. List get incompatibleRules => const []; - /// The lint codes associated with this analysis rule. - @Deprecated("Use 'diagnosticCodes' instead.") - List get lintCodes => diagnosticCodes; - /// Returns a visitor that visits a [Pubspec] to perform analysis. /// /// Diagnostics are reported via this [LintRule]'s error [reporter]. PubspecVisitor? get pubspecVisitor => null; - @protected - // Protected so that analysis rule visitors do not access this directly. - // TODO(srawlins): With the new availability of an ErrorReporter on - // LinterContextUnit, we should probably remove this reporter. But whatever - // the new API would be is not yet decided. It might also change with the - // notion of post-processing lint rules that have access to all unit - // reporters at once. - ErrorReporter get reporter => _reporter; - + /// Sets the [ErrorReporter] for the [CompilationUnit] currently being + /// visited. set reporter(ErrorReporter value) => _reporter = value; /// Registers node processors in the given [registry]. @@ -95,7 +84,7 @@ sealed class AbstractAnalysisRule { required DiagnosticCode diagnosticCode, }) { if (node != null && !node.isSynthetic) { - reporter.atNode( + _reporter.atNode( node, diagnosticCode, arguments: arguments, @@ -111,7 +100,7 @@ sealed class AbstractAnalysisRule { List arguments = const [], List? contextMessages, }) { - reporter.atOffset( + _reporter.atOffset( offset: offset, length: length, errorCode: diagnosticCode, @@ -135,7 +124,7 @@ sealed class AbstractAnalysisRule { arguments: arguments, contextMessages: contextMessages, ); - reporter.reportError(diagnostic); + _reporter.reportError(diagnostic); } void _reportAtToken( @@ -145,7 +134,7 @@ sealed class AbstractAnalysisRule { List? contextMessages, }) { if (!token.isSynthetic) { - reporter.atToken( + _reporter.atToken( token, diagnosticCode, arguments: arguments, @@ -166,10 +155,6 @@ abstract class AnalysisRule extends AbstractAnalysisRule { @override List get diagnosticCodes => [diagnosticCode]; - /// The code to report for a violation. - @Deprecated("Use 'diagnosticCode' instead.") - DiagnosticCode get lintCode => diagnosticCode; - /// Reports a diagnostic at [node] with message [arguments] and /// [contextMessages]. void reportAtNode( @@ -436,7 +421,7 @@ abstract class MultiAnalysisRule extends AbstractAnalysisRule { arguments: arguments, contextMessages: contextMessages, ); - reporter.reportError(error); + _reporter.reportError(error); } /// Reports [errorCode] at [token], with message [arguments] and