Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1d7f790

Browse files
authored
Sync analyzer_options.yaml (#25129)
1 parent b5e15d0 commit 1d7f790

21 files changed

+155
-84
lines changed

analysis_options.yaml

Lines changed: 102 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
# Specify analysis options.
22
#
3-
# This file is a copy of analysis_options_repo.yaml from flutter repo
4-
# as of 2018-05-30, but with:
3+
# This file is a copy of analysis_options.yaml from flutter repo
4+
# as of 2021-03-19, but with:
55
# - "always_require_non_null_named_parameters" disabled (because we
6-
# can't import the meta package from the SDK), and
6+
# can't import the meta package from the SDK),
7+
# - "avoid_equals_and_hash_code_on_mutable_classes" disabled (same reason),
8+
# - "missing_whitespace_between_adjacent_strings" disabled (too many false
9+
# positives),
710
# - "sort_constructors_first" disabled (because we have private fake
811
# constructors),
912
# - "prefer_final_fields" disabled (because we do weird things with
10-
# private fields, especially on the PlatformDispatcher object):
13+
# private fields, especially on the PlatformDispatcher object),
14+
# - "public_member_api_docs" enabled.
1115

1216
analyzer:
13-
enable-experiment:
14-
- non-nullable
1517
exclude: [
1618
# this test pretends to be part of dart:ui and results in lots of false
1719
# positives.
@@ -32,9 +34,8 @@ analyzer:
3234
todo: ignore
3335
# allow dart:ui to import dart:_internal
3436
import_internal_library: ignore
35-
# `flutter analyze` (without `--watch`) just ignores directories
36-
# that contain a .dartignore file, and this file does not have any
37-
# effect on what files are actually analyzed.
37+
# Turned off until null-safe rollout is complete.
38+
unnecessary_null_comparison: ignore
3839

3940
linter:
4041
rules:
@@ -44,56 +45,89 @@ linter:
4445
- always_declare_return_types
4546
- always_put_control_body_on_new_line
4647
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
47-
# always_require_non_null_named_parameters # DIFFERENT FROM FLUTTER/FLUTTER
48+
# - always_require_non_null_named_parameters # DIFFERENT FROM FLUTTER/FLUTTER
4849
- always_specify_types
50+
# - always_use_package_imports # we do this commonly
4951
- annotate_overrides
5052
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
51-
# - avoid_as # required for implicit-casts: false
52-
# - avoid_bool_literals_in_conditional_expressions # not yet tested
53+
- avoid_bool_literals_in_conditional_expressions
5354
# - avoid_catches_without_on_clauses # we do this commonly
5455
# - avoid_catching_errors # we do this commonly
5556
- avoid_classes_with_only_static_members # We want to avoid classes that can be instantiated but only have statics
57+
# - avoid_double_and_int_checks # only useful when targeting JS runtime
58+
# - avoid_dynamic_calls # not yet tested
5659
- avoid_empty_else
60+
# - avoid_equals_and_hash_code_on_mutable_classes # DIFFERENT FROM FLUTTER/FLUTTER
61+
# - avoid_escaping_inner_quotes # not yet tested
62+
- avoid_field_initializers_in_const_classes
5763
- avoid_function_literals_in_foreach_calls
64+
# - avoid_implementing_value_types # not yet tested
5865
- avoid_init_to_null
66+
# - avoid_js_rounded_ints # only useful when targeting JS runtime
5967
- avoid_null_checks_in_equality_operators
6068
# - avoid_positional_boolean_parameters # not yet tested
69+
# - avoid_print # not yet tested
6170
# - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
71+
# - avoid_redundant_argument_values # not yet tested
6272
- avoid_relative_lib_imports
6373
- avoid_renaming_method_parameters
6474
- avoid_return_types_on_setters
65-
# - avoid_returning_null # we do this commonly
66-
# - avoid_returning_this # https://github.com/dart-lang/linter/issues/842
75+
# - avoid_returning_null # there are plenty of valid reasons to return null
76+
# - avoid_returning_null_for_future # not yet tested
77+
- avoid_returning_null_for_void
78+
# - avoid_returning_this # there are plenty of valid reasons to return this
6779
# - avoid_setters_without_getters # not yet tested
68-
# - avoid_single_cascade_in_expression_statements # not yet tested
80+
- avoid_shadowing_type_parameters
81+
- avoid_single_cascade_in_expression_statements
6982
- avoid_slow_async_io
70-
# - avoid_types_as_parameter_names # https://github.com/dart-lang/linter/pull/954/files
83+
- avoid_type_to_string
84+
- avoid_types_as_parameter_names
7185
# - avoid_types_on_closure_parameters # conflicts with always_specify_types
72-
# - avoid_unused_constructor_parameters # https://github.com/dart-lang/linter/pull/847
86+
- avoid_unnecessary_containers
87+
- avoid_unused_constructor_parameters
88+
- avoid_void_async
89+
# - avoid_web_libraries_in_flutter # not yet tested
7390
- await_only_futures
91+
- camel_case_extensions
7492
- camel_case_types
7593
- cancel_subscriptions
7694
# - cascade_invocations # not yet tested
77-
# - close_sinks # https://github.com/flutter/flutter/issues/5789
78-
# - comment_references # blocked on https://github.com/dart-lang/dartdoc/issues/1153
79-
# - constant_identifier_names # https://github.com/dart-lang/linter/issues/204
95+
- cast_nullable_to_non_nullable
96+
# - close_sinks # not reliable enough
97+
# - comment_references # blocked on https://github.com/dart-lang/linter/issues/1142
98+
# - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204
8099
- control_flow_in_finally
100+
# - curly_braces_in_flow_control_structures # not required by flutter style
101+
- deprecated_consistency
102+
# - diagnostic_describe_all_properties # not yet tested
81103
- directives_ordering
104+
# - do_not_use_environment # we do this commonly
82105
- empty_catches
83106
- empty_constructor_bodies
84107
- empty_statements
108+
- exhaustive_cases
109+
- file_names
110+
- flutter_style_todos
85111
- hash_and_equals
86112
- implementation_imports
87-
# - invariant_booleans # https://github.com/flutter/flutter/issues/5790
113+
# - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811
88114
- iterable_contains_unrelated_type
89-
# - join_return_with_assignment # not yet tested
115+
# - join_return_with_assignment # not required by flutter style
116+
- leading_newlines_in_multiline_strings
90117
- library_names
91118
- library_prefixes
119+
# - lines_longer_than_80_chars # not required by flutter style
92120
- list_remove_unrelated_type
93-
# - literal_only_boolean_expressions # https://github.com/flutter/flutter/issues/5791
121+
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181
122+
# - missing_whitespace_between_adjacent_strings # DIFFERENT FROM FLUTTER/FLUTTER
94123
- no_adjacent_strings_in_list
124+
# - no_default_cases # too many false positives
95125
- no_duplicate_case_values
126+
- no_logic_in_create_state
127+
# - no_runtimeType_toString # ok in tests; we enable this only in packages/
96128
- non_constant_identifier_names
129+
- null_check_on_nullable_type_parameter
130+
- null_closures
97131
# - omit_local_variable_types # opposite of always_specify_types
98132
# - one_member_abstracts # too many false positives
99133
# - only_throw_errors # https://github.com/flutter/flutter/issues/5792
@@ -104,51 +138,88 @@ linter:
104138
# - parameter_assignments # we do this commonly
105139
- prefer_adjacent_string_concatenation
106140
- prefer_asserts_in_initializer_lists
141+
# - prefer_asserts_with_message # not required by flutter style
107142
- prefer_collection_literals
108143
- prefer_conditional_assignment
109144
- prefer_const_constructors
110145
- prefer_const_constructors_in_immutables
111146
- prefer_const_declarations
112147
- prefer_const_literals_to_create_immutables
113-
# - prefer_constructors_over_static_methods # not yet tested
148+
# - prefer_constructors_over_static_methods # far too many false positives
114149
- prefer_contains
150+
# - prefer_double_quotes # opposite of prefer_single_quotes
115151
- prefer_equal_for_default_values
116152
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
117153
# - prefer_final_fields # DIFFERENT FROM FLUTTER/FLUTTER
154+
- prefer_final_in_for_each
118155
- prefer_final_locals
156+
- prefer_for_elements_to_map_fromIterable
119157
- prefer_foreach
120-
# - prefer_function_declarations_over_variables # not yet tested
158+
- prefer_function_declarations_over_variables
121159
- prefer_generic_function_type_aliases
160+
- prefer_if_elements_to_conditional_expressions
161+
- prefer_if_null_operators
122162
- prefer_initializing_formals
123-
# - prefer_interpolation_to_compose_strings # not yet tested
163+
- prefer_inlined_adds
164+
# - prefer_int_literals # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#use-double-literals-for-double-constants
165+
# - prefer_interpolation_to_compose_strings # doesn't work with raw strings, see https://github.com/dart-lang/linter/issues/2490
124166
- prefer_is_empty
125167
- prefer_is_not_empty
168+
- prefer_is_not_operator
169+
- prefer_iterable_whereType
170+
# - prefer_mixin # https://github.com/dart-lang/language/issues/32
171+
- prefer_null_aware_operators
172+
# - prefer_relative_imports # incompatible with sub-package imports
126173
- prefer_single_quotes
174+
- prefer_spread_collections
127175
- prefer_typing_uninitialized_variables
128-
- public_member_api_docs # this is the only difference from analysis_options.yaml
176+
- prefer_void_to_null
177+
- provide_deprecation_message
178+
- public_member_api_docs # DIFFERENT FROM FLUTTER/FLUTTER
129179
- recursive_getters
180+
- sized_box_for_whitespace
130181
- slash_for_doc_comments
182+
# - sort_child_properties_last # not yet tested
131183
# - sort_constructors_first # DIFFERENT FROM FLUTTER/FLUTTER
184+
# - sort_pub_dependencies # prevents separating pinned transitive dependencies
132185
- sort_unnamed_constructors_first
133186
- test_types_in_equals
134187
- throw_in_finally
188+
- tighten_type_of_initializing_formals
135189
# - type_annotate_public_apis # subset of always_specify_types
136190
- type_init_formals
137-
# - unawaited_futures # https://github.com/flutter/flutter/issues/5793
191+
# - unawaited_futures # too many false positives
192+
- unnecessary_await_in_return
138193
- unnecessary_brace_in_string_interps
139194
- unnecessary_const
195+
# - unnecessary_final # conflicts with prefer_final_locals
140196
- unnecessary_getters_setters
141-
# - unnecessary_lambdas # https://github.com/dart-lang/linter/issues/498
197+
# - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
142198
- unnecessary_new
143199
- unnecessary_null_aware_assignments
200+
# - unnecessary_null_checks # not yet tested
144201
- unnecessary_null_in_if_null_operators
202+
- unnecessary_nullable_for_final_variable_declarations
145203
- unnecessary_overrides
146204
- unnecessary_parenthesis
147-
# - unnecessary_statements # not yet tested
205+
# - unnecessary_raw_strings # not yet tested
206+
- unnecessary_statements
207+
- unnecessary_string_escapes
208+
- unnecessary_string_interpolations
148209
- unnecessary_this
149210
- unrelated_type_equality_checks
211+
# - unsafe_html # not yet tested
212+
- use_full_hex_values_for_flutter_colors
213+
- use_function_type_syntax_for_parameters
214+
# - use_if_null_to_convert_nulls_to_bools # not yet tested
215+
- use_is_even_rather_than_modulo
216+
- use_key_in_widget_constructors
217+
# - use_late_for_private_fields_and_variables # not yet tested
218+
# - use_named_constants # not yet tested
219+
- use_raw_strings
150220
- use_rethrow_when_possible
151221
# - use_setters_to_change_properties # not yet tested
152-
# - use_string_buffers # https://github.com/dart-lang/linter/pull/664
222+
# - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
153223
# - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
154224
- valid_regexps
225+
- void_checks

flutter_frontend_server/bin/starter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'dart:io';
99

1010
import 'package:flutter_frontend_server/server.dart';
1111

12-
void main(List<String> args) async {
12+
Future<void> main(List<String> args) async {
1313
final int exitCode = await starter(args);
1414
if (exitCode != 0) {
1515
exit(exitCode);

flutter_frontend_server/lib/server.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class _FlutterFrontendCompiler implements frontend.CompilerInterface {
4444
}
4545

4646
@override
47-
Future<Null> recompileDelta({String entryPoint}) async {
47+
Future<Null> recompileDelta({String entryPoint}) async { // ignore: prefer_void_to_null
4848
return _compiler.recompileDelta(entryPoint: entryPoint);
4949
}
5050

@@ -64,7 +64,7 @@ class _FlutterFrontendCompiler implements frontend.CompilerInterface {
6464
}
6565

6666
@override
67-
Future<Null> compileExpression(
67+
Future<Null> compileExpression( // ignore: prefer_void_to_null
6868
String expression,
6969
List<String> definitions,
7070
List<String> typeDefinitions,
@@ -76,7 +76,7 @@ class _FlutterFrontendCompiler implements frontend.CompilerInterface {
7676
}
7777

7878
@override
79-
Future<Null> compileExpressionToJs(
79+
Future<Null> compileExpressionToJs( // ignore: prefer_void_to_null
8080
String libraryUri,
8181
int line,
8282
int column,

flutter_frontend_server/test/to_string_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'package:path/path.dart' as path;
1212

1313
import 'package:test/test.dart';
1414

15-
void main(List<String> args) async {
15+
Future<void> main(List<String> args) async {
1616
if (args.length != 2) {
1717
stderr.writeln('The first argument must be the path to the forntend server dill.');
1818
stderr.writeln('The second argument must be the path to the flutter_patched_sdk');

lib/ui/hash_codes.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ int hashValues(
116116
int hashList(Iterable<Object?>? arguments) {
117117
int result = 0;
118118
if (arguments != null) {
119-
for (Object? argument in arguments)
119+
for (final Object? argument in arguments)
120120
result = _Jenkins.combine(result, argument);
121121
}
122122
return _Jenkins.finish(result);

lib/ui/natives.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ List<int> saveCompilationTrace() {
7878

7979
dynamic _saveCompilationTrace() native 'SaveCompilationTrace';
8080

81-
void _scheduleMicrotask(void callback()) native 'ScheduleMicrotask';
81+
void _scheduleMicrotask(void Function() callback) native 'ScheduleMicrotask';
8282

8383
int? _getCallbackHandle(Function closure) native 'GetCallbackHandle';
8484
Function? _getCallbackFromHandle(int handle) native 'GetCallbackFromHandle';

lib/ui/painting.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,7 +1984,7 @@ class Codec extends NativeFieldWrapperClass2 {
19841984
if (error != null) {
19851985
throw Exception(error);
19861986
}
1987-
return await completer.future;
1987+
return completer.future;
19881988
}
19891989

19901990
/// Returns an error message on failure, null on success.
@@ -2699,7 +2699,7 @@ class PathMetricIterator implements Iterator<PathMetric> {
26992699
if (currentMetric == null) {
27002700
throw RangeError(
27012701
'PathMetricIterator is not pointing to a PathMetric. This can happen in two situations:\n'
2702-
'- The iteration has not started yet. If so, call "moveNext" to start iteration.'
2702+
'- The iteration has not started yet. If so, call "moveNext" to start iteration.\n'
27032703
'- The iterator ran out of elements. If so, check that "moveNext" returns true prior to calling "current".'
27042704
);
27052705
}

lib/ui/platform_dispatcher.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ class PlatformDispatcher {
358358
void _dispatchKeyData(ByteData packet, int responseId) {
359359
_invoke2<KeyData, _KeyDataResponseCallback>(
360360
(KeyData data, _KeyDataResponseCallback callback) {
361-
callback(responseId, onKeyData == null ? false : onKeyData!(data));
361+
callback(responseId, onKeyData != null && onKeyData!(data));
362362
},
363363
_onKeyDataZone,
364364
_unpackKeyData(packet),
@@ -644,7 +644,7 @@ class PlatformDispatcher {
644644
/// platform specific APIs without invoking method channels.
645645
Locale? computePlatformResolvedLocale(List<Locale> supportedLocales) {
646646
final List<String?> supportedLocalesData = <String?>[];
647-
for (Locale locale in supportedLocales) {
647+
for (final Locale locale in supportedLocales) {
648648
supportedLocalesData.add(locale.languageCode);
649649
supportedLocalesData.add(locale.countryCode);
650650
supportedLocalesData.add(locale.scriptCode);

lib/ui/text.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ class TextDecoration {
14971497
/// Creates a decoration that paints the union of all the given decorations.
14981498
factory TextDecoration.combine(List<TextDecoration> decorations) {
14991499
int mask = 0;
1500-
for (TextDecoration decoration in decorations)
1500+
for (final TextDecoration decoration in decorations)
15011501
mask |= decoration._mask;
15021502
return TextDecoration._(mask);
15031503
}
@@ -3335,7 +3335,7 @@ class ParagraphBuilder extends NativeFieldWrapperClass2 {
33353335
if (fontFeatures != null) {
33363336
encodedFontFeatures = ByteData(fontFeatures.length * FontFeature._kEncodedSize);
33373337
int byteOffset = 0;
3338-
for (FontFeature feature in fontFeatures) {
3338+
for (final FontFeature feature in fontFeatures) {
33393339
feature._encode(ByteData.view(encodedFontFeatures.buffer, byteOffset, FontFeature._kEncodedSize));
33403340
byteOffset += FontFeature._kEncodedSize;
33413341
}
@@ -3449,13 +3449,13 @@ class ParagraphBuilder extends NativeFieldWrapperClass2 {
34493449
TextBaseline? baseline,
34503450
}) {
34513451
// Require a baseline to be specified if using a baseline-based alignment.
3452-
assert((alignment == PlaceholderAlignment.aboveBaseline ||
3452+
assert(!(alignment == PlaceholderAlignment.aboveBaseline ||
34533453
alignment == PlaceholderAlignment.belowBaseline ||
3454-
alignment == PlaceholderAlignment.baseline) ? baseline != null : true);
3454+
alignment == PlaceholderAlignment.baseline) || baseline != null);
34553455
// Default the baselineOffset to height if null. This will place the placeholder
34563456
// fully above the baseline, similar to [PlaceholderAlignment.aboveBaseline].
34573457
baselineOffset = baselineOffset ?? height;
3458-
_addPlaceholder(width * scale, height * scale, alignment.index, baselineOffset * scale, baseline == null ? null : baseline.index);
3458+
_addPlaceholder(width * scale, height * scale, alignment.index, baselineOffset * scale, baseline?.index);
34593459
_placeholderCount++;
34603460
_placeholderScales.add(scale);
34613461
}

0 commit comments

Comments
 (0)