Add a diagnostic message for malformed imports in analyze.dart (#38355)

This commit is contained in:
LongCatIsLooong 2020-01-09 10:25:58 -08:00 committed by GitHub
parent 1df6e2af5d
commit d291de086c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -435,6 +435,22 @@ Future<void> verifyNoBadImportsInFlutter(String workingDirectory) async {
); );
} }
} }
for (final String key in dependencyMap.keys) {
for (final String dependency in dependencyMap[key]) {
if (dependencyMap[dependency] != null)
continue;
// Sanity check before performing _deepSearch, to ensure there's no rogue
// dependencies.
final String validFilenames = dependencyMap.keys.map((String name) => name + '.dart').join(', ');
errors.add(
'$key imported package:flutter/$dependency.dart '
'which is not one of the valid exports { $validFilenames }.\n'
'Consider changing $dependency.dart to one of them.'
);
}
}
for (final String package in dependencyMap.keys) { for (final String package in dependencyMap.keys) {
final List<String> loop = _deepSearch<String>(dependencyMap, package); final List<String> loop = _deepSearch<String>(dependencyMap, package);
if (loop != null) { if (loop != null) {
@ -1180,6 +1196,9 @@ Set<String> _findFlutterDependencies(String srcPath, List<String> errors, { bool
} }
List<T> _deepSearch<T>(Map<T, Set<T>> map, T start, [ Set<T> seen ]) { List<T> _deepSearch<T>(Map<T, Set<T>> map, T start, [ Set<T> seen ]) {
if (map[start] == null)
return null; // We catch these separately.
for (final T key in map[start]) { for (final T key in map[start]) {
if (key == start) if (key == start)
continue; // we catch these separately continue; // we catch these separately