Skip to content

Commit 773b7ef

Browse files
authored
Skip dependency caches path in _findRoots. (#269)
1 parent d8ab55d commit 773b7ef

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

packages/custom_lint/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Unreleased patch
2+
3+
- Fixed an error in the CLI when Flutter generates code under `.dart_tool/` or has dependencies on iOS libraries (thanks to @Kurogoma4D)
4+
15
## 0.6.5 - 2024-08-15
26

37
- Upgraded to analyzer ^6.6.0.

packages/custom_lint/lib/src/workspace.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,17 @@ Iterable<String> _findRoots(String path) sync* {
425425

426426
yield* directory.listSync(recursive: true).whereType<File>().where((file) {
427427
final fileName = basename(file.path);
428-
return fileName == 'pubspec.yaml' || fileName == 'analysis_options.yaml';
428+
if (fileName != 'pubspec.yaml' && fileName != 'analysis_options.yaml') {
429+
return false;
430+
}
431+
// Check if the project has a package_config.json file.
432+
final isChildFromCache =
433+
file.uri.pathSegments.any((e) => e == '.dart_tool' || e == '.symlinks');
434+
if (isChildFromCache) {
435+
return file.parent.packageConfig.existsSync();
436+
}
437+
438+
return true;
429439
}).map((file) => file.parent.path);
430440
}
431441

packages/custom_lint/test/cli_process_test.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:io';
66

77
import 'package:custom_lint/src/output/output_format.dart';
88
import 'package:custom_lint_core/custom_lint_core.dart';
9+
import 'package:path/path.dart';
910
import 'package:test/test.dart';
1011
import 'package:test_process/test_process.dart';
1112

@@ -113,6 +114,47 @@ No issues found!
113114
expect(process.stdout, '''
114115
Analyzing...
115116
117+
No issues found!
118+
''');
119+
expect(process.exitCode, 0);
120+
});
121+
122+
test(
123+
'running on a workspace with dependencies without a package_config.json',
124+
() {
125+
final app = createLintUsage(name: 'test_app');
126+
const testDepsName = 'test_deps';
127+
const testDepsPubSpec = '''
128+
name: $testDepsName
129+
version: 0.0.1
130+
''';
131+
createTmpFolder(
132+
{
133+
'pubspec.yaml': testDepsPubSpec,
134+
},
135+
testDepsName,
136+
parent: Directory(join(app.path, '.dart_tool')),
137+
);
138+
createTmpFolder(
139+
{
140+
join('.symlinks', 'plugins', 'pubspec.yaml'): testDepsPubSpec,
141+
},
142+
'ios',
143+
parent: app,
144+
);
145+
146+
final process = Process.runSync(
147+
'dart',
148+
[customLintBinPath],
149+
workingDirectory: app.path,
150+
stdoutEncoding: utf8,
151+
stderrEncoding: utf8,
152+
);
153+
154+
expect(trimDependencyOverridesWarning(process.stderr), isEmpty);
155+
expect(process.stdout, '''
156+
Analyzing...
157+
116158
No issues found!
117159
''');
118160
expect(process.exitCode, 0);

0 commit comments

Comments
 (0)