-
Notifications
You must be signed in to change notification settings - Fork 29.7k
update flutter analyze to call dartanalyzer #8808
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
update flutter analyze to call dartanalyzer #8808
Conversation
| // Use dartanalyzer directly when possible | ||
| if (!flutterRepo) { | ||
| final String dartanalyzer = fs.path.join( | ||
| Cache.flutterRoot, 'bin', 'cache', 'dart-sdk', 'bin', 'dartanalyzer'); |
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: newline before ) since there was a newline after the (
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.
Fixed.
|
|
||
| if (cmd.length < 2 || currentPackage) { | ||
| final Directory projDir = await projectDirFor(fs.currentDirectory.absolute); | ||
| if (projDir != null) { |
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: no braces around one-line statements
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.
Fixed.
| if (cmd.length < 2 || currentPackage) { | ||
| final Directory projDir = await projectDirFor(fs.currentDirectory.absolute); | ||
| if (projDir != null) { | ||
| cmd.add((projDir).path); |
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: i think the inner parentheses are redundant here?
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.
Artifact of refactoring tools. Removed.
| if (!flutterRepo) { | ||
| final String dartanalyzer = fs.path.join( | ||
| Cache.flutterRoot, 'bin', 'cache', 'dart-sdk', 'bin', 'dartanalyzer'); | ||
| final List<String> cmd = <String>[dartanalyzer]; |
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: please don't use abbreviations for variable names.
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.
Renamed cmd to arguments. Hopefully that's more clear.
| final List<String> cmd = <String>[dartanalyzer]; | ||
| cmd.addAll(dartFiles.map((FileSystemEntity f) => f.path)); | ||
|
|
||
| if (cmd.length < 2 || currentPackage) { |
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 got a bit confused reading this, in part because I was reading "cmd" as "our command line" as opposed to "the command line we are building", and in part because it took me a while to realise that "< 2" was equivalent to "nothing got added in the previous step, and so there's one entry, the analyzer itself".
I suggest adding the path to the analyzer after all this work of adding the files to be analyzed (inserting at index 0). That would let you change this from length < 2 to isEmpty which I think would be clearer.
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 like that approach. Done.
| cmd.addAll(dartFiles.map((FileSystemEntity f) => f.path)); | ||
|
|
||
| if (cmd.length < 2 || currentPackage) { | ||
| final Directory projDir = await projectDirFor(fs.currentDirectory.absolute); |
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: no abbreviations
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.
Fixed.
| } | ||
|
|
||
| final bool currentDirectory = argResults['current-directory'] && (argResults.wasParsed('current-directory') || dartFiles.isEmpty); | ||
| final bool currentPackage = argResults['current-package'] && (argResults.wasParsed('current-package') || dartFiles.isEmpty); |
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 we should remove --current-directory in this patch. This would simplify the logic here and is consistent with the long term plan in #7274.
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.
Makes sense. Done.
| if (projDir != null) { | ||
| cmd.add((projDir).path); | ||
| } | ||
| } else if (currentDirectory) { |
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.
imho we should remove this here and just let people use . if they want this.
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.
Removed.
| } | ||
| } else if (currentDirectory) { | ||
| cmd.add('.'); | ||
| } else if (!cmd[1].startsWith(fs.currentDirectory.path)) { |
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 understand what this is doing. Why does the path of the first command line argument matter?
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 is path guaranteed to end in a separator?
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 the files being analyzed are outside of the current directory hierarchy then dartanalyzer does not yet know how to find the
.packagesfile. I'll add a comment to that effect. -
Hmm... not sure. Modified the code to ensure that it does.
| stopwatch.stop(); | ||
| final String elapsed = (stopwatch.elapsedMilliseconds / 1000.0).toStringAsFixed(1); | ||
| if (exitCode != 0) | ||
| throwToolExit('(Ran in ${elapsed}s)'); |
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.
propagate the exit code?
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.
Good idea. Done.
| if (isDartFile(entry)) { | ||
| dartFiles.add(entry); | ||
| foundOne = true; | ||
| // Use dartanalyzer directly when possible |
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 comment should elaborate on why it's not possible if flutterRepo is true.
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.
Good point. Done.
| } | ||
| } | ||
|
|
||
| Future<Directory> projectDirFor(FileSystemEntity entity) async { |
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: no abbreviations (several cases in this method including the method name)
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.
Renamed to projectDirectoryContaining.
| else | ||
| throwToolExit('(Ran in ${elapsed}s)'); | ||
| } | ||
| if (argResults['congratulate']) { |
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.
Update the docs to mention that congratulate will be ignored if you're not using either --watch or --flutter-repo?
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.
Help text updated.
| // Use dartanalyzer directly except when analyzing the Flutter repository. | ||
| // Analyzing the repository requires a more complex report than dartanalyzer | ||
| // currently supports (e.g. missing member dartdoc summary). | ||
| // TODO(danrubel) enhance dartanalyzer to provide this type of summary |
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: missing color after TODO(danrubel)
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.
Fixed.
| final List<String> arguments = <String>[]; | ||
| arguments.addAll(dartFiles.map((FileSystemEntity f) => f.path)); | ||
|
|
||
| if (arguments.length < 1 || currentPackage) { |
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.
arguments.length < 1 is better written arguments.isEmpty
Amusingly this is a creative-enough way to write isEmpty that the lint that looks for this kind of thing didn't catch it. :-)
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.
Fixed.
| final Directory projDir = await projectDirectoryContaining(target); | ||
| if (projDir != null) { | ||
| final String packagesPath = fs.path.join(projDir.path, '.packages'); | ||
| if (packagesPath != null) { |
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.
how can it be null?
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.
Heh. Left over from refactoring. Removed null check.
| final String targetPath = arguments[0]; | ||
| final FileSystemEntity target = await fs.isDirectory(targetPath) | ||
| ? fs.directory(targetPath) : fs.file(targetPath); | ||
| final Directory projDir = await projectDirectoryContaining(target); |
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: projDir is two abbreviations
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.
Missed that one when renaming. Fixed.
| // In this situation, use the first file as a starting point | ||
| // to search for a "pubspec.yaml" and ".packages" file. | ||
| // TODO(danrubel): fix dartanalyzer to find the .packages file | ||
| if (!arguments[0].startsWith(currentDirectoryPath)) { |
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 we should explicitly check that all the files would find the same .packages (or all would find no .packages?), and exit with a message saying that we don't yet support checking multiple packages at once if you're not also checking the flutter repo. I've definitely run into the case where I've tried to use flutter analyze to analyze two packages at once (an app I was working on and the support library I was writing for the app), and it would be massively confusing if that did something different depending on the order in which the paths were listed.
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.
Good point. I simplified the code to always pass in the .packages file path and report an error as you suggested.
| toolExit: 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.
nice test!
| '[lint] Only throw instances of classes extending either Exception or Error', | ||
| '1 warning and 1 lint found.', | ||
| ], | ||
| // TODO(danrubel) fix dartanalyzer to have non-zero exit code |
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 make sure to fix this asap because anyone depending on flutter analyze in their build bots will be skewered by this regression.
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 updated this functionality to work around this issue so that flutter analyze will return a non-zero exit code even though dartanalyzer never does.
| // Not used by analyze --watch | ||
| argParser.addFlag('congratulate', help: 'Show output even when there are no errors, warnings, hints, or lints.', defaultsTo: true); | ||
| argParser.addFlag('congratulate', help: 'When analyzing the flutter repository, show output even when there are no errors, warnings, hints, or lints.', defaultsTo: true); | ||
| argParser.addFlag('preamble', help: 'Display the number of files that will be analyzed.', defaultsTo: true); |
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.
looks like this also only works with --flutter-repo now
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.
Good point. Help text updated.
| await createTestCommandRunner(command).run(arguments); | ||
| expect(toolExit, isFalse, reason: 'Expected ToolExit exception'); | ||
| } on ToolExit catch (e) { | ||
| } on ToolExit catch (_) { |
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.
You can just remove the "catch" clause entirely (just } on ToolExit {)
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.
Done.
| class AnalyzeCommand extends FlutterCommand { | ||
| AnalyzeCommand({bool verboseHelp: false}) { | ||
| /// The working directory for testing analysis using dartanalyzer. | ||
| final 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: constructor first
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.
Fixed.
| /// The working directory for testing analysis using dartanalyzer | ||
| final Directory workingDirectory; | ||
|
|
||
| AnalyzeOnce(ArgResults argResults, this.repoPackages, { this.workingDirectory }) : super(argResults); |
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: constructors first please
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.
Sorry. Fixed.
* update platform_channel package name * lowercase name
…to the same TabBarController (flutter#9015)
* adds border radius to ink widgets. sets default ink border radius for material buttons with no background colors * tidying up code * add ink test stub * remove unused import
…ivity in FlutterActivity (flutter#9036)
…gmentActivity in FlutterActivity (flutter#9036)" (flutter#9041) This reverts commit 6bf0ceb.
…e of FragmentActivity in FlutterActivity (flutter#9036)"" (flutter#9046) Increased the time limit slightly to allow the microbenchmark test time to finish.
…allow use of FragmentActivity in FlutterActivity (flutter#9036)"" (flutter#9046)" (flutter#9047) Test is still failing with increased timeout. This reverts commit 864b3c3.
We now use modern scrolling machinery and patterns. The API should also be easier to maintain over time. Fixes flutter#6166 Fixes flutter#2591 Fixes flutter#3123
…el/flutter into flutter-analyze-call-dartanalyzer
|
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
|
So.... this is what happens when I rebase and push. |
|
Closing this in favor of the identical PR... #9049 |
Now that
dartanalyzeruses the default Flutter analysis options (package:flutter/analysis_options_user.yaml) to analyze a flutter project,and a Dart SDK containing this functionality has rolled into Flutter...
Update
flutter analyzeto usedartanalyzerfor everything except analyzing the flutter repository.flutter analyzeflutter analyzealways delegate todartanalyzerso that flutter tools might someday not be tightly coupled to analyzer
@Hixie