Skip to content

Commit f23cea4

Browse files
keertipCommit Queue
authored andcommitted
Find options file when it is not in the folder of the containing root.
Fixes #56552 Change-Id: I1cf8ec10203a2b1bb11eafd16938ceb4f965c03c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390082 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Keerti Parthasarathy <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent dac5fa8 commit f23cea4

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

pkg/analyzer/lib/src/dart/analysis/context_locator.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,19 @@ class ContextLocatorImpl implements ContextLocator {
348348
);
349349
var root = ContextRootImpl(resourceProvider, folder, workspace);
350350
root.packagesFile = rootPackagesFile;
351+
// Check for analysis options file in the parent directories, from
352+
// root folder to the containing root folder. Pick the one closest
353+
// to the root.
354+
if (localOptionsFile == null) {
355+
var parentFolder = root.root.parent;
356+
while (parentFolder != containingRoot.root) {
357+
localOptionsFile = parentFolder.existingAnalysisOptionsYamlFile;
358+
if (localOptionsFile != null) {
359+
break;
360+
}
361+
parentFolder = parentFolder.parent;
362+
}
363+
}
351364
root.optionsFile = localOptionsFile ?? containingRoot.optionsFile;
352365
root.included.add(folder);
353366
containingRoot.excluded.add(folder);

pkg/analyzer/test/src/dart/analysis/analysis_context_collection_test.dart

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,16 @@ name: test
297297
);
298298

299299
newFile('$testPackageLibPath/a.dart', '');
300-
newFile('$testPackageLibPath/b.g.dart', '');
301-
newAnalysisOptionsYamlFile(testPackageRootPath, r'''
300+
newAnalysisOptionsYamlFile(testPackageLibPath, r'''
302301
analyzer:
303302
exclude:
304303
- "**/*.g.dart"
305304
''');
306305

306+
var nestedNoYamlPath = '$testPackageLibPath/nestedNoYaml';
307+
newFile('$nestedNoYamlPath/a.dart', '');
308+
newFile('$nestedNoYamlPath/b.g.dart', '');
309+
307310
var nestedPath = '$testPackageLibPath/nested';
308311
newFile('$nestedPath/lib/c.dart', '');
309312
newFile('$nestedPath/lib/d.g.dart', '');
@@ -320,24 +323,28 @@ name: nested
320323
contexts
321324
/home/test
322325
packagesFile: /home/test/.dart_tool/package_config.json
323-
optionsFile: /home/test/analysis_options.yaml
324326
workspace: workspace_0
325327
analyzedFiles
326328
/home/test/lib/a.dart
327329
uri: package:test/a.dart
328330
analysisOptions_0
329331
workspacePackage_0_0
332+
/home/test/lib/nestedNoYaml/a.dart
333+
uri: package:test/nestedNoYaml/a.dart
334+
analysisOptions_0
335+
workspacePackage_0_0
330336
/home/test/lib/nested
331337
packagesFile: /home/test/lib/nested/.dart_tool/package_config.json
332-
optionsFile: /home/test/analysis_options.yaml
338+
optionsFile: /home/test/lib/analysis_options.yaml
333339
workspace: workspace_1
334340
analyzedFiles
335341
/home/test/lib/nested/lib/c.dart
336342
uri: package:nested/c.dart
337-
analysisOptions_0
343+
analysisOptions_1
338344
workspacePackage_1_0
339345
analysisOptions
340-
analysisOptions_0: /home/test/analysis_options.yaml
346+
analysisOptions_0: /home/test/lib/analysis_options.yaml
347+
analysisOptions_1: /home/test/lib/analysis_options.yaml
341348
workspaces
342349
workspace_0: PackageConfigWorkspace
343350
root: /home/test

0 commit comments

Comments
 (0)