-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support nested analysis options files #212
Changes from 19 commits
9f2ca24
c925ce8
deea5e6
33273a5
c375d98
3d080e2
d9f5609
5fd23c7
c46b021
c6071d7
736c968
6e171ff
78c4a8c
0455aa9
1e234b5
39b10cc
fc7785a
ad57385
7b5d15e
a4b4518
bafad81
859470e
95de80d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -278,7 +278,8 @@ Analyzing... | |||||
'dependency conflict', | ||||||
() async { | ||||||
// Create two packages with the same name but different paths | ||||||
final workspace = await createSimpleWorkspace(['dep', 'dep']); | ||||||
final workspace = | ||||||
await createSimpleWorkspace(['dep', 'dep'], local: true); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a trailling comma, then format :)
Suggested change
|
||||||
|
||||||
final plugin = createPlugin( | ||||||
parent: workspace, | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -231,6 +231,7 @@ void writeSimplePackageConfig( | |
Future<Directory> createSimpleWorkspace( | ||
List<Object> projectEntry, { | ||
bool withPackageConfig = true, | ||
bool local = false, | ||
}) async { | ||
/// The number of time we've created a package with a given name. | ||
final packageCount = <String, int>{}; | ||
|
@@ -249,7 +250,7 @@ Future<Directory> createSimpleWorkspace( | |
return folderName; | ||
} | ||
|
||
return createWorkspace(withPackageConfig: withPackageConfig, { | ||
return createWorkspace(local: local, withPackageConfig: withPackageConfig, { | ||
for (final projectEntry in projectEntry) | ||
if (projectEntry is Pubspec) | ||
getFolderName(projectEntry.name): projectEntry | ||
|
@@ -275,8 +276,10 @@ Future<Directory> createSimpleWorkspace( | |
Future<Directory> createWorkspace( | ||
Map<String, Pubspec> pubspecs, { | ||
bool withPackageConfig = true, | ||
bool withNestedAnalysisOptions = false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems unused |
||
bool local = false, | ||
}) async { | ||
final dir = createTemporaryDirectory(); | ||
final dir = createTemporaryDirectory(local: local); | ||
|
||
String packagePathOf(Dependency dependency, String name) { | ||
switch (dependency) { | ||
|
@@ -339,10 +342,16 @@ Future<Directory> createWorkspace( | |
return dir; | ||
} | ||
|
||
Directory createTemporaryDirectory() { | ||
final dir = Directory.current // | ||
.dir('.dart_tool') | ||
.createTempSync('custom_lint_test'); | ||
Directory createTemporaryDirectory({bool local = false}) { | ||
final Directory dir; | ||
if (local) { | ||
// The cli_process_test needs it to be local in order for the relative paths to match | ||
dir = | ||
Directory.current.dir('.dart_tool').createTempSync('custom_lint_test'); | ||
} else { | ||
// Others need global directory in order to not pick up this project's package_config.json | ||
dir = Directory.systemTemp.createTempSync('custom_lint_test'); | ||
} | ||
addTearDown(() => dir.deleteSync(recursive: true)); | ||
|
||
// Watches process kill to delete the temporary directory. | ||
|
@@ -2453,25 +2462,67 @@ dependency_overrides: | |
}); | ||
|
||
group('fromContextRoots', () { | ||
test('throws MissingPubspecError if package does not contain a pubspec', | ||
/// Shorthand for calling [CustomLintWorkspace.fromContextRoots] from | ||
/// a list of path. | ||
Future<CustomLintWorkspace> fromContextRootsFromPaths( | ||
List<String> paths, { | ||
required Directory workingDirectory, | ||
}) { | ||
return CustomLintWorkspace.fromContextRoots( | ||
paths.map((path) => ContextRoot(path, [])).toList(), | ||
workingDirectory: workingDirectory, | ||
); | ||
} | ||
|
||
test( | ||
'finds pubspecs above analysis options file if there exists one', | ||
() async { | ||
final workspace = await createSimpleWorkspace(['package']); | ||
|
||
final analysisFile = File( | ||
p.join(workspace.path, 'package', 'analysis_options.yaml'), | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
analysisFile.createSync(); | ||
analysisFile.writeAsStringSync(analysisOptionsWithCustomLintEnabled); | ||
final nestedAnalysisFile = File( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
p.join(workspace.path, 'package', 'test', 'analysis_options.yaml'), | ||
); | ||
nestedAnalysisFile.createSync(recursive: true); | ||
nestedAnalysisFile | ||
.writeAsStringSync(analysisOptionsWithCustomLintEnabled); | ||
|
||
final customLintWorkspace = await CustomLintWorkspace.fromPaths( | ||
[p.join(workspace.path, 'package')], | ||
workingDirectory: workspace, | ||
); | ||
// Expect one context root for the workspace and one for the test folder | ||
expect(customLintWorkspace.contextRoots.length, equals(2)); | ||
}, | ||
); | ||
|
||
test( | ||
'throws PackageConfigParseError if package has a pubspec but no .dart_tool/package_config.json', | ||
() async { | ||
final workspace = await createSimpleWorkspace([]); | ||
workspace.dir('package').createSync(recursive: true); | ||
final workspace = await createSimpleWorkspace(['package']); | ||
workspace.dir('package', '.dart_tool').deleteSync(recursive: true); | ||
|
||
expect( | ||
() => fromContextRootsFromPaths( | ||
[p.join(workspace.path, 'package')], | ||
workingDirectory: workspace, | ||
), | ||
throwsA(isA<PubspecParseError>()), | ||
throwsA(isA<PackageConfigParseError>()), | ||
); | ||
}); | ||
|
||
test( | ||
'throws MissingPackageConfigError if package has a pubspec but no .dart_tool/package_config.json', | ||
'throws PackageConfigParseError if package has a malformed .dart_tool/package_config.json', | ||
() async { | ||
final workspace = await createSimpleWorkspace(['package']); | ||
workspace.dir('package', '.dart_tool').deleteSync(recursive: true); | ||
workspace | ||
.dir('package', '.dart_tool') | ||
.file('package_config.json') | ||
.writeAsStringSync('malformed'); | ||
|
||
expect( | ||
() => fromContextRootsFromPaths( | ||
|
@@ -2482,6 +2533,23 @@ dependency_overrides: | |
); | ||
}); | ||
|
||
test('throws PubspecParseError if package has a malformed pubspec.yaml', | ||
() async { | ||
final workspace = await createSimpleWorkspace(['package']); | ||
workspace | ||
.dir('package') | ||
.file('pubspec.yaml') | ||
.writeAsStringSync('malformed'); | ||
|
||
expect( | ||
() => fromContextRootsFromPaths( | ||
[p.join(workspace.path, 'package')], | ||
workingDirectory: workspace, | ||
), | ||
throwsA(isA<PubspecParseError>()), | ||
); | ||
}); | ||
|
||
test('Supports empty workspace', () async { | ||
final customLintWorkspace = await fromContextRootsFromPaths( | ||
[], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.