Skip to content

Commit 0714852

Browse files
authored
Revert "re-write flutter analyze (the single-shot and --flutter-repo) to use the analysis server (flutter#16281)" (flutter#16482)
This reverts commit 2f41ea5.
1 parent 2f41ea5 commit 0714852

17 files changed

+960
-423
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ analyzer. There are two main ways to run it. In either case you will
7979
want to run `flutter update-packages` first, or you will get bogus
8080
error messages about core classes like Offset from `dart:ui`.
8181

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

8585
For continuous analysis, use `flutter analyze --flutter-repo --watch`. This uses normal

analysis_options.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,22 @@
99
#
1010
# There are four similar analysis options files in the flutter repos:
1111
# - analysis_options.yaml (this file)
12+
# - analysis_options_repo.yaml
1213
# - packages/flutter/lib/analysis_options_user.yaml
1314
# - https://github.com/flutter/plugins/blob/master/analysis_options.yaml
14-
# - https://github.com/flutter/engine/blob/master/analysis_options.yaml
1515
#
1616
# This file contains the analysis options used by Flutter tools, such as IntelliJ,
1717
# Android Studio, and the `flutter analyze` command.
18+
# It is very similar to the analysis_options_repo.yaml file in this same directory;
19+
# the only difference (currently) is the public_member_api_docs option,
20+
# which triggers too many messages to be used in editors.
1821
#
1922
# The flutter/plugins repo contains a copy of this file, which should be kept
2023
# in sync with this file.
2124

2225
analyzer:
2326
language:
27+
enableStrictCallChecks: true
2428
enableSuperMixins: true
2529
strong-mode:
2630
implicit-dynamic: false
@@ -127,6 +131,7 @@ linter:
127131
- prefer_is_not_empty
128132
- prefer_single_quotes
129133
- prefer_typing_uninitialized_variables
134+
# - public_member_api_docs # this is the only difference from analysis_options_repo.yaml
130135
- recursive_getters
131136
- slash_for_doc_comments
132137
- sort_constructors_first

analysis_options_repo.yaml

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Specify analysis options.
2+
#
3+
# Until there are meta linter rules, each desired lint must be explicitly enabled.
4+
# See: https://github.com/dart-lang/linter/issues/288
5+
#
6+
# For a list of lints, see: http://dart-lang.github.io/linter/lints/
7+
# See the configuration guide for more
8+
# https://github.com/dart-lang/sdk/tree/master/pkg/analyzer#configuring-the-analyzer
9+
#
10+
# There are three similar analysis options files in the flutter repo:
11+
# - analysis_options.yaml
12+
# - analysis_options_repo.yaml (this file)
13+
# - packages/flutter/lib/analysis_options_user.yaml
14+
#
15+
# This file contains the analysis options used by 'flutter analyze' when analyzing
16+
# the flutter repository. It is very similar to analysis_options.yaml;
17+
# the only difference (currently) is the public_member_api_docs option,
18+
# which is turned on and programmatically reduced to a single output line
19+
# indicating the # of violations for that rule.
20+
21+
analyzer:
22+
language:
23+
enableStrictCallChecks: true
24+
enableSuperMixins: true
25+
strong-mode:
26+
implicit-dynamic: false
27+
errors:
28+
# treat missing required parameters as a warning (not a hint)
29+
missing_required_param: warning
30+
# treat missing returns as a warning (not a hint)
31+
missing_return: warning
32+
# allow having TODOs in the code
33+
todo: ignore
34+
# `flutter analyze` (without `--watch`) just ignores directories
35+
# that contain a .dartignore file, and this file does not have any
36+
# effect on what files are actually analyzed.
37+
38+
linter:
39+
rules:
40+
# these rules are documented on and in the same order as
41+
# the Dart Lint rules page to make maintenance easier
42+
# https://github.com/dart-lang/linter/blob/master/example/all.yaml
43+
- always_declare_return_types
44+
- always_put_control_body_on_new_line
45+
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
46+
- always_require_non_null_named_parameters
47+
- always_specify_types
48+
- annotate_overrides
49+
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
50+
- avoid_as
51+
# - avoid_bool_literals_in_conditional_expressions # not yet tested
52+
# - avoid_catches_without_on_clauses # we do this commonly
53+
# - avoid_catching_errors # we do this commonly
54+
- avoid_classes_with_only_static_members
55+
- avoid_empty_else
56+
- avoid_function_literals_in_foreach_calls
57+
- avoid_init_to_null
58+
- avoid_null_checks_in_equality_operators
59+
# - avoid_positional_boolean_parameters # not yet tested
60+
# - avoid_private_typedef_functions # not yet tested
61+
- avoid_relative_lib_imports
62+
- avoid_renaming_method_parameters
63+
- avoid_return_types_on_setters
64+
# - avoid_returning_null # we do this commonly
65+
# - avoid_returning_this # https://github.com/dart-lang/linter/issues/842
66+
# - avoid_setters_without_getters # not yet tested
67+
# - avoid_single_cascade_in_expression_statements # not yet tested
68+
- avoid_slow_async_io
69+
# - avoid_types_as_parameter_names # https://github.com/dart-lang/linter/pull/954/files
70+
# - avoid_types_on_closure_parameters # conflicts with always_specify_types
71+
# - avoid_unused_constructor_parameters # https://github.com/dart-lang/linter/pull/847
72+
- await_only_futures
73+
- camel_case_types
74+
- cancel_subscriptions
75+
# - cascade_invocations # not yet tested
76+
# - close_sinks # https://github.com/flutter/flutter/issues/5789
77+
# - comment_references # blocked on https://github.com/dart-lang/dartdoc/issues/1153
78+
# - constant_identifier_names # https://github.com/dart-lang/linter/issues/204
79+
- control_flow_in_finally
80+
- directives_ordering
81+
- empty_catches
82+
- empty_constructor_bodies
83+
- empty_statements
84+
- hash_and_equals
85+
- implementation_imports
86+
# - invariant_booleans # https://github.com/flutter/flutter/issues/5790
87+
- iterable_contains_unrelated_type
88+
# - join_return_with_assignment # not yet tested
89+
- library_names
90+
- library_prefixes
91+
- list_remove_unrelated_type
92+
# - literal_only_boolean_expressions # https://github.com/flutter/flutter/issues/5791
93+
- no_adjacent_strings_in_list
94+
- no_duplicate_case_values
95+
- non_constant_identifier_names
96+
# - omit_local_variable_types # opposite of always_specify_types
97+
# - one_member_abstracts # too many false positives
98+
# - only_throw_errors # https://github.com/flutter/flutter/issues/5792
99+
- overridden_fields
100+
- package_api_docs
101+
- package_names
102+
- package_prefixed_library_names
103+
# - parameter_assignments # we do this commonly
104+
- prefer_adjacent_string_concatenation
105+
- prefer_asserts_in_initializer_lists
106+
- prefer_bool_in_asserts
107+
- prefer_collection_literals
108+
- prefer_conditional_assignment
109+
- prefer_const_constructors
110+
- prefer_const_constructors_in_immutables
111+
- prefer_const_declarations
112+
- prefer_const_literals_to_create_immutables
113+
# - prefer_constructors_over_static_methods # not yet tested
114+
- prefer_contains
115+
# - prefer_equal_for_default_values # not yet tested
116+
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
117+
- prefer_final_fields
118+
- prefer_final_locals
119+
- prefer_foreach
120+
# - prefer_function_declarations_over_variables # not yet tested
121+
- prefer_initializing_formals
122+
# - prefer_interpolation_to_compose_strings # not yet tested
123+
- prefer_is_empty
124+
- prefer_is_not_empty
125+
- prefer_single_quotes
126+
- prefer_typing_uninitialized_variables
127+
- public_member_api_docs # this is the only difference from analysis_options.yaml
128+
- recursive_getters
129+
- slash_for_doc_comments
130+
- sort_constructors_first
131+
- sort_unnamed_constructors_first
132+
- super_goes_last
133+
- test_types_in_equals
134+
- throw_in_finally
135+
# - type_annotate_public_apis # subset of always_specify_types
136+
- type_init_formals
137+
# - unawaited_futures # https://github.com/flutter/flutter/issues/5793
138+
- unnecessary_brace_in_string_interps
139+
- unnecessary_getters_setters
140+
# - unnecessary_lambdas # https://github.com/dart-lang/linter/issues/498
141+
- unnecessary_null_aware_assignments
142+
- unnecessary_null_in_if_null_operators
143+
- unnecessary_overrides
144+
- unnecessary_parenthesis
145+
# - unnecessary_statements # not yet tested
146+
- unnecessary_this
147+
- unrelated_type_equality_checks
148+
- use_rethrow_when_possible
149+
# - use_setters_to_change_properties # not yet tested
150+
# - use_string_buffers # https://github.com/dart-lang/linter/pull/664
151+
# - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
152+
- valid_regexps

dev/bots/analyze-sample-code.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,6 @@ Future<Null> main() async {
185185
}
186186
}
187187
buffer.add('');
188-
buffer.add('// ignore_for_file: unused_element');
189-
buffer.add('');
190188
final List<Line> lines = new List<Line>.filled(buffer.length, null, growable: true);
191189
for (Section section in sections) {
192190
buffer.addAll(section.strings);
@@ -205,7 +203,7 @@ dependencies:
205203
print('Found $sampleCodeSections sample code sections.');
206204
final Process process = await Process.start(
207205
_flutter,
208-
<String>['analyze', '--no-preamble', '--no-congratulate', mainDart.parent.path],
206+
<String>['analyze', '--no-preamble', mainDart.path],
209207
workingDirectory: temp.path,
210208
);
211209
stderr.addStream(process.stderr);
@@ -214,6 +212,10 @@ dependencies:
214212
errors.removeAt(0);
215213
if (errors.first.startsWith('Running "flutter packages get" in '))
216214
errors.removeAt(0);
215+
if (errors.first.startsWith('Analyzing '))
216+
errors.removeAt(0);
217+
if (errors.last.endsWith(' issues found.') || errors.last.endsWith(' issue found.'))
218+
errors.removeLast();
217219
int errorCount = 0;
218220
for (String error in errors) {
219221
final String kBullet = Platform.isWindows ? ' - ' : ' • ';

dev/devicelab/bin/tasks/dartdocs.dart

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,21 @@ Future<Null> main() async {
2121
int publicMembers = 0;
2222
int otherErrors = 0;
2323
int otherLines = 0;
24-
await for (String entry in analysis.stdout.transform(utf8.decoder).transform(const LineSplitter())) {
25-
entry = entry.trim();
26-
print('analyzer stdout: $entry');
27-
if (entry == 'Building flutter tool...') {
28-
// ignore this line
29-
} else if (entry.startsWith('info • Document all public members •')) {
24+
await for (String entry in analysis.stderr.transform(utf8.decoder).transform(const LineSplitter())) {
25+
print('analyzer stderr: $entry');
26+
if (entry.startsWith('[lint] Document all public members')) {
3027
publicMembers += 1;
31-
} else if (entry.startsWith('info •') || entry.startsWith('warning •') || entry.startsWith('error •')) {
28+
} else if (entry.startsWith('[')) {
3229
otherErrors += 1;
33-
} else if (entry.contains(' (ran in ')) {
30+
} else if (entry.startsWith('(Ran in ')) {
3431
// ignore this line
35-
} else if (entry.isNotEmpty) {
32+
} else {
3633
otherLines += 1;
3734
}
3835
}
39-
await for (String entry in analysis.stderr.transform(utf8.decoder).transform(const LineSplitter())) {
40-
print('analyzer stderr: $entry');
41-
if (entry.startsWith('[lint] ')) {
36+
await for (String entry in analysis.stdout.transform(utf8.decoder).transform(const LineSplitter())) {
37+
print('analyzer stdout: $entry');
38+
if (entry == 'Building flutter tool...') {
4239
// ignore this line
4340
} else {
4441
otherLines += 1;

packages/analysis_options.yaml

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/flutter/lib/analysis_options_user.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77
# See the configuration guide for more
88
# https://github.com/dart-lang/sdk/tree/master/pkg/analyzer#configuring-the-analyzer
99
#
10-
# There are four similar analysis options files in the flutter repos:
10+
# There are three similar analysis options files in the flutter repo:
1111
# - analysis_options.yaml
12+
# - analysis_options_repo.yaml
1213
# - packages/flutter/lib/analysis_options_user.yaml (this file)
13-
# - https://github.com/flutter/plugins/blob/master/analysis_options.yaml
14-
# - https://github.com/flutter/engine/blob/master/analysis_options.yaml
1514
#
16-
# This file contains the analysis options used by "flutter analyze" and the
17-
# dartanalyzer when analyzing code outside the flutter repository. It isn't named
18-
# 'analysis_options.yaml' because otherwise editors would use it when analyzing
19-
# the flutter tool itself.
15+
# This file contains the analysis options used by "flutter analyze"
16+
# and the dartanalyzer when analyzing code outside the flutter repository.
17+
# It isn't named 'analysis_options.yaml' because otherwise editors like Atom
18+
# would use it when analyzing the flutter tool itself.
2019
#
21-
# When editing, make sure you keep this and /analysis_options.yaml consistent.
20+
# When editing, make sure you keep /analysis_options.yaml consistent.
2221

2322
analyzer:
2423
language:
24+
enableStrictCallChecks: true
2525
enableSuperMixins: true
2626
strong-mode: true
2727
errors:

packages/flutter_tools/analysis_options.yaml

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)