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

Side by Side Diff: test/rule_test.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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library linter.test.rule; 5 library linter.test.rule;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/error.dart'; 10 import 'package:analyzer/src/generated/error.dart';
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 if (entry is! File || !isDartFile(entry)) continue; 302 if (entry is! File || !isDartFile(entry)) continue;
303 var ruleName = p.basenameWithoutExtension(entry.path); 303 var ruleName = p.basenameWithoutExtension(entry.path);
304 if (ruleName == ruleToTest) { 304 if (ruleName == ruleToTest) {
305 testRule(ruleName, entry); 305 testRule(ruleName, entry);
306 } 306 }
307 } 307 }
308 } 308 }
309 309
310 Annotation extractAnnotation(String line) { 310 Annotation extractAnnotation(String line) {
311 int index = line.indexOf(new RegExp(r'(//|#)[ ]?LINT')); 311 int index = line.indexOf(new RegExp(r'(//|#)[ ]?LINT'));
312 //Grab the first comment to see if there's one preceding the annotation. 312
313 int comment = line.indexOf(new RegExp(r'(//|#)')); 313 // Grab the first comment to see if there's one preceding the annotation.
314 // Check for '#' first to allow for lints on dartdocs.
315 int comment = line.indexOf('#');
316 if (comment == -1) {
317 comment = line.indexOf('//');
318 }
319
314 if (index > -1 && comment == index) { 320 if (index > -1 && comment == index) {
315 int column; 321 int column;
316 int length; 322 int length;
317 var annotation = line.substring(index); 323 var annotation = line.substring(index);
318 var leftBrace = annotation.indexOf('['); 324 var leftBrace = annotation.indexOf('[');
319 if (leftBrace != -1) { 325 if (leftBrace != -1) {
320 var sep = annotation.indexOf(':'); 326 var sep = annotation.indexOf(':');
321 column = int.parse(annotation.substring(leftBrace + 1, sep)); 327 column = int.parse(annotation.substring(leftBrace + 1, sep));
322 var rightBrace = annotation.indexOf(']'); 328 var rightBrace = annotation.indexOf(']');
323 length = int.parse(annotation.substring(sep + 1, rightBrace)); 329 length = int.parse(annotation.substring(sep + 1, rightBrace));
324 } 330 }
325 331
326 int msgIndex = annotation.indexOf(']') + 1; 332 int msgIndex = annotation.indexOf(']') + 1;
327 if (msgIndex < 1) { 333 if (msgIndex < 1) {
328 msgIndex = annotation.indexOf('T') + 1; 334 msgIndex = annotation.indexOf('T') + 1;
329 } 335 }
330 String msg = null; 336 String msg = null;
331 if (msgIndex < line.length) { 337 if (msgIndex < line.length) {
332 msg = line.substring(index + msgIndex).trim(); 338 msg = line.substring(index + msgIndex).trim();
333 if (msg.length == 0) { 339 if (msg.isEmpty) {
334 msg = null; 340 msg = null;
335 } 341 }
336 } 342 }
337 return new Annotation.forLint(msg, column, length); 343 return new Annotation.forLint(msg, column, length);
338 } 344 }
339 return null; 345 return null;
340 } 346 }
341 347
342 AnnotationMatcher matchesAnnotation( 348 AnnotationMatcher matchesAnnotation(
343 String message, ErrorType type, int lineNumber) => 349 String message, ErrorType type, int lineNumber) =>
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 480
475 class NoFilter implements LintFilter { 481 class NoFilter implements LintFilter {
476 @override 482 @override
477 bool filter(AnalysisError lint) => false; 483 bool filter(AnalysisError lint) => false;
478 } 484 }
479 485
480 class ResultReporter extends DetailedReporter { 486 class ResultReporter extends DetailedReporter {
481 ResultReporter(Iterable<AnalysisErrorInfo> errors) 487 ResultReporter(Iterable<AnalysisErrorInfo> errors)
482 : super(errors, new NoFilter(), stdout); 488 : super(errors, new NoFilter(), stdout);
483 } 489 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698