Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Side by Side Diff: lib/src/rules/comment_references.dart

Issue 1978603003: Lint to detect dangling identifiers in docs (#240). (Closed) Base URL: https://github.com/dart-lang/linter.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/rules.dart ('k') | test/rule_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « lib/src/rules.dart ('k') | test/rule_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698