Skip to content

Commit

Permalink
re-write flutter analyze (the single-shot and --flutter-repo) to use …
Browse files Browse the repository at this point in the history
…the analysis server (flutter#16281)

re-write flutter analyze (the single-shot and --flutter-repo) to use the analysis server
  • Loading branch information
devoncarew authored Apr 11, 2018
1 parent 4c22123 commit 2f41ea5
Show file tree
Hide file tree
Showing 17 changed files with 423 additions and 960 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ analyzer. There are two main ways to run it. In either case you will
want to run `flutter update-packages` first, or you will get bogus
error messages about core classes like Offset from `dart:ui`.

For a one-off, use `flutter analyze --flutter-repo`. This uses the `analysis_options_repo.yaml` file
For a one-off, use `flutter analyze --flutter-repo`. This uses the `analysis_options.yaml` file
at the root of the repository for its configuration.

For continuous analysis, use `flutter analyze --flutter-repo --watch`. This uses normal
Expand Down
7 changes: 1 addition & 6 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,18 @@
#
# There are four similar analysis options files in the flutter repos:
# - analysis_options.yaml (this file)
# - analysis_options_repo.yaml
# - packages/flutter/lib/analysis_options_user.yaml
# - https://github.com/flutter/plugins/blob/master/analysis_options.yaml
# - https://github.com/flutter/engine/blob/master/analysis_options.yaml
#
# This file contains the analysis options used by Flutter tools, such as IntelliJ,
# Android Studio, and the `flutter analyze` command.
# It is very similar to the analysis_options_repo.yaml file in this same directory;
# the only difference (currently) is the public_member_api_docs option,
# which triggers too many messages to be used in editors.
#
# The flutter/plugins repo contains a copy of this file, which should be kept
# in sync with this file.

analyzer:
language:
enableStrictCallChecks: true
enableSuperMixins: true
strong-mode:
implicit-dynamic: false
Expand Down Expand Up @@ -131,7 +127,6 @@ linter:
- prefer_is_not_empty
- prefer_single_quotes
- prefer_typing_uninitialized_variables
# - public_member_api_docs # this is the only difference from analysis_options_repo.yaml
- recursive_getters
- slash_for_doc_comments
- sort_constructors_first
Expand Down
152 changes: 0 additions & 152 deletions analysis_options_repo.yaml

This file was deleted.

8 changes: 3 additions & 5 deletions dev/bots/analyze-sample-code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ Future<Null> main() async {
}
}
buffer.add('');
buffer.add('// ignore_for_file: unused_element');
buffer.add('');
final List<Line> lines = new List<Line>.filled(buffer.length, null, growable: true);
for (Section section in sections) {
buffer.addAll(section.strings);
Expand All @@ -203,7 +205,7 @@ dependencies:
print('Found $sampleCodeSections sample code sections.');
final Process process = await Process.start(
_flutter,
<String>['analyze', '--no-preamble', mainDart.path],
<String>['analyze', '--no-preamble', '--no-congratulate', mainDart.parent.path],
workingDirectory: temp.path,
);
stderr.addStream(process.stderr);
Expand All @@ -212,10 +214,6 @@ dependencies:
errors.removeAt(0);
if (errors.first.startsWith('Running "flutter packages get" in '))
errors.removeAt(0);
if (errors.first.startsWith('Analyzing '))
errors.removeAt(0);
if (errors.last.endsWith(' issues found.') || errors.last.endsWith(' issue found.'))
errors.removeLast();
int errorCount = 0;
for (String error in errors) {
final String kBullet = Platform.isWindows ? ' - ' : ' • ';
Expand Down
21 changes: 12 additions & 9 deletions dev/devicelab/bin/tasks/dartdocs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,24 @@ Future<Null> main() async {
int publicMembers = 0;
int otherErrors = 0;
int otherLines = 0;
await for (String entry in analysis.stderr.transform(utf8.decoder).transform(const LineSplitter())) {
print('analyzer stderr: $entry');
if (entry.startsWith('[lint] Document all public members')) {
await for (String entry in analysis.stdout.transform(utf8.decoder).transform(const LineSplitter())) {
entry = entry.trim();
print('analyzer stdout: $entry');
if (entry == 'Building flutter tool...') {
// ignore this line
} else if (entry.startsWith('info • Document all public members •')) {
publicMembers += 1;
} else if (entry.startsWith('[')) {
} else if (entry.startsWith('info •') || entry.startsWith('warning •') || entry.startsWith('error •')) {
otherErrors += 1;
} else if (entry.startsWith('(Ran in ')) {
} else if (entry.contains(' (ran in ')) {
// ignore this line
} else {
} else if (entry.isNotEmpty) {
otherLines += 1;
}
}
await for (String entry in analysis.stdout.transform(utf8.decoder).transform(const LineSplitter())) {
print('analyzer stdout: $entry');
if (entry == 'Building flutter tool...') {
await for (String entry in analysis.stderr.transform(utf8.decoder).transform(const LineSplitter())) {
print('analyzer stderr: $entry');
if (entry.startsWith('[lint] ')) {
// ignore this line
} else {
otherLines += 1;
Expand Down
8 changes: 8 additions & 0 deletions packages/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Take our settings from the repo's main analysis_options.yaml file, but include
# an additional rule to validate that public members are documented.

include: ../analysis_options.yaml

linter:
rules:
- public_member_api_docs
16 changes: 8 additions & 8 deletions packages/flutter/lib/analysis_options_user.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
# See the configuration guide for more
# https://github.com/dart-lang/sdk/tree/master/pkg/analyzer#configuring-the-analyzer
#
# There are three similar analysis options files in the flutter repo:
# There are four similar analysis options files in the flutter repos:
# - analysis_options.yaml
# - analysis_options_repo.yaml
# - packages/flutter/lib/analysis_options_user.yaml (this file)
# - https://github.com/flutter/plugins/blob/master/analysis_options.yaml
# - https://github.com/flutter/engine/blob/master/analysis_options.yaml
#
# This file contains the analysis options used by "flutter analyze"
# and the dartanalyzer when analyzing code outside the flutter repository.
# It isn't named 'analysis_options.yaml' because otherwise editors like Atom
# would use it when analyzing the flutter tool itself.
# This file contains the analysis options used by "flutter analyze" and the
# dartanalyzer when analyzing code outside the flutter repository. It isn't named
# 'analysis_options.yaml' because otherwise editors would use it when analyzing
# the flutter tool itself.
#
# When editing, make sure you keep /analysis_options.yaml consistent.
# When editing, make sure you keep this and /analysis_options.yaml consistent.

analyzer:
language:
enableStrictCallChecks: true
enableSuperMixins: true
strong-mode: true
errors:
Expand Down
4 changes: 4 additions & 0 deletions packages/flutter_tools/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Use the analysis options settings from the top level of the repo (not
# the ones from above, which include the `public_member_api_docs` rule).

include: ../../analysis_options.yaml
Loading

0 comments on commit 2f41ea5

Please sign in to comment.