Skip to content

Commit c2fe957

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: Swap LintRule and typedef AnalysisRule
Work towards #50986 Change-Id: Ie9b2130d48929f8407a2ef20e23576699ecea2b9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428223 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 3117e40 commit c2fe957

File tree

1 file changed

+68
-70
lines changed

1 file changed

+68
-70
lines changed

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

Lines changed: 68 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ export 'package:analyzer/src/lint/state.dart'
2626

2727
/// Describes an [AbstractAnalysisRule] which reports diagnostics using exactly
2828
/// one [DiagnosticCode].
29-
typedef AnalysisRule = LintRule;
30-
31-
//typedef MultiAnalysisRule = MultiLintRule;
29+
typedef LintRule = AnalysisRule;
3230

3331
/// Describes a static analysis rule, either a lint rule (which must be enabled
3432
/// via analysis options) or a warning rule (which is enabled by default).
@@ -155,8 +153,73 @@ sealed class AbstractAnalysisRule {
155153
}
156154
}
157155

158-
/// Provides access to information needed by lint rules that is not available
159-
/// from AST nodes or the element model.
156+
/// Describes an [AbstractAnalysisRule] which reports exactly one type of
157+
/// diagnostic (one [DiagnosticCode]).
158+
abstract class AnalysisRule extends AbstractAnalysisRule {
159+
AnalysisRule({required super.name, required super.description, super.state});
160+
161+
LintCode get lintCode;
162+
163+
@override
164+
List<LintCode> get lintCodes => [lintCode];
165+
166+
/// Reports a diagnostic at [node] with message [arguments] and
167+
/// [contextMessages].
168+
void reportAtNode(
169+
AstNode? node, {
170+
List<Object> arguments = const [],
171+
List<DiagnosticMessage>? contextMessages,
172+
}) => _reportAtNode(
173+
node,
174+
diagnosticCode: lintCode,
175+
arguments: arguments,
176+
contextMessages: contextMessages,
177+
);
178+
179+
/// Reports a diagnostic at [offset], with [length], with message [arguments]
180+
/// and [contextMessages].
181+
void reportAtOffset(
182+
int offset,
183+
int length, {
184+
List<Object> arguments = const [],
185+
List<DiagnosticMessage>? contextMessages,
186+
}) => _reportAtOffset(
187+
offset,
188+
length,
189+
diagnosticCode: lintCode,
190+
arguments: arguments,
191+
contextMessages: contextMessages,
192+
);
193+
194+
/// Reports a diagnostic at Pubspec [node], with message [arguments] and
195+
/// [contextMessages].
196+
void reportAtPubNode(
197+
PSNode node, {
198+
List<Object> arguments = const [],
199+
List<DiagnosticMessage> contextMessages = const [],
200+
}) => _reportAtPubNode(
201+
node,
202+
errorCode: lintCode,
203+
arguments: arguments,
204+
contextMessages: contextMessages,
205+
);
206+
207+
/// Reports a diagnostic at [token], with message [arguments] and
208+
/// [contextMessages].
209+
void reportAtToken(
210+
Token token, {
211+
List<Object> arguments = const [],
212+
List<DiagnosticMessage>? contextMessages,
213+
}) => _reportAtToken(
214+
token,
215+
diagnosticCode: lintCode,
216+
arguments: arguments,
217+
contextMessages: contextMessages,
218+
);
219+
}
220+
221+
/// Provides access to information needed by analysis rules that is not
222+
/// available from AST nodes or the element model.
160223
abstract class LinterContext {
161224
/// The list of all compilation units that make up the library under analysis,
162225
/// including the defining compilation unit, all parts, and all augmentations.
@@ -303,71 +366,6 @@ final class LinterContextWithResolvedResults implements LinterContext {
303366
definingUnit.unit.declaredFragment!.element;
304367
}
305368

306-
/// Describes an [AbstractAnalysisRule] which reports exactly one type of
307-
/// diagnostic (one [DiagnosticCode]).
308-
abstract class LintRule extends AbstractAnalysisRule {
309-
LintRule({required super.name, required super.description, super.state});
310-
311-
LintCode get lintCode;
312-
313-
@override
314-
List<LintCode> get lintCodes => [lintCode];
315-
316-
/// Reports a diagnostic at [node] with message [arguments] and
317-
/// [contextMessages].
318-
void reportAtNode(
319-
AstNode? node, {
320-
List<Object> arguments = const [],
321-
List<DiagnosticMessage>? contextMessages,
322-
}) => _reportAtNode(
323-
node,
324-
diagnosticCode: lintCode,
325-
arguments: arguments,
326-
contextMessages: contextMessages,
327-
);
328-
329-
/// Reports a diagnostic at [offset], with [length], with message [arguments]
330-
/// and [contextMessages].
331-
void reportAtOffset(
332-
int offset,
333-
int length, {
334-
List<Object> arguments = const [],
335-
List<DiagnosticMessage>? contextMessages,
336-
}) => _reportAtOffset(
337-
offset,
338-
length,
339-
diagnosticCode: lintCode,
340-
arguments: arguments,
341-
contextMessages: contextMessages,
342-
);
343-
344-
/// Reports a diagnostic at Pubspec [node], with message [arguments] and
345-
/// [contextMessages].
346-
void reportAtPubNode(
347-
PSNode node, {
348-
List<Object> arguments = const [],
349-
List<DiagnosticMessage> contextMessages = const [],
350-
}) => _reportAtPubNode(
351-
node,
352-
errorCode: lintCode,
353-
arguments: arguments,
354-
contextMessages: contextMessages,
355-
);
356-
357-
/// Reports a diagnostic at [token], with message [arguments] and
358-
/// [contextMessages].
359-
void reportAtToken(
360-
Token token, {
361-
List<Object> arguments = const [],
362-
List<DiagnosticMessage>? contextMessages,
363-
}) => _reportAtToken(
364-
token,
365-
diagnosticCode: lintCode,
366-
arguments: arguments,
367-
contextMessages: contextMessages,
368-
);
369-
}
370-
371369
/// Provides access to information needed by lint rules that is not available
372370
/// from AST nodes or the element model.
373371
class LintRuleUnitContext {

0 commit comments

Comments
 (0)