Skip to content

Commit f193637

Browse files
bwilkersoncommit-bot@chromium.org
authored andcommitted
Fix a bug in the way analysis option files are merged
Fixes: https://github.com/dart-lang/linter/issues/2612 Change-Id: I1e383a040a47c75ba55b2eee787850543159232d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/197242 Reviewed-by: Samuel Rawlins <[email protected]> Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent d9f9b4d commit f193637

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

pkg/analyzer/lib/src/util/yaml.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Merger {
3030
/// * maps are merged recursively.
3131
/// * if map values cannot be merged, the overriding value is taken.
3232
///
33-
YamlNode merge(YamlNode o1, YamlNode? o2) {
33+
YamlNode merge(YamlNode o1, YamlNode o2) {
3434
// Handle promotion first.
3535
YamlMap listToMap(YamlList list) {
3636
Map<YamlNode, YamlNode> map =
@@ -56,7 +56,10 @@ class Merger {
5656
return mergeList(o1, o2);
5757
}
5858
// Default to override, unless the overriding value is `null`.
59-
return o2 ?? o1;
59+
if (o2 is YamlScalar && o2.value == null) {
60+
return o1;
61+
}
62+
return o2;
6063
}
6164

6265
/// Merge lists, avoiding duplicates.
@@ -75,7 +78,7 @@ class Merger {
7578
YamlMap mergeMap(YamlMap m1, YamlMap m2) {
7679
Map<YamlNode, YamlNode> merged =
7780
HashMap<YamlNode, YamlNode>(); // equals: _equals, hashCode: _hashCode
78-
m1.nodes.forEach((k, v) {
81+
m1.nodeMap.forEach((k, v) {
7982
merged[k] = v;
8083
});
8184
m2.nodeMap.forEach((k, v) {

pkg/analyzer/test/source/analysis_options_provider_test.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,31 @@ include: foo.include
195195
}
196196
}
197197

198+
void test_getOptions_include_emptyLints() {
199+
pathTranslator.newFile('/foo.include', r'''
200+
linter:
201+
rules:
202+
- prefer_single_quotes
203+
''');
204+
pathTranslator.newFile('/$analysisOptionsYaml', r'''
205+
include: foo.include
206+
linter:
207+
rules:
208+
# avoid_print: false
209+
''');
210+
YamlMap options = _getOptions('/');
211+
expect(options, hasLength(2));
212+
{
213+
var linter = options.valueAt('linter') as YamlMap;
214+
expect(linter, hasLength(1));
215+
{
216+
var rules = linter.valueAt('rules') as YamlList;
217+
expect(rules, hasLength(1));
218+
expect(rules[0], 'prefer_single_quotes');
219+
}
220+
}
221+
}
222+
198223
void test_getOptions_include_missing() {
199224
pathTranslator.newFile('/$analysisOptionsYaml', r'''
200225
include: /foo.include

0 commit comments

Comments
 (0)