Skip to content

Commit 9bee017

Browse files
FMorschelCommit Queue
authored andcommitted
[analyzer] Fixes empty linter rules incompatible_lint false negative
Also fixes the message that contained extra quotes around the incompatible lint list even though the parameter itself was "quoted with and", so wrongly `''lint_pos' and 'lint_neg''` instead of `'lint_pos and lint_neg'`. Fixes: #61500 Change-Id: I60b730aee84eb8d4f229e594aa582aaf00a9c3c3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449560 Auto-Submit: Felipe Morschel <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]>
1 parent 4c43103 commit 9bee017

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

pkg/analyzer/lib/src/analysis_options/error/option_codes.g.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ class AnalysisOptionsWarningCode extends DiagnosticCodeWithExpectedTypes {
315315
>
316316
incompatibleLintIncluded = AnalysisOptionsWarningTemplate(
317317
'INCOMPATIBLE_LINT',
318-
"The rule '{0}' is incompatible with '{1}', which is included from {2} "
318+
"The rule '{0}' is incompatible with {1}, which is included from {2} "
319319
"file{3}.",
320320
correctionMessage:
321321
"Try locally disabling all but one of the conflicting rules or "

pkg/analyzer/lib/src/lint/options_rule_validator.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ class LinterRuleOptionsValidator extends OptionsValidator {
362362
) {
363363
if (rules is! YamlList &&
364364
rules is! YamlMap &&
365+
// This handles empty keys like
366+
// linter:
367+
// rules:
368+
(rules is! YamlScalar || rules.value != null) &&
365369
// We accept 'null' for triggering `INCOMPATIBLE_LINT_INCLUDED`
366370
rules != null) {
367371
return;

pkg/analyzer/messages.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ AnalysisOptionsWarningCode:
171171
int p2: the number of files that include the incompatible rule
172172
String p3: plural suffix for the word "file"
173173
sharedName: INCOMPATIBLE_LINT
174-
problemMessage: "The rule '#p0' is incompatible with '#p1', which is included from #p2 file#p3."
174+
problemMessage: "The rule '#p0' is incompatible with #p1, which is included from #p2 file#p3."
175175
correctionMessage: "Try locally disabling all but one of the conflicting rules or removing one of the incompatible files."
176176
hasPublishedDocs: false
177177
comment: |-

pkg/analyzer/test/src/options/options_rule_validator_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,30 @@ include:
185185
]);
186186
}
187187

188+
Future<void> test_incompatible_multiple_include_noLintMainFile() async {
189+
newFile('/included1.yaml', '''
190+
linter:
191+
rules:
192+
- rule_neg
193+
''');
194+
newFile('/included2.yaml', '''
195+
linter:
196+
rules:
197+
- rule_pos
198+
''');
199+
assertErrors(
200+
'''
201+
include:
202+
- included1.yaml
203+
- included2.yaml
204+
205+
linter:
206+
rules:
207+
''',
208+
[AnalysisOptionsWarningCode.incompatibleLintIncluded],
209+
);
210+
}
211+
188212
void test_incompatible_noTrigger_invalidMap() {
189213
newFile('/included.yaml', '''
190214
linter:

0 commit comments

Comments
 (0)