@@ -245,7 +245,12 @@ abstract class LintRule {
245
245
LinterContext context,
246
246
) {}
247
247
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 (
249
254
AstNode ? node, {
250
255
List <Object > arguments = const [],
251
256
List <DiagnosticMessage >? contextMessages,
@@ -261,7 +266,12 @@ abstract class LintRule {
261
266
}
262
267
}
263
268
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 (
265
275
int offset,
266
276
int length, {
267
277
List <Object > arguments = const [],
@@ -277,7 +287,35 @@ abstract class LintRule {
277
287
);
278
288
}
279
289
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 (
281
319
Token token, {
282
320
List <Object > arguments = const [],
283
321
List <DiagnosticMessage >? contextMessages,
@@ -293,23 +331,59 @@ abstract class LintRule {
293
331
}
294
332
}
295
333
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].
296
376
void reportPubLint (
297
377
PSNode node, {
298
378
List <Object > arguments = const [],
299
379
List <DiagnosticMessage > contextMessages = const [],
300
380
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
+ );
313
387
}
314
388
315
389
/// Provides access to information needed by lint rules that is not available
0 commit comments