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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/rules.dart ('k') | test/rule_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/rules/comment_references.dart
diff --git a/lib/src/rules/comment_references.dart b/lib/src/rules/comment_references.dart
new file mode 100644
index 0000000000000000000000000000000000000000..d0fae8313eb0932477e4c0e8322aed7beec34fa9
--- /dev/null
+++ b/lib/src/rules/comment_references.dart
@@ -0,0 +1,60 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library linter.src.rules.comment_references;
+
+import 'package:analyzer/dart/ast/ast.dart';
+import 'package:analyzer/dart/ast/visitor.dart';
+import 'package:linter/src/linter.dart';
+
+const desc = r'Only reference in-scope identifers in doc comments.';
+
+const details = r'''
+**DO** reference only in-scope identifers in doc comments.
+
+If you surround things like variable, method, or type names in square brackets,
+then [dartdoc](https://www.dartlang.org/effective-dart/documentation/) will look
+up the name and link to its docs. For this all to work, ensure that all
+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.
+
+For example,
+
+**GOOD:**
+```
+/// Return the larger of [a] or [b].
+int max_int(int a, int b) { ... }
+```
+
+On the other hand, assuming `outOfScopeId` is out of scope:
+
+**BAD:**
+```
+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.
+```
+''';
+
+class CommentReferences extends LintRule {
+ CommentReferences()
+ : super(
+ name: 'comment_references',
+ description: desc,
+ details: details,
+ group: Group.errors);
+
+ @override
+ AstVisitor getVisitor() => new Visitor(this);
+}
+
+class Visitor extends SimpleAstVisitor {
+ final LintRule rule;
+ Visitor(this.rule);
+
+ @override
+ visitCommentReference(CommentReference node) {
+ Identifier identifier = node.identifier;
+ if (!identifier.isSynthetic && identifier.bestElement == null) {
+ rule.reportLint(identifier);
+ }
+ }
+}
« 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