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

Side by Side Diff: pkg/analysis_server/lib/src/services/linter/linter.dart

Issue 1418333002: OptionsValidator plugin extension and linter service. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Review feedback. Created 5 years, 1 month 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
(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 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/plugin/server_plugin.dart ('k') | pkg/analysis_server/test/services/linter/linter_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698