OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library linter.src.rules.comment_references; | |
6 | |
7 import 'package:analyzer/dart/ast/ast.dart'; | |
8 import 'package:analyzer/dart/ast/visitor.dart'; | |
9 import 'package:linter/src/linter.dart'; | |
10 | |
11 const desc = r'Only reference in-scope identifers in doc comments.'; | |
12 | |
13 const details = r''' | |
14 **DO** reference only in-scope identifers in doc comments. | |
15 | |
16 If you surround things like variable, method, or type names in square brackets, | |
17 then [dartdoc](https://www.dartlang.org/effective-dart/documentation/) will look | |
18 up the name and link to its docs. For this all to work, ensure that all | |
19 identifiers in docs wrapped in brackets are in-scope. | |
Brian Wilkerson
2016/05/13 14:37:17
nit: 'in-scope' --> 'in scope'
pquitslund
2016/05/13 21:13:16
Done.
| |
20 | |
21 For example, | |
22 | |
23 **GOOD:** | |
24 ``` | |
25 /// Return the larger of [a] or [b]. | |
26 int max_int(int a, int b) { ... } | |
27 ``` | |
28 | |
29 On the other hand, assuming `outOfScopeId` is out of scope: | |
30 | |
31 **BAD:** | |
32 ``` | |
33 void f(int outOfScopeId) { ... } | |
scheglov
2016/05/12 21:08:46
Should there be a documentation comment that refer
pquitslund
2016/05/13 21:13:15
Acknowledged.
| |
34 ``` | |
35 '''; | |
36 | |
37 class CommentReferences extends LintRule { | |
38 CommentReferences() | |
39 : super( | |
40 name: 'comment_references', | |
41 description: desc, | |
42 details: details, | |
43 group: Group.errors); | |
44 | |
45 @override | |
46 AstVisitor getVisitor() => new Visitor(this); | |
47 } | |
48 | |
49 class Visitor extends SimpleAstVisitor { | |
50 final LintRule rule; | |
51 Visitor(this.rule); | |
52 | |
53 @override | |
54 visitCommentReference(CommentReference node) { | |
55 Identifier identifier = node.identifier; | |
56 if (!identifier.isSynthetic && identifier.bestElement == null) { | |
57 rule.reportLint(identifier); | |
58 } | |
59 } | |
60 } | |
OLD | NEW |