Skip to content

Commit 26641af

Browse files
srawlinsCommit Queue
authored and
Commit Queue
committed
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 <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 1dd93dd commit 26641af

File tree

1 file changed

+89
-15
lines changed

1 file changed

+89
-15
lines changed

pkg/analyzer/lib/src/lint/linter.dart

Lines changed: 89 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,12 @@ abstract class LintRule {
245245
LinterContext context,
246246
) {}
247247

248-
void reportLint(
248+
/// Reports a diagnostic at [node] with message [arguments] and
249+
/// [contextMessages].
250+
///
251+
/// The error reported is either [errorCode] if that is passed in, otherwise
252+
/// [lintCode].
253+
void reportAtNode(
249254
AstNode? node, {
250255
List<Object> arguments = const [],
251256
List<DiagnosticMessage>? contextMessages,
@@ -261,7 +266,12 @@ abstract class LintRule {
261266
}
262267
}
263268

264-
void reportLintForOffset(
269+
/// Reports a diagnostic at [offset], with [length], with message [arguments]
270+
/// and [contextMessages].
271+
///
272+
/// The error reported is either [errorCode] if that is passed in, otherwise
273+
/// [lintCode].
274+
void reportAtOffset(
265275
int offset,
266276
int length, {
267277
List<Object> arguments = const [],
@@ -277,7 +287,35 @@ abstract class LintRule {
277287
);
278288
}
279289

280-
void reportLintForToken(
290+
/// Reports a diagnostic at Pubspec [node], with message [arguments] and
291+
/// [contextMessages].
292+
///
293+
/// The error reported is either [errorCode] if that is passed in, otherwise
294+
/// [lintCode].
295+
void reportAtPubNode(
296+
PSNode node, {
297+
List<Object> arguments = const [],
298+
List<DiagnosticMessage> contextMessages = const [],
299+
ErrorCode? errorCode,
300+
}) {
301+
// Cache error and location info for creating `AnalysisErrorInfo`s.
302+
var error = AnalysisError.tmp(
303+
source: node.source,
304+
offset: node.span.start.offset,
305+
length: node.span.length,
306+
errorCode: errorCode ?? lintCode,
307+
arguments: arguments,
308+
contextMessages: contextMessages,
309+
);
310+
reporter.reportError(error);
311+
}
312+
313+
/// Reports a diagnostic at [token], with message [arguments] and
314+
/// [contextMessages].
315+
///
316+
/// The error reported is either [errorCode] if that is passed in, otherwise
317+
/// [lintCode].
318+
void reportAtToken(
281319
Token token, {
282320
List<Object> arguments = const [],
283321
List<DiagnosticMessage>? contextMessages,
@@ -293,23 +331,59 @@ abstract class LintRule {
293331
}
294332
}
295333

334+
// TODO(srawlins): Deprecate this in favor of [reportNode].
335+
void reportLint(
336+
AstNode? node, {
337+
List<Object> arguments = const [],
338+
List<DiagnosticMessage>? contextMessages,
339+
ErrorCode? errorCode,
340+
}) => reportAtNode(
341+
node,
342+
arguments: arguments,
343+
contextMessages: contextMessages,
344+
errorCode: errorCode,
345+
);
346+
347+
// TODO(srawlins): Deprecate this in favor of [reportOffset].
348+
void reportLintForOffset(
349+
int offset,
350+
int length, {
351+
List<Object> arguments = const [],
352+
List<DiagnosticMessage>? contextMessages,
353+
ErrorCode? errorCode,
354+
}) => reportAtOffset(
355+
offset,
356+
length,
357+
arguments: arguments,
358+
contextMessages: contextMessages,
359+
errorCode: errorCode,
360+
);
361+
362+
// TODO(srawlins): Deprecate this in favor of [reportToken].
363+
void reportLintForToken(
364+
Token token, {
365+
List<Object> arguments = const [],
366+
List<DiagnosticMessage>? contextMessages,
367+
ErrorCode? errorCode,
368+
}) => reportAtToken(
369+
token,
370+
arguments: arguments,
371+
contextMessages: contextMessages,
372+
errorCode: errorCode,
373+
);
374+
375+
// TODO(srawlins): Deprecate this in favor of [reportPubNode].
296376
void reportPubLint(
297377
PSNode node, {
298378
List<Object> arguments = const [],
299379
List<DiagnosticMessage> contextMessages = const [],
300380
ErrorCode? errorCode,
301-
}) {
302-
// Cache error and location info for creating `AnalysisErrorInfo`s.
303-
var error = AnalysisError.tmp(
304-
source: node.source,
305-
offset: node.span.start.offset,
306-
length: node.span.length,
307-
errorCode: errorCode ?? lintCode,
308-
arguments: arguments,
309-
contextMessages: contextMessages,
310-
);
311-
reporter.reportError(error);
312-
}
381+
}) => reportAtPubNode(
382+
node,
383+
arguments: arguments,
384+
contextMessages: contextMessages,
385+
errorCode: errorCode,
386+
);
313387
}
314388

315389
/// Provides access to information needed by lint rules that is not available

0 commit comments

Comments
 (0)