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

Side by Side Diff: pkg/analyzer/lib/source/error_processor.dart

Issue 1813973002: Don't upgrade the severity of *everything* to an error in strong mode. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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 | « no previous file | pkg/analyzer/test/source/error_processor_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
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 analyzer.source.error_processor; 5 library analyzer.source.error_processor;
6 6
7 import 'package:analyzer/src/generated/engine.dart'; 7 import 'package:analyzer/src/generated/engine.dart';
8 import 'package:analyzer/src/generated/error.dart'; 8 import 'package:analyzer/src/generated/error.dart';
9 import 'package:analyzer/src/generated/utilities_general.dart'; 9 import 'package:analyzer/src/generated/utilities_general.dart';
10 import 'package:analyzer/src/task/options.dart'; 10 import 'package:analyzer/src/task/options.dart';
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 bool appliesTo(AnalysisError error) => code == error.errorCode.name; 87 bool appliesTo(AnalysisError error) => code == error.errorCode.name;
88 88
89 /// Return an error processor associated with this [context] for the given 89 /// Return an error processor associated with this [context] for the given
90 /// [error], or `null` if none is found. 90 /// [error], or `null` if none is found.
91 static ErrorProcessor getProcessor( 91 static ErrorProcessor getProcessor(
92 AnalysisContext context, AnalysisError error) { 92 AnalysisContext context, AnalysisError error) {
93 if (context == null) { 93 if (context == null) {
94 return null; 94 return null;
95 } 95 }
96 96
97 // By default, the error is not processed.
98 ErrorProcessor processor;
99
100 // Give strong mode a chance to upgrade it.
101 if (context.analysisOptions.strongMode) {
102 processor = _StrongModeTypeErrorProcessor.instance;
103 }
104
105 // Let the user configure how specific errors are processed. 97 // Let the user configure how specific errors are processed.
106 List<ErrorProcessor> processors = 98 List<ErrorProcessor> processors =
107 context.getConfigurationData(CONFIGURED_ERROR_PROCESSORS); 99 context.getConfigurationData(CONFIGURED_ERROR_PROCESSORS);
108 100
101 // Give strong mode a chance to upgrade it.
102 if (context.analysisOptions.strongMode) {
103 processors = processors.toList();
Brian Wilkerson 2016/03/17 19:54:14 It looks like it should already be a list. Is 'get
Bob Nystrom 2016/03/17 19:58:25 It is a list, but I want to copy it so I don't mut
104 processors.add(_StrongModeTypeErrorProcessor.instance);
105 }
106
109 return processors.firstWhere((ErrorProcessor p) => p.appliesTo(error), 107 return processors.firstWhere((ErrorProcessor p) => p.appliesTo(error),
110 orElse: () => processor); 108 orElse: () => null);
111 } 109 }
112 } 110 }
113 111
114 /// In strong mode, this upgrades static type warnings to errors. 112 /// In strong mode, this upgrades static type warnings to errors.
115 class _StrongModeTypeErrorProcessor implements ErrorProcessor { 113 class _StrongModeTypeErrorProcessor implements ErrorProcessor {
116 static final instance = new _StrongModeTypeErrorProcessor(); 114 static final instance = new _StrongModeTypeErrorProcessor();
117 115
118 // TODO(rnystrom): As far as I know, this is only used to implement 116 // TODO(rnystrom): As far as I know, this is only used to implement
119 // appliesTo(). Consider making it private in ErrorProcessor if possible. 117 // appliesTo(). Consider making it private in ErrorProcessor if possible.
120 String get code => throw new UnsupportedError( 118 String get code => throw new UnsupportedError(
121 "_StrongModeTypeErrorProcessor is not specific to an error code."); 119 "_StrongModeTypeErrorProcessor is not specific to an error code.");
122 120
123 /// In strong mode, type warnings are upgraded to errors. 121 /// In strong mode, type warnings are upgraded to errors.
124 ErrorSeverity get severity => ErrorSeverity.ERROR; 122 ErrorSeverity get severity => ErrorSeverity.ERROR;
125 123
126 /// Check if this processor applies to the given [error]. 124 /// Check if this processor applies to the given [error].
127 bool appliesTo(AnalysisError error) => 125 bool appliesTo(AnalysisError error) =>
128 error.errorCode.type == ErrorType.STATIC_TYPE_WARNING; 126 error.errorCode.type == ErrorType.STATIC_TYPE_WARNING;
129 } 127 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/source/error_processor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698