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

Unified Diff: pkg/analyzer/lib/src/task/options.dart

Issue 1419673006: More options file validation (and API iteration). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/error.dart ('k') | pkg/analyzer/test/src/task/options_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/task/options.dart
diff --git a/pkg/analyzer/lib/src/task/options.dart b/pkg/analyzer/lib/src/task/options.dart
index 120f3059bd966d21562c95891a4471d04937e007..ee02e5c48bf65408eaf4c93df908d8676146d09a 100644
--- a/pkg/analyzer/lib/src/task/options.dart
+++ b/pkg/analyzer/lib/src/task/options.dart
@@ -21,6 +21,12 @@ final ListResultDescriptor<AnalysisError> ANALYSIS_OPTIONS_ERRORS =
new ListResultDescriptor<AnalysisError>(
'ANALYSIS_OPTIONS_ERRORS', AnalysisError.NO_ERRORS);
+/// Validates `analyzer` top-level options.
+class AnalyzerOptionsValidator extends TopLevelOptionValidator {
+ AnalyzerOptionsValidator()
+ : super('analyzer', const ['exclude', 'plugins', 'strong-mode']);
+}
+
/// A task that generates errors for an `.analysis_options` file.
class GenerateOptionsErrorsTask extends SourceBasedAnalysisTask {
/// The name of the input whose value is the content of the file.
@@ -81,56 +87,58 @@ class GenerateOptionsErrorsTask extends SourceBasedAnalysisTask {
new GenerateOptionsErrorsTask(context, target);
}
+/// Validates `linter` top-level options.
+/// TODO(pq): move into `linter` package and plugin.
pquitslund 2015/10/22 17:48:26 Or maybe to a server-hosted linter plugin. (In an
+class LinterOptionsValidator extends TopLevelOptionValidator {
+ LinterOptionsValidator() : super('linter', const ['rules']);
+}
+
/// Validates options defined in an `.analysis_options` file.
class OptionsFileValidator {
- // TODO(pq): consider an extension point.
+ // TODO(pq): move to an extension point.
static final List<OptionsValidator> _validators = [
- new AnalyzerOptionsValidator()
+ new AnalyzerOptionsValidator(), new LinterOptionsValidator()
];
final Source source;
OptionsFileValidator(this.source);
List<AnalysisError> validate(Map<String, YamlNode> options) {
- List<AnalysisError> errors = <AnalysisError>[];
- _validators.forEach(
- (OptionsValidator v) => errors.addAll(v.validate(source, options)));
- return errors;
+ RecordingErrorListener recorder = new RecordingErrorListener();
+ ErrorReporter reporter = new ErrorReporter(recorder, source);
+ _validators.forEach((OptionsValidator v) => v.validate(reporter, options));
+ return recorder.errors;
}
}
-AnalysisError _unsupportedOption(
- Source source, YamlScalar key, String pluginName) {
- SourceSpan span = key.span;
- return new AnalysisError(source, span.start.column + 1, span.length,
- AnalysisOptionsWarningCode.UNSUPPORTED_OPTION, [pluginName, key.value]);
-}
-
/// Validates options.
abstract class OptionsValidator {
- List<AnalysisError> validate(Source source, Map<String, YamlNode> options);
+ /// Validate [options], reporting any errors to the given [reporter].
+ void validate(ErrorReporter reporter, Map<String, YamlNode> options);
}
-/// Validates `analyzer` options.
-class AnalyzerOptionsValidator extends OptionsValidator {
- static const List<String> _supportedOptions = const [
- 'exclude',
- 'strong-mode'
- ];
+/// Validates top-level options. For example,
+/// plugin:
+/// top-level-option: true
+class TopLevelOptionValidator extends OptionsValidator {
+ final String pluginName;
+ final List<String> supportedOptions;
Brian Wilkerson 2015/10/22 20:00:15 Might be interesting to eventually make this a map
pquitslund 2015/10/22 20:19:26 Good idea!
+ TopLevelOptionValidator(this.pluginName, this.supportedOptions);
@override
- List<AnalysisError> validate(Source source, Map<String, YamlNode> options) {
- List<AnalysisError> errors = <AnalysisError>[];
- YamlNode node = options['analyzer'];
+ void validate(ErrorReporter reporter, Map<String, YamlNode> options) {
+ YamlNode node = options[pluginName];
if (node is YamlMap) {
node.nodes.forEach((k, v) {
if (k is YamlScalar) {
Brian Wilkerson 2015/10/22 20:00:15 Is it an error if the key is not a scalar value? (
pquitslund 2015/10/22 20:19:26 Done.
- if (!_supportedOptions.contains(k.value)) {
- errors.add(_unsupportedOption(source, k, 'analyzer'));
+ if (!supportedOptions.contains(k.value)) {
+ reporter.reportErrorForSpan(
+ AnalysisOptionsWarningCode.UNSUPPORTED_OPTION,
+ k.span,
+ [pluginName, k.value]);
}
}
});
}
- return errors;
}
}
« no previous file with comments | « pkg/analyzer/lib/src/generated/error.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