2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- import 'dart:collection' ;
6
-
7
5
import 'package:analyzer/error/error.dart' ;
8
6
import 'package:analyzer/error/listener.dart' ;
9
7
import 'package:analyzer/src/analysis_options/error/option_codes.dart' ;
@@ -34,6 +32,18 @@ const AnalysisOptionsHintCode DUPLICATE_RULE_HINT = AnalysisOptionsHintCode(
34
32
"The rule {0} is already specified and doesn't need to be specified again." ,
35
33
correction: "Try removing all but one specification of the rule." );
36
34
35
+ /**
36
+ * An error code indicating an incompatible rule.
37
+ *
38
+ * Parameters:
39
+ * 0: the rule name
40
+ * 1: the incompatible rule
41
+ */
42
+ const AnalysisOptionsWarningCode INCOMPATIBLE_LINT_WARNING =
43
+ AnalysisOptionsWarningCode ('INCOMPATIBLE_LINT_WARNING' ,
44
+ "The rule '{0}' is incompatible with the rule '{1}'" ,
45
+ correction: "Try removing one of the incompatible rules." );
46
+
37
47
/**
38
48
* An error code indicating an undefined lint rule.
39
49
*
@@ -77,14 +87,31 @@ class LinterRuleOptionsValidator extends OptionsValidator {
77
87
78
88
validateRules (YamlNode rules, ErrorReporter reporter) {
79
89
if (rules is YamlList ) {
80
- Set <String > seenRules = HashSet <String >();
81
- rules.nodes.forEach ((YamlNode ruleNode) {
82
- Object value = ruleNode.value;
90
+ final seenRules = < String > {};
91
+
92
+ String findIncompatibleRule (LintRule rule) {
93
+ for (var incompatibleRule in rule.incompatibleRules) {
94
+ if (seenRules.contains (incompatibleRule)) {
95
+ return incompatibleRule;
96
+ }
97
+ }
98
+ return null ;
99
+ }
100
+
101
+ for (var ruleNode in rules.nodes) {
102
+ final value = ruleNode.value;
83
103
if (value != null ) {
84
- LintRule rule = getRegisteredLint (value);
104
+ final rule = getRegisteredLint (value);
85
105
if (rule == null ) {
86
106
reporter.reportErrorForSpan (
87
107
UNDEFINED_LINT_WARNING , ruleNode.span, [value]);
108
+ continue ;
109
+ }
110
+
111
+ final incompatibleRule = findIncompatibleRule (rule);
112
+ if (incompatibleRule != null ) {
113
+ reporter.reportErrorForSpan (INCOMPATIBLE_LINT_WARNING ,
114
+ ruleNode.span, [value, incompatibleRule]);
88
115
} else if (! seenRules.add (rule.name)) {
89
116
reporter.reportErrorForSpan (
90
117
DUPLICATE_RULE_HINT , ruleNode.span, [value]);
@@ -93,7 +120,7 @@ class LinterRuleOptionsValidator extends OptionsValidator {
93
120
DEPRECATED_LINT_HINT , ruleNode.span, [value]);
94
121
}
95
122
}
96
- });
123
+ }
97
124
}
98
125
}
99
126
}
0 commit comments