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

Commit e3d01e1

Browse files
authored
Sync lints with flutter/flutter (#49192)
1 parent d9cc207 commit e3d01e1

35 files changed

+53
-189
lines changed

analysis_options.yaml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Specify analysis options.
22
#
33
# This file is a copy of analysis_options.yaml from flutter repo
4-
# as of 2023-03-22, but with some modifications marked with
4+
# as of 2023-12-18, but with some modifications marked with
55
# "DIFFERENT FROM FLUTTER/FLUTTER" below.
66

77
analyzer:
@@ -20,7 +20,7 @@ analyzer:
2020
linter:
2121
rules:
2222
# This list is derived from the list of all available lints located at
23-
# https://github.com/dart-lang/linter/blob/master/example/all.yaml
23+
# https://github.com/dart-lang/linter/blob/main/example/all.yaml
2424
- always_declare_return_types
2525
- always_put_control_body_on_new_line
2626
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
@@ -31,7 +31,7 @@ linter:
3131
- avoid_bool_literals_in_conditional_expressions
3232
# - avoid_catches_without_on_clauses # blocked on https://github.com/dart-lang/linter/issues/3023
3333
# - avoid_catching_errors # blocked on https://github.com/dart-lang/linter/issues/3023
34-
# - avoid_classes_with_only_static_members # we do this commonly
34+
# - avoid_classes_with_only_static_members # we do this commonly for `abstract final class`es
3535
- avoid_double_and_int_checks
3636
- avoid_dynamic_calls
3737
- avoid_empty_else
@@ -40,7 +40,7 @@ linter:
4040
- avoid_field_initializers_in_const_classes
4141
# - avoid_final_parameters # incompatible with prefer_final_parameters
4242
- avoid_function_literals_in_foreach_calls
43-
- avoid_implementing_value_types
43+
# - avoid_implementing_value_types # see https://github.com/dart-lang/linter/issues/4558
4444
- avoid_init_to_null
4545
- avoid_js_rounded_ints
4646
# - avoid_multiple_declarations_per_line # seems to be a stylistic choice we don't subscribe to
@@ -82,6 +82,7 @@ linter:
8282
- dangling_library_doc_comments
8383
- depend_on_referenced_packages
8484
- deprecated_consistency
85+
# - deprecated_member_use_from_same_package # we allow self-references to deprecated members
8586
# - diagnostic_describe_all_properties # enabled only at the framework level (packages/flutter/lib)
8687
- directives_ordering
8788
# - discarded_futures # too many false positives, similar to unawaited_futures
@@ -96,25 +97,28 @@ linter:
9697
- hash_and_equals
9798
- implementation_imports
9899
- implicit_call_tearoffs
100+
- implicit_reopen
99101
- invalid_case_patterns
100-
- iterable_contains_unrelated_type
101102
# - join_return_with_assignment # not required by flutter style
102103
- leading_newlines_in_multiline_strings
103104
- library_annotations
104105
- library_names
105106
- library_prefixes
106107
- library_private_types_in_public_api
107108
# - lines_longer_than_80_chars # not required by flutter style
108-
- list_remove_unrelated_type
109-
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/linter/issues/453
109+
- literal_only_boolean_expressions
110+
# - matching_super_parameters # blocked on https://github.com/dart-lang/language/issues/2509
110111
# - missing_whitespace_between_adjacent_strings # DIFFERENT FROM FLUTTER/FLUTTER (too many false positives)
111112
- no_adjacent_strings_in_list
112113
- no_default_cases
113114
- no_duplicate_case_values
114115
- no_leading_underscores_for_library_prefixes
115116
- no_leading_underscores_for_local_identifiers
117+
- no_literal_bool_comparisons
116118
- no_logic_in_create_state
117119
# - no_runtimeType_toString # ok in tests; we enable this only in packages/
120+
- no_self_assignments
121+
- no_wildcard_variable_uses
118122
- non_constant_identifier_names
119123
- noop_primitive_operations
120124
- null_check_on_nullable_type_parameter
@@ -143,7 +147,7 @@ linter:
143147
- prefer_final_fields
144148
- prefer_final_in_for_each
145149
- prefer_final_locals
146-
# - prefer_final_parameters # we should enable this one day when it can be auto-fixed (https://github.com/dart-lang/linter/issues/3104), see also parameter_assignments
150+
# - prefer_final_parameters # adds too much verbosity
147151
- prefer_for_elements_to_map_fromIterable
148152
- prefer_foreach
149153
- prefer_function_declarations_over_variables
@@ -183,6 +187,7 @@ linter:
183187
- tighten_type_of_initializing_formals
184188
# - type_annotate_public_apis # subset of always_specify_types
185189
- type_init_formals
190+
- type_literal_in_constant_pattern
186191
# - unawaited_futures # too many false positives, especially with the way AnimationController works
187192
- unnecessary_await_in_return
188193
- unnecessary_brace_in_string_interps
@@ -208,7 +213,7 @@ linter:
208213
- unnecessary_string_interpolations
209214
- unnecessary_this
210215
- unnecessary_to_list_in_spreads
211-
# - unreachable_from_main # Do not enable this rule until it is un-marked as "experimental" and carefully re-evaluated.
216+
- unreachable_from_main
212217
- unrelated_type_equality_checks
213218
- unsafe_html
214219
- use_build_context_synchronously

ci/bin/format.dart

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ class FormattingException implements Exception {
2020
final String message;
2121
final ProcessResult? result;
2222

23-
int get exitCode => result?.exitCode ?? -1;
24-
2523
@override
2624
String toString() {
2725
final StringBuffer output = StringBuffer(runtimeType.toString());
@@ -109,7 +107,6 @@ abstract class FormatChecker {
109107
ProcessManager processManager = const LocalProcessManager(),
110108
required this.baseGitRef,
111109
required this.repoDir,
112-
required this.srcDir,
113110
this.allFiles = false,
114111
this.messageCallback,
115112
}) : _processRunner = ProcessRunner(
@@ -142,7 +139,6 @@ abstract class FormatChecker {
142139
processManager: processManager,
143140
baseGitRef: baseGitRef,
144141
repoDir: repoDir,
145-
srcDir: srcDir,
146142
allFiles: allFiles,
147143
messageCallback: messageCallback,
148144
);
@@ -160,7 +156,6 @@ abstract class FormatChecker {
160156
processManager: processManager,
161157
baseGitRef: baseGitRef,
162158
repoDir: repoDir,
163-
srcDir: srcDir,
164159
allFiles: allFiles,
165160
messageCallback: messageCallback,
166161
);
@@ -169,15 +164,13 @@ abstract class FormatChecker {
169164
processManager: processManager,
170165
baseGitRef: baseGitRef,
171166
repoDir: repoDir,
172-
srcDir: srcDir,
173167
allFiles: allFiles,
174168
messageCallback: messageCallback,
175169
);
176170
}
177171
}
178172

179173
final ProcessRunner _processRunner;
180-
final Directory srcDir;
181174
final Directory repoDir;
182175
final bool allFiles;
183176
MessageCallback? messageCallback;
@@ -302,9 +295,7 @@ class ClangFormatChecker extends FormatChecker {
302295
required Directory srcDir,
303296
super.allFiles,
304297
super.messageCallback,
305-
}) : super(
306-
srcDir: srcDir,
307-
) {
298+
}) {
308299
/*late*/ String clangOs;
309300
if (Platform.isLinux) {
310301
clangOs = 'linux-x64';
@@ -462,9 +453,7 @@ class JavaFormatChecker extends FormatChecker {
462453
required Directory srcDir,
463454
super.allFiles,
464455
super.messageCallback,
465-
}) : super(
466-
srcDir: srcDir,
467-
) {
456+
}) {
468457
googleJavaFormatJar = File(
469458
path.absolute(
470459
path.join(
@@ -619,7 +608,6 @@ class GnFormatChecker extends FormatChecker {
619608
super.processManager,
620609
required super.baseGitRef,
621610
required Directory repoDir,
622-
required super.srcDir,
623611
super.allFiles,
624612
super.messageCallback,
625613
}) : super(
@@ -750,7 +738,6 @@ class PythonFormatChecker extends FormatChecker {
750738
super.processManager,
751739
required super.baseGitRef,
752740
required Directory repoDir,
753-
required super.srcDir,
754741
super.allFiles,
755742
super.messageCallback,
756743
}) : super(
@@ -845,7 +832,6 @@ class WhitespaceFormatChecker extends FormatChecker {
845832
super.processManager,
846833
required super.baseGitRef,
847834
required super.repoDir,
848-
required super.srcDir,
849835
super.allFiles,
850836
super.messageCallback,
851837
});

ci/licenses_golden/tool_signature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Signature: 5e484e46971049766e74d801d325ad63
1+
Signature: b0fbe71c20bdf5b2a1c163281b1f90de
22

ci/test/format_test.dart

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,34 @@ import 'dart:io' as io;
66

77
import 'package:litetest/litetest.dart';
88
import 'package:path/path.dart' as path;
9-
import 'package:process_runner/process_runner.dart';
109

1110
import '../bin/format.dart' as target;
1211

1312
final io.File script = io.File.fromUri(io.Platform.script).absolute;
1413
final io.Directory repoDir = script.parent.parent.parent;
15-
final ProcessPool pool = ProcessPool(
16-
numWorkers: 1,
17-
processRunner: ProcessRunner(defaultWorkingDirectory: repoDir),
18-
);
1914

2015
class FileContentPair {
21-
FileContentPair(this.original, this.formatted, this.fileExtension);
16+
FileContentPair(this.original, this.formatted);
2217

2318
final String original;
2419
final String formatted;
25-
final String fileExtension;
2620
}
2721

2822
final FileContentPair ccContentPair = FileContentPair(
29-
'int main(){return 0;}\n', 'int main() {\n return 0;\n}\n', '.cc');
23+
'int main(){return 0;}\n', 'int main() {\n return 0;\n}\n');
3024
final FileContentPair hContentPair =
31-
FileContentPair('int\nmain\n()\n;\n', 'int main();\n', '.h');
25+
FileContentPair('int\nmain\n()\n;\n', 'int main();\n');
3226
final FileContentPair gnContentPair = FileContentPair(
33-
'test\n(){testvar=true}\n', 'test() {\n testvar = true\n}\n', '.gn');
27+
'test\n(){testvar=true}\n', 'test() {\n testvar = true\n}\n');
3428
final FileContentPair javaContentPair = FileContentPair(
3529
'class Test{public static void main(String args[]){System.out.println("Test");}}\n',
36-
'class Test {\n public static void main(String args[]) {\n System.out.println("Test");\n }\n}\n',
37-
'.java');
30+
'class Test {\n public static void main(String args[]) {\n System.out.println("Test");\n }\n}\n');
3831
final FileContentPair pythonContentPair = FileContentPair(
3932
"if __name__=='__main__':\n sys.exit(\nMain(sys.argv)\n)\n",
40-
"if __name__ == '__main__':\n sys.exit(Main(sys.argv))\n",
41-
'.py');
33+
"if __name__ == '__main__':\n sys.exit(Main(sys.argv))\n");
4234
final FileContentPair whitespaceContentPair = FileContentPair(
4335
'int main() {\n return 0; \n}\n',
44-
'int main() {\n return 0;\n}\n',
45-
'.c');
36+
'int main() {\n return 0;\n}\n');
4637

