Skip to content

Commit 4533a04

Browse files
[vector_math] Add and adopt repo analysis options (#2)
- Copies the analysis options from flutter/packages, so that we are standardized - Removes the package-level analysis options - Fixes all analyzer issues (many with `dart fix --apply`, others by hand but mostly mechanically) - Runs the autoformatter This is part of bringing this initial package into compliance with the existing flutter/packages standards, in order to bring up the same tooling in this repository. Part of flutter/flutter#185027
1 parent e4b8416 commit 4533a04

88 files changed

Lines changed: 5299 additions & 4322 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

analysis_options.yaml

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
# Specify analysis options.
2+
#
3+
# This file is a copy of analysis_options.yaml from flutter/packages
4+
# as of 2026-05-20. The file is expected to be kept in sync with the
5+
# flutter/packages copy (which is in turn mostly synchronized with
6+
# flutter/flutter).
7+
8+
analyzer:
9+
language:
10+
strict-casts: true
11+
strict-inference: true
12+
strict-raw-types: true
13+
errors:
14+
# allow deprecated members (we do this because otherwise we have to annotate
15+
# every member in every test, assert, etc, when we or the Dart SDK deprecates
16+
# something (https://github.com/flutter/flutter/issues/143312)
17+
deprecated_member_use: ignore
18+
deprecated_member_use_from_same_package: ignore
19+
exclude: # DIFFERENT FROM FLUTTER/FLUTTER
20+
# Ignore generated files
21+
- '**/*.pb.dart'
22+
- '**/*.g.dart'
23+
- '**/*.jni.dart'
24+
- '**/*.ffi.dart'
25+
- '**/*.mocks.dart' # Mockito @GenerateMocks
26+
27+
linter:
28+
rules:
29+
# This list is derived from the list of all available lints located at
30+
# https://github.com/dart-lang/linter/blob/main/example/all.yaml
31+
- always_declare_return_types
32+
- always_put_control_body_on_new_line
33+
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
34+
# - always_specify_types # conflicts with omit_obvious_local_variable_types
35+
# - always_use_package_imports # we do this commonly
36+
- annotate_overrides
37+
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
38+
- avoid_bool_literals_in_conditional_expressions
39+
# - avoid_catches_without_on_clauses # blocked on https://github.com/dart-lang/linter/issues/3023
40+
# - avoid_catching_errors # blocked on https://github.com/dart-lang/linter/issues/3023
41+
# - avoid_classes_with_only_static_members # we do this commonly for `abstract final class`es
42+
- avoid_double_and_int_checks
43+
- avoid_dynamic_calls
44+
- avoid_empty_else
45+
- avoid_equals_and_hash_code_on_mutable_classes
46+
- avoid_escaping_inner_quotes
47+
- avoid_field_initializers_in_const_classes
48+
# - avoid_final_parameters # incompatible with prefer_final_parameters
49+
- avoid_function_literals_in_foreach_calls
50+
# - avoid_implementing_value_types # see https://github.com/dart-lang/linter/issues/4558
51+
- avoid_init_to_null
52+
- avoid_js_rounded_ints
53+
# - avoid_multiple_declarations_per_line # seems to be a stylistic choice we don't subscribe to
54+
# - avoid_positional_boolean_parameters # would have been nice to enable this but by now there's too many places that break it
55+
- avoid_print
56+
# - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
57+
- avoid_redundant_argument_values
58+
- avoid_relative_lib_imports
59+
- avoid_renaming_method_parameters
60+
- avoid_return_types_on_setters
61+
- avoid_returning_null_for_void
62+
# - avoid_returning_this # there are enough valid reasons to return `this` that this lint ends up with too many false positives
63+
- avoid_setters_without_getters
64+
- avoid_shadowing_type_parameters
65+
- avoid_single_cascade_in_expression_statements
66+
- avoid_slow_async_io
67+
- avoid_type_to_string
68+
- avoid_types_as_parameter_names
69+
# - avoid_types_on_closure_parameters # conflicts with always_specify_types
70+
- avoid_unnecessary_containers
71+
- avoid_unused_constructor_parameters
72+
- avoid_void_async
73+
# - avoid_web_libraries_in_flutter # we use web libraries in web-specific code, and our tests prevent us from using them elsewhere
74+
- await_only_futures
75+
- camel_case_extensions
76+
- camel_case_types
77+
- cancel_subscriptions
78+
# - cascade_invocations # doesn't match the typical style of this repo
79+
- cast_nullable_to_non_nullable
80+
# - close_sinks # not reliable enough
81+
- collection_methods_unrelated_type
82+
- combinators_ordering
83+
# - comment_references # blocked on https://github.com/dart-lang/linter/issues/1142
84+
- conditional_uri_does_not_exist
85+
# - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204
86+
- control_flow_in_finally
87+
- curly_braces_in_flow_control_structures
88+
- dangling_library_doc_comments
89+
- depend_on_referenced_packages
90+
- deprecated_consistency
91+
# - deprecated_member_use_from_same_package # we allow self-references to deprecated members
92+
# - diagnostic_describe_all_properties # enabled only at the framework level (packages/flutter/lib)
93+
- directives_ordering
94+
# - discarded_futures # too many false positives, similar to unawaited_futures
95+
# - do_not_use_environment # there are appropriate times to use the environment, especially in our tests and build logic
96+
- empty_catches
97+
- empty_constructor_bodies
98+
- empty_statements
99+
- eol_at_end_of_file
100+
- exhaustive_cases
101+
- file_names
102+
- flutter_style_todos
103+
- hash_and_equals
104+
- implementation_imports
105+
- implicit_call_tearoffs
106+
- implicit_reopen
107+
- invalid_case_patterns
108+
# - join_return_with_assignment # not required by flutter style
109+
- leading_newlines_in_multiline_strings
110+
- library_annotations
111+
- library_names
112+
- library_prefixes
113+
- library_private_types_in_public_api
114+
# - lines_longer_than_80_chars # not required by flutter style
115+
- literal_only_boolean_expressions
116+
# - matching_super_parameters # blocked on https://github.com/dart-lang/language/issues/2509
117+
- missing_code_block_language_in_doc_comment
118+
- missing_whitespace_between_adjacent_strings
119+
# - no_adjacent_strings_in_list # conflicts with prefer_adjacent_string_concatenation
120+
- no_default_cases
121+
- no_duplicate_case_values
122+
- no_leading_underscores_for_library_prefixes
123+
- no_leading_underscores_for_local_identifiers
124+
- no_literal_bool_comparisons
125+
- no_logic_in_create_state
126+
- no_runtimeType_toString # DIFFERENT FROM FLUTTER/FLUTTER
127+
- no_self_assignments
128+
- no_wildcard_variable_uses
129+
- non_constant_identifier_names
130+
- noop_primitive_operations
131+
- null_check_on_nullable_type_parameter
132+
- null_closures
133+
# - omit_local_variable_types # conflicts with specify_nonobvious_local_variable_types
134+
- omit_obvious_local_variable_types
135+
# - one_member_abstracts # too many false positives
136+
- only_throw_errors # this does get disabled in a few places where we have legacy code that uses strings et al
137+
- overridden_fields
138+
# - package_api_docs # Deprecated (https://github.com/dart-lang/linter/issues/5107)
139+
- package_names
140+
- package_prefixed_library_names
141+
# - parameter_assignments # we do this commonly
142+
- prefer_adjacent_string_concatenation
143+
- prefer_asserts_in_initializer_lists
144+
# - prefer_asserts_with_message # not required by flutter style
145+
- prefer_collection_literals
146+
- prefer_conditional_assignment
147+
- prefer_const_constructors
148+
- prefer_const_constructors_in_immutables
149+
- prefer_const_declarations
150+
- prefer_const_literals_to_create_immutables
151+
# - prefer_constructors_over_static_methods # far too many false positives
152+
- prefer_contains
153+
# - prefer_double_quotes # opposite of prefer_single_quotes
154+
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md#consider-using--for-short-functions-and-methods
155+
- prefer_final_fields
156+
- prefer_final_in_for_each
157+
- prefer_final_locals
158+
# - prefer_final_parameters # adds too much verbosity
159+
- prefer_for_elements_to_map_fromIterable
160+
- prefer_foreach
161+
- prefer_function_declarations_over_variables
162+
- prefer_generic_function_type_aliases
163+
- prefer_if_elements_to_conditional_expressions
164+
- prefer_if_null_operators
165+
- prefer_initializing_formals
166+
- prefer_inlined_adds
167+
# - prefer_int_literals # conflicts with https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md#use-double-literals-for-double-constants
168+
- prefer_interpolation_to_compose_strings
169+
- prefer_is_empty
170+
- prefer_is_not_empty
171+
- prefer_is_not_operator
172+
- prefer_iterable_whereType
173+
- prefer_mixin
174+
# - prefer_null_aware_method_calls # "call()" is confusing to people new to the language since it's not documented anywhere
175+
- prefer_null_aware_operators
176+
- prefer_relative_imports
177+
- prefer_single_quotes
178+
- prefer_spread_collections
179+
- prefer_typing_uninitialized_variables
180+
- prefer_void_to_null
181+
- provide_deprecation_message
182+
- public_member_api_docs # DIFFERENT FROM FLUTTER/FLUTTER
183+
- recursive_getters
184+
# - require_trailing_commas # would be nice, but requires a lot of manual work: 10,000+ code locations would need to be reformatted by hand after bulk fix is applied
185+
- secure_pubspec_urls
186+
- sized_box_for_whitespace
187+
- sized_box_shrink_expand
188+
- slash_for_doc_comments
189+
- sort_child_properties_last
190+
- sort_constructors_first
191+
- sort_pub_dependencies # DIFFERENT FROM FLUTTER/FLUTTER: Flutter's use case for not sorting does not apply to this repository.
192+
- sort_unnamed_constructors_first
193+
- specify_nonobvious_local_variable_types
194+
- specify_nonobvious_property_types
195+
- test_types_in_equals
196+
- throw_in_finally
197+
- tighten_type_of_initializing_formals
198+
- type_annotate_public_apis
199+
- type_init_formals
200+
- type_literal_in_constant_pattern
201+
- unintended_html_in_doc_comment # DIFFERENT FROM FLUTTER/FLUTTER: Disabled due to an issue that has been fixed, so just hasn't been adopted there yet.
202+
- unawaited_futures # DIFFERENT FROM FLUTTER/FLUTTER: It's disabled there for "too many false positives"; that's not an issue here, and missing awaits have caused production issues in plugins.
203+
- unnecessary_await_in_return
204+
- unnecessary_brace_in_string_interps
205+
- unnecessary_breaks
206+
- unnecessary_const
207+
- unnecessary_constructor_name
208+
# - unnecessary_final # conflicts with prefer_final_locals
209+
- unnecessary_getters_setters
210+
# - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
211+
- unnecessary_late
212+
- unnecessary_library_directive
213+
- unnecessary_new
214+
- unnecessary_null_aware_assignments
215+
- unnecessary_null_aware_operator_on_extension_on_nullable
216+
- unnecessary_null_checks
217+
- unnecessary_null_in_if_null_operators
218+
- unnecessary_nullable_for_final_variable_declarations
219+
- unnecessary_overrides
220+
- unnecessary_parenthesis
221+
# - unnecessary_raw_strings # what's "necessary" is a matter of opinion; consistency across strings can help readability more than this lint
222+
- unnecessary_statements
223+
- unnecessary_string_escapes
224+
- unnecessary_string_interpolations
225+
- unnecessary_this
226+
- unnecessary_to_list_in_spreads
227+
- unreachable_from_main
228+
- unrelated_type_equality_checks
229+
- use_build_context_synchronously
230+
- use_colored_box
231+
# - use_decorated_box # leads to bugs: DecoratedBox and Container are not equivalent (Container inserts extra padding)
232+
- use_enums
233+
- use_full_hex_values_for_flutter_colors
234+
- use_function_type_syntax_for_parameters
235+
- use_if_null_to_convert_nulls_to_bools
236+
- use_is_even_rather_than_modulo
237+
- use_key_in_widget_constructors
238+
- use_late_for_private_fields_and_variables
239+
- use_named_constants
240+
- use_raw_strings
241+
- use_rethrow_when_possible
242+
- use_setters_to_change_properties
243+
# - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
244+
- use_string_in_part_of_directives
245+
- use_super_parameters
246+
- use_test_throws_matchers
247+
# - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
248+
- valid_regexps
249+
- void_checks

packages/vector_math/analysis_options.yaml

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

packages/vector_math/benchmark/matrix4_tween_bench.dart

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ mixin Setup on BenchmarkBase {
2020

2121
@override
2222
void run() {
23-
var sum_traces = 0.0;
23+
var sumTraces = 0.0;
2424
for (var i = 0; i <= 1024; i++) {
25-
final t = i / 1024.0;
26-
final m1 = lerp(beginTransform, endTransform, t);
27-
final m2 = lerp(endTransform, beginTransform, t);
28-
sum_traces += m1.trace();
29-
sum_traces += m2.trace();
25+
final double t = i / 1024.0;
26+
final Matrix4 m1 = lerp(beginTransform, endTransform, t);
27+
final Matrix4 m2 = lerp(endTransform, beginTransform, t);
28+
sumTraces += m1.trace();
29+
sumTraces += m2.trace();
3030
}
31-
if (sum_traces < 6320 || sum_traces > 6321) {
32-
throw StateError('Bad result: $sum_traces');
31+
if (sumTraces < 6320 || sumTraces > 6321) {
32+
throw StateError('Bad result: $sumTraces');
3333
}
3434
}
3535

@@ -49,10 +49,11 @@ class Matrix4TweenBenchmark1 extends BenchmarkBase with Setup {
4949
final endScale = Vector3.zero();
5050
begin.decompose(beginTranslation, beginRotation, beginScale);
5151
end.decompose(endTranslation, endRotation, endScale);
52-
final lerpTranslation = beginTranslation * (1.0 - t) + endTranslation * t;
53-
final lerpRotation =
52+
final Vector3 lerpTranslation =
53+
beginTranslation * (1.0 - t) + endTranslation * t;
54+
final Quaternion lerpRotation =
5455
(beginRotation.scaled(1.0 - t) + endRotation.scaled(t)).normalized();
55-
final lerpScale = beginScale * (1.0 - t) + endScale * t;
56+
final Vector3 lerpScale = beginScale * (1.0 - t) + endScale * t;
5657
return Matrix4.compose(lerpTranslation, lerpRotation, lerpScale);
5758
}
5859
}
@@ -65,7 +66,7 @@ class Matrix4TweenBenchmark2 extends BenchmarkBase with Setup {
6566
begin.decompose(beginTranslation, beginRotation, beginScale);
6667
end.decompose(endTranslation, endRotation, endScale);
6768
Vector3.mix(beginTranslation, endTranslation, t, lerpTranslation);
68-
final lerpRotation =
69+
final Quaternion lerpRotation =
6970
(beginRotation.scaled(1.0 - t) + endRotation.scaled(t)).normalized();
7071
Vector3.mix(beginScale, endScale, t, lerpScale);
7172
return Matrix4.compose(lerpTranslation, lerpRotation, lerpScale);
@@ -90,7 +91,7 @@ class Matrix4TweenBenchmark3 extends BenchmarkBase with Setup {
9091
begin.decompose(beginTranslation, beginRotation, beginScale);
9192
end.decompose(endTranslation, endRotation, endScale);
9293
Vector3.mix(beginTranslation, endTranslation, t, lerpTranslation);
93-
final lerpRotation =
94+
final Quaternion lerpRotation =
9495
(beginRotation.scaled(1.0 - t) + endRotation.scaled(t)).normalized();
9596
Vector3.mix(beginScale, endScale, t, lerpScale);
9697
return Matrix4.compose(lerpTranslation, lerpRotation, lerpScale);
@@ -107,19 +108,19 @@ class Matrix4TweenBenchmark3 extends BenchmarkBase with Setup {
107108
}
108109

109110
void main() {
110-
final benchmarks = [
111+
final List<Setup> benchmarks = [
111112
Matrix4TweenBenchmark1(),
112113
Matrix4TweenBenchmark2(),
113114
Matrix4TweenBenchmark3(),
114115
];
115116
// Warmup all bencmarks.
116-
for (var b in benchmarks) {
117+
for (final b in benchmarks) {
117118
b.run();
118119
}
119-
for (var b in benchmarks) {
120+
for (final b in benchmarks) {
120121
b.exercise();
121122
}
122-
for (var b in benchmarks) {
123+
for (final b in benchmarks) {
123124
b.report();
124125
}
125126
}

0 commit comments

Comments
 (0)