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

Unified Diff: pkg/analyzer/lib/src/dart/analysis/driver.dart

Issue 2545553007: Add support for generating lints when using the new driver (Closed)
Patch Set: fix some tests Created 4 years 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 | « pkg/analysis_server/test/test_all.dart ('k') | pkg/analyzer/lib/src/dart/analysis/status.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/dart/analysis/driver.dart
diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart
index b43a71b6872059294e39f6db09a579004f2dff09..7782d648c3b008a30a7ce3b3deb91b3c15b08cfe 100644
--- a/pkg/analyzer/lib/src/dart/analysis/driver.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart
@@ -21,6 +21,7 @@ import 'package:analyzer/src/dart/analysis/top_level_declaration.dart';
import 'package:analyzer/src/generated/engine.dart'
show AnalysisContext, AnalysisEngine, AnalysisOptions, ChangeSet;
import 'package:analyzer/src/generated/source.dart';
+import 'package:analyzer/src/services/lint.dart';
import 'package:analyzer/src/summary/api_signature.dart';
import 'package:analyzer/src/summary/format.dart';
import 'package:analyzer/src/summary/idl.dart';
@@ -749,8 +750,12 @@ class AnalysisDriver {
var unit = new AnalysisDriverResolvedUnit.fromBuffer(bytes);
List<AnalysisError> errors = unit.errors.map((error) {
String errorName = error.uniqueName;
- ErrorCode errorCode = errorCodeByUniqueName(errorName);
+ ErrorCode errorCode =
+ errorCodeByUniqueName(errorName) ?? _lintCodeByUniqueName(errorName);
if (errorCode == null) {
+ // This could fail because the error code is no longer defined, or, in
+ // the case of a lint rule, if the lint rule has been disabled since the
+ // errors were written.
throw new StateError('No ErrorCode for $errorName in $file');
}
return new AnalysisError.forValues(file.source, error.offset,
@@ -784,6 +789,24 @@ class AnalysisDriver {
}
/**
+ * Return the lint code with the given [errorName], or `null` if there is no
+ * lint registered with that name or the lint is not enabled in the analysis
+ * options.
+ */
+ ErrorCode _lintCodeByUniqueName(String errorName) {
+ if (errorName.startsWith('_LintCode.')) {
+ String lintName = errorName.substring(10);
+ List<Linter> lintRules = analysisOptions.lintRules;
+ for (Linter linter in lintRules) {
+ if (linter.name == lintName) {
+ return linter.lintCode;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
* Perform a single chunk of work and produce [results].
*/
Future<Null> _performWork() async {
@@ -974,6 +997,12 @@ class AnalysisDriverScheduler {
AnalysisDriverScheduler(this._logger);
/**
+ * Return `true` if we are currently analyzing code.
+ */
+ bool get isAnalyzing =>
+ _statusSupport.currentStatus == AnalysisStatus.ANALYZING;
+
+ /**
* Return the stream that produces [AnalysisStatus] events.
*/
Stream<AnalysisStatus> get status => _statusSupport.stream;
« no previous file with comments | « pkg/analysis_server/test/test_all.dart ('k') | pkg/analyzer/lib/src/dart/analysis/status.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698