| OLD | NEW |
| 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.src.linter; | 5 library linter.src.linter; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart'; | 9 import 'package:analyzer/analyzer.dart'; |
| 10 import 'package:analyzer/src/generated/engine.dart' | 10 import 'package:analyzer/src/generated/engine.dart' |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 | 255 |
| 256 /// Return a visitor to be passed to pubspecs to perform lint | 256 /// Return a visitor to be passed to pubspecs to perform lint |
| 257 /// analysis. | 257 /// analysis. |
| 258 /// Lint errors are reported via this [Linter]'s error [reporter]. | 258 /// Lint errors are reported via this [Linter]'s error [reporter]. |
| 259 PubspecVisitor getPubspecVisitor() => null; | 259 PubspecVisitor getPubspecVisitor() => null; |
| 260 | 260 |
| 261 @override | 261 @override |
| 262 AstVisitor getVisitor() => null; | 262 AstVisitor getVisitor() => null; |
| 263 | 263 |
| 264 void reportLint(AstNode node) { | 264 void reportLint(AstNode node) { |
| 265 reporter.reportErrorForNode(new _LintCode(name, description), node, []); | 265 if (node != null) { |
| 266 reporter.reportErrorForNode(new _LintCode(name, description), node, []); |
| 267 } |
| 266 } | 268 } |
| 267 | 269 |
| 268 void reportLintForToken(Token token) { | 270 void reportLintForToken(Token token) { |
| 269 reporter.reportErrorForToken(new _LintCode(name, description), token, []); | 271 if (token != null) { |
| 272 reporter.reportErrorForToken(new _LintCode(name, description), token, []); |
| 273 } |
| 270 } | 274 } |
| 271 | 275 |
| 272 void reportPubLint(PSNode node) { | 276 void reportPubLint(PSNode node) { |
| 273 Source source = createSource(node.span.sourceUrl); | 277 Source source = createSource(node.span.sourceUrl); |
| 274 | 278 |
| 275 // Cache error and location info for creating AnalysisErrorInfos | 279 // Cache error and location info for creating AnalysisErrorInfos |
| 276 // Note that error columns are 1-based | 280 // Note that error columns are 1-based |
| 277 var error = new AnalysisError(source, node.span.start.column + 1, | 281 var error = new AnalysisError(source, node.span.start.column + 1, |
| 278 node.span.length, new _LintCode(name, description)); | 282 node.span.length, new _LintCode(name, description)); |
| 279 | 283 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 } | 436 } |
| 433 | 437 |
| 434 class _LintCode extends LintCode { | 438 class _LintCode extends LintCode { |
| 435 static final registry = <String, LintCode>{}; | 439 static final registry = <String, LintCode>{}; |
| 436 | 440 |
| 437 factory _LintCode(String name, String message) => registry.putIfAbsent( | 441 factory _LintCode(String name, String message) => registry.putIfAbsent( |
| 438 name + message, () => new _LintCode._(name, message)); | 442 name + message, () => new _LintCode._(name, message)); |
| 439 | 443 |
| 440 _LintCode._(String name, String message) : super(name, message); | 444 _LintCode._(String name, String message) : super(name, message); |
| 441 } | 445 } |
| OLD | NEW |