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

Side by Side Diff: pkg/analyzer/lib/src/task/options.dart

Issue 1541453002: Error code validation updates. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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 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 analyzer.src.task.options; 5 library analyzer.src.task.options;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/analyzer.dart'; 9 import 'package:analyzer/analyzer.dart';
10 import 'package:analyzer/plugin/options.dart'; 10 import 'package:analyzer/plugin/options.dart';
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 static const String exclude = 'exclude'; 45 static const String exclude = 'exclude';
46 static const String language = 'language'; 46 static const String language = 'language';
47 static const String plugins = 'plugins'; 47 static const String plugins = 'plugins';
48 static const String strong_mode = 'strong-mode'; 48 static const String strong_mode = 'strong-mode';
49 49
50 /// Ways to say `ignore`. 50 /// Ways to say `ignore`.
51 static const List<String> ignoreSynonyms = const ['ignore', 'false']; 51 static const List<String> ignoreSynonyms = const ['ignore', 'false'];
52 52
53 /// Valid error `severity`s. 53 /// Valid error `severity`s.
54 static final List<String> severities = 54 static final List<String> severities =
55 ErrorSeverity.values.map((s) => s.name).toList(); 55 new List.unmodifiable(severityMap.keys);
56 56
57 /// Ways to say `include`. 57 /// Ways to say `include`.
58 static const List<String> includeSynonyms = const ['include', 'true']; 58 static const List<String> includeSynonyms = const ['include', 'true'];
59 59
60 /// Ways to say `true` or `false`. 60 /// Ways to say `true` or `false`.
61 static const List<String> trueOrFalse = const ['true', 'false']; 61 static const List<String> trueOrFalse = const ['true', 'false'];
62 62
63 /// Supported top-level `analyzer` options. 63 /// Supported top-level `analyzer` options.
64 static const List<String> topLevel = const [ 64 static const List<String> topLevel = const [
65 errors, 65 errors,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 114 }
115 } 115 }
116 AnalysisOptionsWarningCode get pluralProposalCode => 116 AnalysisOptionsWarningCode get pluralProposalCode =>
117 AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES; 117 AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES;
118 118
119 AnalysisOptionsWarningCode get singularProposalCode => 119 AnalysisOptionsWarningCode get singularProposalCode =>
120 AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE; 120 AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE;
121 121
122 /// Report an unsupported [node] value, defined in the given [scopeName]. 122 /// Report an unsupported [node] value, defined in the given [scopeName].
123 void reportError(ErrorReporter reporter, String scopeName, YamlNode node) { 123 void reportError(ErrorReporter reporter, String scopeName, YamlNode node) {
124 reporter.reportErrorForSpan( 124 reporter
125 code, node.span, [scopeName, node.value, proposal]); 125 .reportErrorForSpan(code, node.span, [scopeName, node.value, proposal]);
126 } 126 }
127 } 127 }
128 128
129 /// Validates `analyzer` error filter options. 129 /// Validates `analyzer` error filter options.
130 class ErrorFilterOptionValidator extends OptionsValidator { 130 class ErrorFilterOptionValidator extends OptionsValidator {
131 /// Pretty list of legal includes. 131 /// Legal values.
132 static final String legalIncludes = StringUtilities.printListOfQuotedNames( 132 static final List<String> legalValues =
133 new List.from(AnalyzerOptions.ignoreSynonyms) 133 new List.from(AnalyzerOptions.ignoreSynonyms)
134 ..addAll(AnalyzerOptions.includeSynonyms)); 134 ..addAll(AnalyzerOptions.includeSynonyms)
135 ..addAll(AnalyzerOptions.severities);
136
137 /// Pretty String listing legal values.
138 static final String legalValueString =
139 StringUtilities.printListOfQuotedNames(legalValues);
135 140
136 /// Lazily populated set of error codes (hashed for speedy lookup). 141 /// Lazily populated set of error codes (hashed for speedy lookup).
137 static HashSet<String> _errorCodes; 142 static HashSet<String> _errorCodes;
138 143
139 /// Legal error code names. 144 /// Legal error code names.
140 static Set<String> get errorCodes { 145 static Set<String> get errorCodes {
141 if (_errorCodes == null) { 146 if (_errorCodes == null) {
142 _errorCodes = new HashSet<String>(); 147 _errorCodes = new HashSet<String>();
143 // Engine codes. 148 // Engine codes.
144 _errorCodes.addAll(ErrorCode.values.map((ErrorCode code) => code.name)); 149 _errorCodes.addAll(ErrorCode.values.map((ErrorCode code) => code.name));
(...skipping 18 matching lines...) Expand all
163 value = toUpperCase(k.value); 168 value = toUpperCase(k.value);
164 if (!errorCodes.contains(value)) { 169 if (!errorCodes.contains(value)) {
165 reporter.reportErrorForSpan( 170 reporter.reportErrorForSpan(
166 AnalysisOptionsWarningCode.UNRECOGNIZED_ERROR_CODE, 171 AnalysisOptionsWarningCode.UNRECOGNIZED_ERROR_CODE,
167 k.span, 172 k.span,
168 [k.value?.toString()]); 173 [k.value?.toString()]);
169 } 174 }
170 } 175 }
171 if (v is YamlScalar) { 176 if (v is YamlScalar) {
172 value = toLowerCase(v.value); 177 value = toLowerCase(v.value);
173 if (!AnalyzerOptions.ignoreSynonyms.contains(value) && 178 if (!legalValues.contains(value)) {
174 !AnalyzerOptions.includeSynonyms.contains(value)) {
175 reporter.reportErrorForSpan( 179 reporter.reportErrorForSpan(
176 AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES, 180 AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES,
177 v.span, 181 v.span, [
178 [AnalyzerOptions.errors, v.value?.toString(), legalIncludes]); 182 AnalyzerOptions.errors,
183 v.value?.toString(),
184 legalValueString
185 ]);
179 } 186 }
180 } 187 }
181 }); 188 });
182 } 189 }
183 } 190 }
184 } 191 }
185 192
186 /// A task that generates errors for an `.analysis_options` file. 193 /// A task that generates errors for an `.analysis_options` file.
187 class GenerateOptionsErrorsTask extends SourceBasedAnalysisTask { 194 class GenerateOptionsErrorsTask extends SourceBasedAnalysisTask {
188 /// The name of the input whose value is the content of the file. 195 /// The name of the input whose value is the content of the file.
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 setLanguageOption(context, feature, v.value); 451 setLanguageOption(context, feature, v.value);
445 } 452 }
446 }); 453 });
447 } else if (configs is Map) { 454 } else if (configs is Map) {
448 configs.forEach((k, v) => setLanguageOption(context, k, v)); 455 configs.forEach((k, v) => setLanguageOption(context, k, v));
449 } 456 }
450 } 457 }
451 458
452 void setProcessors(AnalysisContext context, Object codes) { 459 void setProcessors(AnalysisContext context, Object codes) {
453 ErrorConfig config = new ErrorConfig(codes); 460 ErrorConfig config = new ErrorConfig(codes);
454 context.setConfigurationData(CONFIGURED_ERROR_PROCESSORS, config.processors) ; 461 context.setConfigurationData(
462 CONFIGURED_ERROR_PROCESSORS, config.processors);
455 } 463 }
456 464
457 void setStrongMode(AnalysisContext context, Object strongMode) { 465 void setStrongMode(AnalysisContext context, Object strongMode) {
458 bool strong = strongMode is bool ? strongMode : false; 466 bool strong = strongMode is bool ? strongMode : false;
459 if (context.analysisOptions.strongMode != strong) { 467 if (context.analysisOptions.strongMode != strong) {
460 AnalysisOptionsImpl options = 468 AnalysisOptionsImpl options =
461 new AnalysisOptionsImpl.from(context.analysisOptions); 469 new AnalysisOptionsImpl.from(context.analysisOptions);
462 options.strongMode = strong; 470 options.strongMode = strong;
463 context.analysisOptions = options; 471 context.analysisOptions = options;
464 } 472 }
465 } 473 }
466 } 474 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/source/error_processor.dart ('k') | pkg/analyzer/test/src/task/options_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698