analyzer: Add LintRule.report* methods that don't use the word Lint
Since these can be used to report warnings, in analyzer plugins, we need
to rename them before moving them to be in the public API.
* reportLint -> reportAtNode
* reportLintForOffset -> reportAtOffset
* reportLintForToken -> reportAtToken
* reportPubLint -> reportAtPubNode
After landing these replacements, can start updating call sites and
removing the old names.
based on naming in: https://docs.google.com/document/d/12keEm32bCp8e1SpUM-25RZsuhPED3CkJzlRof4AiEF4/edit?resourcekey=0-b8hNBIXx4fSuubCzQxNbuw&tab=t.0#heading=h.d3j522v1l734
Change-Id: Icdbd43ae9a83b997901125ee286efb0b0745af71
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/424561
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/lint/linter.dart b/pkg/analyzer/lib/src/lint/linter.dart
index 91e606e..5dba1ac 100644
--- a/pkg/analyzer/lib/src/lint/linter.dart
+++ b/pkg/analyzer/lib/src/lint/linter.dart
@@ -245,7 +245,12 @@
LinterContext context,
) {}
- void reportLint(
+ /// Reports a diagnostic at [node] with message [arguments] and
+ /// [contextMessages].
+ ///
+ /// The error reported is either [errorCode] if that is passed in, otherwise
+ /// [lintCode].
+ void reportAtNode(
AstNode? node, {
List<Object> arguments = const [],
List<DiagnosticMessage>? contextMessages,
@@ -261,7 +266,12 @@
}
}
- void reportLintForOffset(
+ /// Reports a diagnostic at [offset], with [length], with message [arguments]
+ /// and [contextMessages].
+ ///
+ /// The error reported is either [errorCode] if that is passed in, otherwise
+ /// [lintCode].
+ void reportAtOffset(
int offset,
int length, {
List<Object> arguments = const [],
@@ -277,23 +287,12 @@
);
}
- void reportLintForToken(
- Token token, {
- List<Object> arguments = const [],
- List<DiagnosticMessage>? contextMessages,
- ErrorCode? errorCode,
- }) {
- if (!token.isSynthetic) {
- reporter.atToken(
- token,
- errorCode ?? lintCode,
- arguments: arguments,
- contextMessages: contextMessages,
- );
- }
- }
-
- void reportPubLint(
+ /// Reports a diagnostic at Pubspec [node], with message [arguments] and
+ /// [contextMessages].
+ ///
+ /// The error reported is either [errorCode] if that is passed in, otherwise
+ /// [lintCode].
+ void reportAtPubNode(
PSNode node, {
List<Object> arguments = const [],
List<DiagnosticMessage> contextMessages = const [],
@@ -310,6 +309,81 @@
);
reporter.reportError(error);
}
+
+ /// Reports a diagnostic at [token], with message [arguments] and
+ /// [contextMessages].
+ ///
+ /// The error reported is either [errorCode] if that is passed in, otherwise
+ /// [lintCode].
+ void reportAtToken(
+ Token token, {
+ List<Object> arguments = const [],
+ List<DiagnosticMessage>? contextMessages,
+ ErrorCode? errorCode,
+ }) {
+ if (!token.isSynthetic) {
+ reporter.atToken(
+ token,
+ errorCode ?? lintCode,
+ arguments: arguments,
+ contextMessages: contextMessages,
+ );
+ }
+ }
+
+ // TODO(srawlins): Deprecate this in favor of [reportNode].
+ void reportLint(
+ AstNode? node, {
+ List<Object> arguments = const [],
+ List<DiagnosticMessage>? contextMessages,
+ ErrorCode? errorCode,
+ }) => reportAtNode(
+ node,
+ arguments: arguments,
+ contextMessages: contextMessages,
+ errorCode: errorCode,
+ );
+
+ // TODO(srawlins): Deprecate this in favor of [reportOffset].
+ void reportLintForOffset(
+ int offset,
+ int length, {
+ List<Object> arguments = const [],
+ List<DiagnosticMessage>? contextMessages,
+ ErrorCode? errorCode,
+ }) => reportAtOffset(
+ offset,
+ length,
+ arguments: arguments,
+ contextMessages: contextMessages,
+ errorCode: errorCode,
+ );
+
+ // TODO(srawlins): Deprecate this in favor of [reportToken].
+ void reportLintForToken(
+ Token token, {
+ List<Object> arguments = const [],
+ List<DiagnosticMessage>? contextMessages,
+ ErrorCode? errorCode,
+ }) => reportAtToken(
+ token,
+ arguments: arguments,
+ contextMessages: contextMessages,
+ errorCode: errorCode,
+ );
+
+ // TODO(srawlins): Deprecate this in favor of [reportPubNode].
+ void reportPubLint(
+ PSNode node, {
+ List<Object> arguments = const [],
+ List<DiagnosticMessage> contextMessages = const [],
+ ErrorCode? errorCode,
+ }) => reportAtPubNode(
+ node,
+ arguments: arguments,
+ contextMessages: contextMessages,
+ errorCode: errorCode,
+ );
}
/// Provides access to information needed by lint rules that is not available