Skip to content

Commit 1ce5b15

Browse files
srawlinsCommit Queue
authored andcommitted
DAS plugins: Update docs for new public names
This change highlights how all of the necessary imports are now public! From here, forward, we are guarded by analyzer's public API rules. Change-Id: I71a7f928fc5913df846aa6253cd880719b4cd726 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439342 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 119e128 commit 1ce5b15

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

pkg/analysis_server_plugin/doc/writing_rules.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ various syntax tree nodes that the visitor class needs to visit. Let's see an
1717
example:
1818

1919
```dart
20+
import 'package:analyzer/analysis_rule/analysis_rule.dart';
21+
import 'package:analyzer/analysis_rule/rule_context.dart';
22+
import 'package:analyzer/analysis_rule/rule_visitor_registry.dart';
2023
import 'package:analyzer/dart/ast/ast.dart';
21-
import 'package:analyzer/src/dart/error/lint_codes.dart';
22-
import 'package:analyzer/src/lint/linter.dart';
24+
import 'package:analyzer/error/error.dart';
2325
2426
class MyRule extends AnalysisRule {
2527
static const LintCode code = LintCode(
@@ -39,7 +41,7 @@ class MyRule extends AnalysisRule {
3941
4042
@override
4143
void registerNodeProcessors(
42-
NodeLintRegistry registry, LinterContext context) {
44+
RuleVisitorRegistry registry, RuleContext context) {
4345
var visitor = _Visitor(this, context);
4446
registry.addAwaitExpression(this, visitor);
4547
}
@@ -75,13 +77,13 @@ Let's look at each declaration individually:
7577
a [Dart syntax tree][] (we see how the visitor is defined in "The visitor
7678
class," below). This visitor is typically named `_Visitor`. This visitor
7779
class must be instantiated once in this method. Typically, the instance of
78-
the rule class (`this`) and a `LinterContext` object (described below) are
80+
the rule class (`this`) and a `RuleContext` object (described below) are
7981
passed to the visitor constructor.
8082

8183
In order for such a visitor's various 'visit' methods to be called, we need
82-
to register them, in a `NodeLintRegistry`. Each 'visit' method found on
83-
`SimpleAstVisitor` has a corresponding 'add' method in the `NodeLintRegistry`
84-
class.
84+
to register them, in a `RuleVisitorRegistry`. Each 'visit' method found on
85+
`SimpleAstVisitor` has a corresponding 'add' method in the
86+
`RuleVisitorRegistry` class.
8587

8688
[Dart syntax tree]: https://github.com/dart-lang/sdk/blob/main/pkg/analyzer/doc/tutorial/ast.md
8789

@@ -95,21 +97,22 @@ implementation. Let's look at a quick example:
9597
[SimpleAstVisitor docs]: https://github.com/dart-lang/sdk/blob/main/pkg/analyzer/lib/dart/ast/visitor.dart#L1841
9698

9799
```dart
100+
import 'package:analyzer/analysis_rule/analysis_rule.dart';
101+
import 'package:analyzer/analysis_rule/rule_context.dart';
98102
import 'package:analyzer/dart/ast/ast.dart';
99103
import 'package:analyzer/dart/ast/visitor.dart';
100-
import 'package:analyzer/src/lint/linter.dart';
101104
102105
class _Visitor extends SimpleAstVisitor<void> {
103-
final LintRule rule;
106+
final AnalysisRule rule;
104107
105-
final LinterContext context;
108+
final RuleContext context;
106109
107110
_Visitor(this.rule, this.context);
108111
109112
@override
110113
void visitAwaitExpression(AwaitExpression node) {
111114
if (context.isInLibDir) {
112-
rule.reportLint(node);
115+
rule.reportAtNode(node);
113116
}
114117
}
115118
}
@@ -122,15 +125,15 @@ Let's look at each declaration individually:
122125
tree visitors, using one directly in a rule can result in poor performance
123126
and unexpected behavior. The type argument on `SimpleAstVisitor` is not
124127
important, as 'visit' return values are not used, so `void` is appropriate.
125-
* `final LintRule rule` - The rule is the object to which we can report
128+
* `final AnalysisRule rule` - The rule is the object to which we can report
126129
diagnostics (lints or warnings). Several methods are provided, all starting
127-
with `reportLint`. The different methods allow for different ranges of text
128-
to be highlighted.
129-
* `final LinterContext context` - The LinterContext object provides various
130+
with `reportAt`. The different methods allow for different ranges of text to
131+
be highlighted.
132+
* `final RuleContext context` - The RuleContext object provides various
130133
information about the library being analyzed. In this example, we make use of
131134
a `isInLibDir` utility.
132-
* `_Visitor(...)` - Often the constructor just initializes the LintRule and
133-
LinterContext fields. Other information can be initialized as well.
135+
* `_Visitor(...)` - Often the constructor just initializes the AnalysisRule and
136+
RuleContext fields. Other information can be initialized as well.
134137
* `void visitAwaitExpression(AwaitExpression node)` - The main component of the
135138
`_Visitor` class is the 'visit' methods. In this case, `visitAwaitExpression`
136139
is invoked for each 'await expression' found in the source code under

0 commit comments

Comments
 (0)