-
Notifications
You must be signed in to change notification settings - Fork 28.7k
[flutter_tool] New command project #102118
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
[flutter_tool] New command project #102118
Conversation
break; | ||
} | ||
|
||
buffer.write('$icon ${result.toString()}'); |
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.
nit. .toString() is unneeded, the default behavior of interpolating a non-string into a string is to call .toString()
on it anyway
buffer.write('$icon ${result.toString()}'); | |
buffer.write('$icon $result'); |
|
||
@override | ||
Future<FlutterCommandResult> runCommand() async { | ||
globals.flutterVersion.fetchTagsAndUpdate(); |
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.
why is this needed?
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.
No need. will delete it next commit
Future<FlutterCommandResult> runCommand() async { | ||
globals.flutterVersion.fetchTagsAndUpdate(); | ||
|
||
Directory workingDirectory; |
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.
nit. prefer final and you can replace the if/else with a ternary
} | ||
|
||
void presentResults(final List<ProjectValidatorResult> results) { | ||
StringBuffer buffer = StringBuffer(); |
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.
this can be final
for (ProjectValidatorResult result in results) { | ||
addToBufferResult(result, buffer); | ||
buffer.write('\n'); | ||
globals.logger.printBox(buffer.toString()); |
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.
Shouldn't you be printing the buffer outside of the for loop?
If this is a bug, can you write a test that would have caught it (for example, hard-code the expected logger output, so that we can see what it should look like)? Add it to packages/flutter_tools/test/commands.shard/hermetic/analyze_project_test.dart
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.
Yes. It should be outside, adding a test is a good idea
final String name; | ||
final String value; | ||
final String? warning; | ||
final StatusProjectValidator _status; |
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.
might as well make this public and get rid of the getter.
|
||
class ProjectValidatorResult { | ||
|
||
ProjectValidatorResult(this.name, this.value, this._status, {this.warning}); |
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.
nit. prefer named parameters when you have more than 2
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.
also, this constructor can be made const
} | ||
|
||
const List <ProjectValidator> allProjectValidators = [ | ||
// add validators |
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.
// add validators | |
// TODO(jsguerrero): add validators |
import 'analyze_project.dart'; | ||
import 'project.dart'; | ||
|
||
abstract class ProjectValidator { |
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.
Can you add dartdoc's for all the new classes you add, and any non-obvious methods? (for example .supportsProject
is self-explanatory)
Future<List<ProjectValidatorResult>> start(FlutterProject project); | ||
} | ||
|
||
const List <ProjectValidator> allProjectValidators = [ |
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.
nit. make this a static on the ProjectValidator
class. Static's are essentially global like this; however, it's a little more organized.
import '../runner/flutter_command.dart'; | ||
|
||
class ValidateProjectCommand extends FlutterCommand { | ||
ValidateProjectCommand(this.fileSystem, this.logger, {this.verbose = false}); |
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.
nit use named parameters when you have more than 2
String icon; | ||
switch(result.status) { | ||
case StatusProjectValidator.error: | ||
icon = '[X]'; |
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.
We should be consistent with the doctor and use this unicode character: https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/doctor_validator.dart#L258
break; | ||
} | ||
|
||
buffer.write('$icon $result'); |
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.
if you call buffer.writeln()
here you don't need to print an extra newline in the above scope (line 53).
buffer.write('$icon $result'); | |
buffer.writeln('$icon $result'); |
|
||
@override | ||
String toString() { | ||
if (_status == StatusProjectValidator.error) { |
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.
if you are returning early, you can un-nest the conditionals to make reading this easier:
if (_status == StatusProjectValidator.error) {
return 'Error: $value';
}
if (warning != null) {
return '$name: $value (warning: $warning)';
}
return '$name: $value';
|
||
for (final ProjectValidator validator in allProjectValidators) { | ||
if (!ranValidators.contains(validator) && validator.supportsProject(project)) { | ||
results.addAll(await validator.start(project)); |
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.
do we need to await
one before starting the next, or are these safe to run concurrently?
|
||
for (final ProjectValidator validator in allProjectValidators) { | ||
if (!ranValidators.contains(validator) && validator.supportsProject(project)) { | ||
results.addAll(await validator.start(project)); |
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.
Also, can we use a spinner like in the doctor, so that the user knows the tool is still running?
https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/doctor.dart#L341
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.
Also maybe we should catch exceptions and mark them as crashed, as we do in the doctor: https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/doctor.dart#L350
} | ||
|
||
void addToBufferResult(ProjectValidatorResult result, StringBuffer buffer) { | ||
String icon; |
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.
i think you can mark this as final
String icon; | |
final String icon; |
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.
This is coming along great. Just a few nits.
FileSystem fileSystem; | ||
|
||
group('analyze project command', () { | ||
setUpAll(() { |
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.
Don't re-use the same filesystem between tests
setUpAll(() { | |
setUp(() { |
} | ||
|
||
void main() { | ||
final BufferLogger loggerTest = BufferLogger.test(); |
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.
I'm thinking you probably shouldn't re-use the logger between tests?
'│ [✓] pass: value │\n' | ||
'│ [✗] Error: my error │\n' | ||
'│ [!] pass two: pass (warning: my warning) │\n' | ||
'│ │\n' |
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.
Can we get rid of this extra line?
/// Can return more than one result in case a file/command have a lot of info to share to the user | ||
Future<List<ProjectValidatorResult>> start(FlutterProject project); | ||
/// new ProjectValidators should be added here for the ValidateProjectCommand to run | ||
static List <ProjectValidator> allProjectValidators = <ProjectValidator>[ |
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.
static List <ProjectValidator> allProjectValidators = <ProjectValidator>[ | |
static const List <ProjectValidator> allProjectValidators = <ProjectValidator>[ |
packages/flutter_tools/test/commands.shard/hermetic/project_validator_test.dart
Show resolved
Hide resolved
packages/flutter_tools/test/commands.shard/hermetic/project_validator_test.dart
Show resolved
Hide resolved
ccc923e
to
e0e74b6
Compare
@@ -146,6 +148,12 @@ List<FlutterCommand> generateCommands({ | |||
terminal: globals.terminal, | |||
artifacts: globals.artifacts, | |||
), | |||
ValidateProjectCommand( |
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.
I don't think we should add this until it's ready to be used.
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.
LGTM!
This pull request is not suitable for automatic merging in its current state.
|
#2885
Pre-launch Checklist
///
).