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

Unified 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, 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
Index: pkg/analysis_server/lib/src/services/linter/linter.dart
diff --git a/pkg/analysis_server/lib/src/services/linter/linter.dart b/pkg/analysis_server/lib/src/services/linter/linter.dart
new file mode 100644
index 0000000000000000000000000000000000000000..87692eaf478bac17f4eb67569c7955c96f745e77
--- /dev/null
+++ b/pkg/analysis_server/lib/src/services/linter/linter.dart
@@ -0,0 +1,51 @@
+// Copyright (c) 2014, 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.
+
+library services.src.linter;
+
+import 'package:analyzer/plugin/options.dart';
+import 'package:analyzer/analyzer.dart';
+import 'package:yaml/yaml.dart';
+import 'package:linter/src/rules.dart';
+import 'package:linter/src/linter.dart';
+
+/**
+ * An error code indicating an undefined lint rule.
+ *
+ * Parameters:
+ * 0: the rule name
+ */
+const AnalysisOptionsWarningCode UNDEFINED_LINT_WARNING =
+ const AnalysisOptionsWarningCode(
+ 'UNDEFINED_LINT_WARNING', "Undefined lint rule '{0}'");
+
+/// 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) {
+ //TODO(pq): migrate this to a proper API once there is one.
+ Iterable<String> registeredLints = ruleRegistry.map((r) => r.name);
+ rules.nodes.forEach((YamlNode ruleNode) {
+ if (!registeredLints.contains(ruleNode.value)) {
+ reporter.reportErrorForSpan(
+ UNDEFINED_LINT_WARNING, ruleNode.span, [ruleNode.value]);
+ }
+ });
+ }
+ }
+}
« 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