Migration: warn if the input code has unresolved imports.
The most likely cause is that the user has forgotten to run "pub get", so we suggest that as a possible fix. Fixes #40824. Change-Id: I9c627017af08f9a851cadb46be8d9bf90a64ce78 Bug: https://github.com/dart-lang/sdk/issues/40824 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/141823 Commit-Queue: Paul Berry <paulberry@google.com> Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
322280e6a8
commit
021fa0fbd4
@@ -16,6 +16,8 @@ void main() {
|
||||
bool _nnbdIsEnabled = false;
|
||||
|
||||
void defineMigrateTests() {
|
||||
final didYouForgetToRunPubGet = contains('Did you forget to run "pub get"?');
|
||||
|
||||
TestProject p;
|
||||
|
||||
tearDown(() => p?.dispose());
|
||||
@@ -67,4 +69,22 @@ void defineMigrateTests() {
|
||||
contains('not found; please provide a path to a package or directory'));
|
||||
expect(result.stdout, isEmpty);
|
||||
});
|
||||
|
||||
test('pub get needs running', () {
|
||||
p = project(mainSrc: 'import "package:foo/foo.dart";\n');
|
||||
var result = p.runSync('migrate',
|
||||
['--server-path=${p.absolutePathToAnalysisServerFile}', p.dirPath]);
|
||||
expect(result.exitCode, 1);
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(result.stdout, didYouForgetToRunPubGet);
|
||||
});
|
||||
|
||||
test('non-pub-related error', () {
|
||||
p = project(mainSrc: 'var missing = "semicolon"\n');
|
||||
var result = p.runSync('migrate',
|
||||
['--server-path=${p.absolutePathToAnalysisServerFile}', p.dirPath]);
|
||||
expect(result.exitCode, 1);
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(result.stdout, isNot(didYouForgetToRunPubGet));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -158,12 +158,14 @@ class MigrateCommand extends Command {
|
||||
fileErrors.values.map((list) => list.length).reduce((a, b) => a + b);
|
||||
logger.stdout(
|
||||
'$issueCount analysis ${pluralize('issue', issueCount)} found:');
|
||||
List<AnalysisError> allErrors = fileErrors.values
|
||||
.fold(<AnalysisError>[], (list, element) => list..addAll(element));
|
||||
_displayIssues(
|
||||
logger,
|
||||
options.directory,
|
||||
fileErrors.values
|
||||
.fold(<AnalysisError>[], (list, element) => list..addAll(element)),
|
||||
allErrors,
|
||||
);
|
||||
var importErrorCount = allErrors.where(_isUriError).length;
|
||||
|
||||
logger.stdout('');
|
||||
logger.stdout(
|
||||
@@ -172,9 +174,14 @@ class MigrateCommand extends Command {
|
||||
if (options.ignoreErrors) {
|
||||
logger.stdout('Continuing with migration suggestions due to the use of '
|
||||
'--${MigrateOptions.ignoreErrorsOption}.');
|
||||
} else if (!options.ignoreErrors) {
|
||||
} else {
|
||||
// Fail with how to continue.
|
||||
logger.stdout('');
|
||||
if (importErrorCount != 0) {
|
||||
logger.stdout(
|
||||
'Unresolved URIs found. Did you forget to run "pub get"?');
|
||||
logger.stdout('');
|
||||
}
|
||||
logger.stdout(
|
||||
'Please fix the analysis issues (or, force generation of migration '
|
||||
'suggestions by re-running with '
|
||||
@@ -371,6 +378,8 @@ the tool with --${MigrateOptions.applyChangesOption}).
|
||||
}
|
||||
}
|
||||
|
||||
bool _isUriError(AnalysisError error) => error.code == 'uri_does_not_exist';
|
||||
|
||||
/// Parse and validate the user's options; throw a UsageException if there are
|
||||
/// issues, and return an [MigrateOptions] result otherwise.
|
||||
MigrateOptions _parseAndValidateOptions() {
|
||||
|
||||
Reference in New Issue
Block a user