4738
class TestFileFixture {
4839
TestFileFixture(this.type) {
@@ -106,31 +97,26 @@ class TestFileFixture {
10697
path.extension(file.path) == '.cc'
10798
? ccContentPair.formatted
10899
: hContentPair.formatted,
109-
path.extension(file.path),
110100
);
111101
case target.FormatCheck.gn:
112102
return FileContentPair(
113103
content,
114104
gnContentPair.formatted,
115-
path.extension(file.path),
116105
);
117106
case target.FormatCheck.java:
118107
return FileContentPair(
119108
content,
120109
javaContentPair.formatted,
121-
path.extension(file.path),
122110
);
123111
case target.FormatCheck.python:
124112
return FileContentPair(
125113
content,
126114
pythonContentPair.formatted,
127-
path.extension(file.path),
128115
);
129116
case target.FormatCheck.whitespace:
130117
return FileContentPair(
131118
content,
132119
whitespaceContentPair.formatted,
133-
path.extension(file.path),
134120
);
135121
}
136122
});

lib/ui/analysis_options.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ analyzer:
44
exclude:
55
# fixtures/ depends on dart:ui and raises false positives.
66
- fixtures/**
7+
8+
linter:
9+
rules:
10+
unreachable_from_main: false # lint not compatible with how dart:ui is structured

lib/ui/painting.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,7 @@ class Paint {
15011501
}
15021502
semicolon = '; ';
15031503
}
1504-
if (isAntiAlias != true) {
1504+
if (!isAntiAlias) {
15051505
result.write('${semicolon}antialias off');
15061506
semicolon = '; ';
15071507
}
@@ -6864,9 +6864,7 @@ base class _NativeImageDescriptor extends NativeFieldWrapperClass1 implements Im
68646864
targetHeight = height;
68656865
} else if (targetWidth == null && targetHeight != null) {
68666866
targetWidth = (targetHeight * (width / height)).round();
6867-
targetHeight = targetHeight;
68686867
} else if (targetHeight == null && targetWidth != null) {
6869-
targetWidth = targetWidth;
68706868
targetHeight = targetWidth ~/ (width / height);
68716869
}
68726870
assert(targetWidth != null);

lib/web_ui/lib/src/engine/canvaskit/image.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ CkImage scaleImage(SkImage image, int? targetWidth, int? targetHeight) {
113113
}
114114
if (targetWidth == null && targetHeight != null) {
115115
targetWidth = (targetHeight * (image.width() / image.height())).round();
116-
targetHeight = targetHeight;
117116
} else if (targetHeight == null && targetWidth != null) {
118-
targetWidth = targetWidth;
119117
targetHeight = targetWidth ~/ (image.width() / image.height());
120118
}
121119

lib/web_ui/lib/src/engine/html/painting.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class SurfacePaint implements ui.Paint {
203203
}
204204
semicolon = '; ';
205205
}
206-
if (isAntiAlias != true) {
206+
if (!isAntiAlias) {
207207
result.write('${semicolon}antialias off');
208208
semicolon = '; ';
209209
}

lib/web_ui/lib/src/engine/html/recording_canvas.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ class RecordingCanvas {
553553
return;
554554
}
555555
final RecordingCanvas pictureRecording = enginePicture.recordingCanvas!;
556-
if (pictureRecording._didDraw == true) {
556+
if (pictureRecording._didDraw) {
557557
_didDraw = true;
558558
}
559559
renderStrategy.merge(pictureRecording.renderStrategy);

lib/web_ui/lib/src/engine/semantics/text_field.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@ class SemanticsTextEditingStrategy extends DefaultTextEditingStrategy {
152152
{OnChangeCallback? onChange, OnActionCallback? onAction}) {
153153
isEnabled = true;
154154
inputConfiguration = inputConfig;
155-
onChange = onChange;
156-
onAction = onAction;
157155
applyConfiguration(inputConfig);
158156
}
159157

0 commit comments

Comments
 (0)