Skip to content

Commit 31dbdd4

Browse files
srawlinsCommit Bot
authored andcommitted
Allow excluding pubspec.yaml and analysis_options.yaml
Bug: #48683 Change-Id: Icb4ac24c37bfa91b4dd8612d2783c6fdcc663106 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/239500 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent f2d3051 commit 31dbdd4

File tree

3 files changed

+78
-2
lines changed

3 files changed

+78
-2
lines changed

pkg/analysis_server/lib/src/context_manager.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,9 @@ class ContextManagerImpl implements ContextManager {
484484
}
485485

486486
var optionsFile = analysisContext.contextRoot.optionsFile;
487-
if (optionsFile != null) {
487+
488+
if (optionsFile != null &&
489+
analysisContext.contextRoot.isAnalyzed(optionsFile.path)) {
488490
_analyzeAnalysisOptionsYaml(driver, optionsFile.path);
489491
}
490492

@@ -497,7 +499,8 @@ class ContextManagerImpl implements ContextManager {
497499

498500
var pubspecFile =
499501
rootFolder.getChildAssumingFile(file_paths.pubspecYaml);
500-
if (pubspecFile.exists) {
502+
if (pubspecFile.exists &&
503+
analysisContext.contextRoot.isAnalyzed(pubspecFile.path)) {
501504
_analyzePubspecYaml(driver, pubspecFile.path);
502505
}
503506
}

pkg/analysis_server/test/domain_analysis_test.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,30 @@ analyzer:
12231223
]);
12241224
}
12251225

1226+
Future<void> test_setRoots_notDartFile_analysisOptions_excluded() async {
1227+
deleteTestPackageAnalysisOptionsFile();
1228+
var a_path = '$testPackageLibPath/a.dart';
1229+
var options_path = '$testPackageRootPath/analysis_options.yaml';
1230+
1231+
newFile2(a_path, 'error');
1232+
1233+
// 'analysis_options.yaml' that has an error and excludes itself.
1234+
newFile2(options_path, '''
1235+
analyzer:
1236+
exclude:
1237+
- analysis_options.yaml
1238+
error:
1239+
''');
1240+
1241+
await setRoots(included: [workspaceRootPath], excluded: []);
1242+
await server.onAnalysisComplete;
1243+
1244+
_assertAnalyzedFiles(
1245+
hasErrors: [a_path],
1246+
notAnalyzed: [options_path],
1247+
);
1248+
}
1249+
12261250
Future<void> test_setRoots_notDartFile_androidManifestXml() async {
12271251
var path = '$testPackageRootPath/AndroidManifest.xml';
12281252

@@ -1253,6 +1277,35 @@ analyzer:
12531277
assertHasErrors(path);
12541278
}
12551279

1280+
Future<void> test_setRoots_notDartFile_pubspec_excluded() async {
1281+
deleteTestPackageAnalysisOptionsFile();
1282+
var a_path = '$testPackageLibPath/a.dart';
1283+
var pubspec_path = '$testPackageRootPath/pubspec.yaml';
1284+
var options_path = '$testPackageRootPath/analysis_options.yaml';
1285+
1286+
newFile2(a_path, 'error');
1287+
1288+
writeTestPackagePubspecYamlFile('''
1289+
name:
1290+
- error
1291+
''');
1292+
1293+
// 'analysis_options.yaml' that excludes pubspec.yaml.
1294+
newFile2(options_path, '''
1295+
analyzer:
1296+
exclude:
1297+
- pubspec.yaml
1298+
''');
1299+
1300+
await setRoots(included: [workspaceRootPath], excluded: []);
1301+
await server.onAnalysisComplete;
1302+
1303+
_assertAnalyzedFiles(
1304+
hasErrors: [a_path],
1305+
notAnalyzed: [pubspec_path],
1306+
);
1307+
}
1308+
12561309
Future<void> test_setRoots_packageConfigJsonFile() async {
12571310
var aaaRootPath = '/packages/aaa';
12581311
var a_path = '$aaaRootPath/lib/a.dart';

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,26 @@ class ContextRootTest with ResourceProviderMixin {
113113
);
114114
}
115115

116+
test_isAnalyzed_explicitlyExcluded_byFile() {
117+
var excludePath = convertPath('/test/root/exclude/c.dart');
118+
var siblingPath = convertPath('/test/root/exclude/d.dart');
119+
contextRoot.excluded.add(newFile2(excludePath, ''));
120+
expect(contextRoot.isAnalyzed(excludePath), isFalse);
121+
expect(contextRoot.isAnalyzed(siblingPath), isTrue);
122+
}
123+
124+
test_isAnalyzed_explicitlyExcluded_byFile_analysisOptions() {
125+
var excludePath = convertPath('/test/root/analysis_options.yaml');
126+
contextRoot.excluded.add(newFile2(excludePath, ''));
127+
expect(contextRoot.isAnalyzed(excludePath), isFalse);
128+
}
129+
130+
test_isAnalyzed_explicitlyExcluded_byFile_pubspec() {
131+
var excludePath = convertPath('/test/root/pubspec.yaml');
132+
contextRoot.excluded.add(newFile2(excludePath, ''));
133+
expect(contextRoot.isAnalyzed(excludePath), isFalse);
134+
}
135+
116136
test_isAnalyzed_explicitlyExcluded_byFolder() {
117137
String excludePath = convertPath('/test/root/exclude');
118138
String filePath = convertPath('/test/root/exclude/root.dart');

0 commit comments

Comments
 (0)