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

Unified Diff: pkg/analyzer/lib/src/lint/options_rule_validator.dart

Issue 2562223002: Add file missed in last commit (TBR) (Closed)
Patch Set: 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/lint/options_rule_validator.dart
diff --git a/pkg/analyzer/lib/src/lint/options_rule_validator.dart b/pkg/analyzer/lib/src/lint/options_rule_validator.dart
new file mode 100644
index 0000000000000000000000000000000000000000..109cdd22c1d56fdfb394c4ca9ab49d91317552e7
--- /dev/null
+++ b/pkg/analyzer/lib/src/lint/options_rule_validator.dart
@@ -0,0 +1,51 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'package:analyzer/analyzer.dart';
+import 'package:analyzer/plugin/options.dart';
+import 'package:analyzer/src/lint/registry.dart';
+import 'package:yaml/yaml.dart';
+
+/**
+ * An error code indicating an undefined lint rule.
+ *
+ * Parameters:
+ * 0: the rule name
+ */
+const AnalysisOptionsWarningCode UNDEFINED_LINT_WARNING =
+ const AnalysisOptionsWarningCode(
+ 'UNDEFINED_LINT_WARNING', "'{0}' is not a recognized lint rule");
+
+/**
+ * Validates `linter` rule configurations.
+ */
+class LinterRuleOptionsValidator extends OptionsValidator {
+ static const linter = 'linter';
+ static const rulesKey = 'rules';
+ @override
+ List<AnalysisError> validate(
+ ErrorReporter reporter, Map<String, YamlNode> options) {
+ List<AnalysisError> errors = <AnalysisError>[];
+ var node = options[linter];
+ if (node is YamlMap) {
+ var rules = node.nodes[rulesKey];
+ validateRules(rules, reporter);
+ }
+ return errors;
+ }
+
+ validateRules(dynamic rules, ErrorReporter reporter) {
+ if (rules is YamlList) {
+ Iterable<String> registeredLints =
+ Registry.ruleRegistry.map((r) => r.name);
+ rules.nodes.forEach((YamlNode ruleNode) {
+ Object value = ruleNode.value;
+ if (value != null && !registeredLints.contains(value)) {
+ reporter.reportErrorForSpan(
+ UNDEFINED_LINT_WARNING, ruleNode.span, [value]);
+ }
+ });
+ }
+ }
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698