OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 library services.src.linter; |
| 6 |
| 7 import 'package:analyzer/plugin/options.dart'; |
| 8 import 'package:analyzer/analyzer.dart'; |
| 9 import 'package:yaml/yaml.dart'; |
| 10 import 'package:linter/src/rules.dart'; |
| 11 import 'package:linter/src/linter.dart'; |
| 12 |
| 13 /** |
| 14 * An error code indicating an undefined lint rule. |
| 15 * |
| 16 * Parameters: |
| 17 * 0: the rule name |
| 18 */ |
| 19 const AnalysisOptionsWarningCode UNDEFINED_LINT_WARNING = |
| 20 const AnalysisOptionsWarningCode( |
| 21 'UNDEFINED_LINT_WARNING', "Undefined lint rule '{0}'"); |
| 22 |
| 23 /// Validates `linter` rule configurations. |
| 24 class LinterRuleOptionsValidator extends OptionsValidator { |
| 25 static const linter = 'linter'; |
| 26 static const rulesKey = 'rules'; |
| 27 @override |
| 28 List<AnalysisError> validate( |
| 29 ErrorReporter reporter, Map<String, YamlNode> options) { |
| 30 List<AnalysisError> errors = <AnalysisError>[]; |
| 31 var node = options[linter]; |
| 32 if (node is YamlMap) { |
| 33 var rules = node.nodes[rulesKey]; |
| 34 validateRules(rules, reporter); |
| 35 } |
| 36 return errors; |
| 37 } |
| 38 |
| 39 validateRules(dynamic rules, ErrorReporter reporter) { |
| 40 if (rules is YamlList) { |
| 41 //TODO(pq): migrate this to a proper API once there is one. |
| 42 Iterable<String> registeredLints = ruleRegistry.map((r) => r.name); |
| 43 rules.nodes.forEach((YamlNode ruleNode) { |
| 44 if (!registeredLints.contains(ruleNode.value)) { |
| 45 reporter.reportErrorForSpan( |
| 46 UNDEFINED_LINT_WARNING, ruleNode.span, [ruleNode.value]); |
| 47 } |
| 48 }); |
| 49 } |
| 50 } |
| 51 } |
OLD | NEW |