Skip to content

Commit b3f7a37

Browse files
authored
refactor: use more strict analysis options (#203)
1 parent f8d6757 commit b3f7a37

19 files changed

+504
-368
lines changed

analysis_options.yaml

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
analyzer:
2+
language:
3+
strict-casts: true
4+
strict-inference: true
5+
strict-raw-types: true
6+
7+
errors:
8+
close_sinks: ignore
9+
missing_required_param: error
10+
missing_return: error
11+
record_literal_one_positional_no_trailing_comma: error
12+
13+
linter:
14+
rules:
15+
- always_declare_return_types
16+
- always_put_required_named_parameters_first
17+
- always_use_package_imports
18+
- annotate_overrides
19+
- avoid_bool_literals_in_conditional_expressions
20+
- avoid_catching_errors
21+
- avoid_double_and_int_checks
22+
- avoid_dynamic_calls
23+
- avoid_empty_else
24+
- avoid_equals_and_hash_code_on_mutable_classes
25+
- avoid_escaping_inner_quotes
26+
- avoid_field_initializers_in_const_classes
27+
- avoid_final_parameters
28+
- avoid_function_literals_in_foreach_calls
29+
- avoid_init_to_null
30+
- avoid_js_rounded_ints
31+
- avoid_multiple_declarations_per_line
32+
- avoid_null_checks_in_equality_operators
33+
- avoid_print
34+
- avoid_private_typedef_functions
35+
- avoid_redundant_argument_values
36+
- avoid_relative_lib_imports
37+
- avoid_renaming_method_parameters
38+
- avoid_return_types_on_setters
39+
- avoid_returning_null_for_void
40+
- avoid_returning_this
41+
- avoid_setters_without_getters
42+
- avoid_shadowing_type_parameters
43+
- avoid_single_cascade_in_expression_statements
44+
- avoid_slow_async_io
45+
- avoid_type_to_string
46+
- avoid_types_as_parameter_names
47+
- avoid_unnecessary_containers
48+
- avoid_unused_constructor_parameters
49+
- avoid_void_async
50+
- avoid_web_libraries_in_flutter
51+
- await_only_futures
52+
- camel_case_extensions
53+
- camel_case_types
54+
- cancel_subscriptions
55+
- cascade_invocations
56+
- cast_nullable_to_non_nullable
57+
- collection_methods_unrelated_type
58+
- comment_references
59+
- conditional_uri_does_not_exist
60+
- constant_identifier_names
61+
- control_flow_in_finally
62+
- curly_braces_in_flow_control_structures
63+
- dangling_library_doc_comments
64+
- depend_on_referenced_packages
65+
- deprecated_consistency
66+
- directives_ordering
67+
- empty_catches
68+
- empty_constructor_bodies
69+
- empty_statements
70+
- eol_at_end_of_file
71+
- exhaustive_cases
72+
- file_names
73+
- flutter_style_todos
74+
- hash_and_equals
75+
- implementation_imports
76+
- implicit_call_tearoffs
77+
- implicit_reopen
78+
- invalid_case_patterns
79+
- iterable_contains_unrelated_type
80+
- join_return_with_assignment
81+
- leading_newlines_in_multiline_strings
82+
- library_annotations
83+
- library_names
84+
- library_prefixes
85+
- library_private_types_in_public_api
86+
- lines_longer_than_80_chars
87+
- list_remove_unrelated_type
88+
- literal_only_boolean_expressions
89+
- missing_whitespace_between_adjacent_strings
90+
- no_adjacent_strings_in_list
91+
- no_default_cases
92+
- no_duplicate_case_values
93+
- no_leading_underscores_for_library_prefixes
94+
- no_leading_underscores_for_local_identifiers
95+
- no_logic_in_create_state
96+
- no_runtimeType_toString
97+
- non_constant_identifier_names
98+
- noop_primitive_operations
99+
- null_check_on_nullable_type_parameter
100+
- null_closures
101+
- omit_local_variable_types
102+
- one_member_abstracts
103+
- only_throw_errors
104+
- overridden_fields
105+
- package_api_docs
106+
- package_names
107+
- package_prefixed_library_names
108+
- prefer_adjacent_string_concatenation
109+
- prefer_asserts_in_initializer_lists
110+
- prefer_asserts_with_message
111+
- prefer_collection_literals
112+
- prefer_conditional_assignment
113+
- prefer_const_constructors
114+
- prefer_const_constructors_in_immutables
115+
- prefer_const_declarations
116+
- prefer_const_literals_to_create_immutables
117+
- prefer_constructors_over_static_methods
118+
- prefer_contains
119+
- prefer_final_fields
120+
- prefer_final_in_for_each
121+
- prefer_final_locals
122+
- prefer_for_elements_to_map_fromIterable
123+
- prefer_function_declarations_over_variables
124+
- prefer_generic_function_type_aliases
125+
- prefer_if_elements_to_conditional_expressions
126+
- prefer_if_null_operators
127+
- prefer_initializing_formals
128+
- prefer_inlined_adds
129+
- prefer_int_literals
130+
- prefer_interpolation_to_compose_strings
131+
- prefer_is_empty
132+
- prefer_is_not_empty
133+
- prefer_is_not_operator
134+
- prefer_iterable_whereType
135+
- prefer_null_aware_method_calls
136+
- prefer_null_aware_operators
137+
- prefer_single_quotes
138+
- prefer_spread_collections
139+
- prefer_typing_uninitialized_variables
140+
- prefer_void_to_null
141+
- provide_deprecation_message
142+
- public_member_api_docs
143+
- recursive_getters
144+
- require_trailing_commas
145+
- secure_pubspec_urls
146+
- sized_box_for_whitespace
147+
- sized_box_shrink_expand
148+
- slash_for_doc_comments
149+
- sort_child_properties_last
150+
- sort_constructors_first
151+
- sort_pub_dependencies
152+
- sort_unnamed_constructors_first
153+
- test_types_in_equals
154+
- throw_in_finally
155+
- tighten_type_of_initializing_formals
156+
- type_annotate_public_apis
157+
- type_init_formals
158+
- unawaited_futures
159+
- unnecessary_await_in_return
160+
- unnecessary_brace_in_string_interps
161+
- unnecessary_breaks
162+
- unnecessary_const
163+
- unnecessary_constructor_name
164+
- unnecessary_getters_setters
165+
- unnecessary_lambdas
166+
- unnecessary_late
167+
- unnecessary_library_directive
168+
- unnecessary_new
169+
- unnecessary_null_aware_assignments
170+
- unnecessary_null_checks
171+
- unnecessary_null_in_if_null_operators
172+
- unnecessary_nullable_for_final_variable_declarations
173+
- unnecessary_overrides
174+
- unnecessary_parenthesis
175+
- unnecessary_raw_strings
176+
- unnecessary_statements
177+
- unnecessary_string_escapes
178+
- unnecessary_string_interpolations
179+
- unnecessary_this
180+
- unnecessary_to_list_in_spreads
181+
- unrelated_type_equality_checks
182+
- use_build_context_synchronously
183+
- use_colored_box
184+
- use_enums
185+
- use_full_hex_values_for_flutter_colors
186+
- use_function_type_syntax_for_parameters
187+
- use_if_null_to_convert_nulls_to_bools
188+
- use_is_even_rather_than_modulo
189+
- use_key_in_widget_constructors
190+
- use_late_for_private_fields_and_variables
191+
- use_named_constants
192+
- use_raw_strings
193+
- use_rethrow_when_possible
194+
- use_setters_to_change_properties
195+
- use_string_buffers
196+
- use_string_in_part_of_directives
197+
- use_super_parameters
198+
- use_test_throws_matchers
199+
- use_to_and_as_if_applicable
200+
- valid_regexps
201+
- void_checks
Lines changed: 1 addition & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1 @@
1-
analyzer:
2-
strong-mode:
3-
implicit-casts: false
4-
implicit-dynamic: false
5-
errors:
6-
close_sinks: ignore
7-
8-
linter:
9-
rules:
10-
- public_member_api_docs
11-
- annotate_overrides
12-
- avoid_empty_else
13-
- avoid_function_literals_in_foreach_calls
14-
- avoid_init_to_null
15-
- avoid_null_checks_in_equality_operators
16-
- avoid_relative_lib_imports
17-
- avoid_renaming_method_parameters
18-
- avoid_return_types_on_setters
19-
- avoid_returning_null
20-
- avoid_types_as_parameter_names
21-
- avoid_unused_constructor_parameters
22-
- await_only_futures
23-
- camel_case_types
24-
- cancel_subscriptions
25-
- cascade_invocations
26-
- comment_references
27-
- constant_identifier_names
28-
- control_flow_in_finally
29-
- directives_ordering
30-
- empty_catches
31-
- empty_constructor_bodies
32-
- empty_statements
33-
- hash_and_equals
34-
- implementation_imports
35-
- iterable_contains_unrelated_type
36-
- library_names
37-
- library_prefixes
38-
- list_remove_unrelated_type
39-
- lines_longer_than_80_chars
40-
- no_adjacent_strings_in_list
41-
- no_duplicate_case_values
42-
- non_constant_identifier_names
43-
- null_closures
44-
- omit_local_variable_types
45-
- only_throw_errors
46-
- overridden_fields
47-
- package_api_docs
48-
- package_names
49-
- package_prefixed_library_names
50-
- prefer_adjacent_string_concatenation
51-
- prefer_collection_literals
52-
- prefer_conditional_assignment
53-
- prefer_const_constructors
54-
- prefer_contains
55-
- prefer_equal_for_default_values
56-
- prefer_final_fields
57-
- prefer_initializing_formals
58-
- prefer_interpolation_to_compose_strings
59-
- prefer_is_empty
60-
- prefer_is_not_empty
61-
- prefer_single_quotes
62-
- prefer_typing_uninitialized_variables
63-
- recursive_getters
64-
- slash_for_doc_comments
65-
- sort_constructors_first
66-
- test_types_in_equals
67-
- throw_in_finally
68-
- type_init_formals
69-
- unawaited_futures
70-
- unnecessary_brace_in_string_interps
71-
- unnecessary_const
72-
- unnecessary_getters_setters
73-
- unnecessary_lambdas
74-
- unnecessary_new
75-
- unnecessary_null_aware_assignments
76-
- unnecessary_statements
77-
- unnecessary_this
78-
- unrelated_type_equality_checks
79-
- use_rethrow_when_possible
80-
- valid_regexps
1+
include: ../../analysis_options.yaml

packages/mocktail/lib/mocktail.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export 'src/mocktail.dart'
2323
verifyNoMoreInteractions,
2424
verifyZeroInteractions,
2525
VerificationResult,
26+
Verify,
2627
ListOfVerificationResult,
2728

2829
// -- misc

packages/mocktail/lib/src/_invocation_matcher.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class InvocationMatcher {
1313
/// matches function which determines whether the current
1414
/// [roleInvocation] matches the provided [invocation].
1515
bool matches(Invocation invocation) {
16-
var isMatching =
16+
final isMatching =
1717
_isMethodMatches(invocation) && _isArgumentsMatches(invocation);
1818
if (isMatching) {
1919
_captureArguments(invocation);
@@ -83,8 +83,8 @@ class InvocationMatcher {
8383
typeArgIndex++;
8484
}
8585

86-
Set roleKeys = roleInvocation.namedArguments.keys.toSet();
87-
Set actKeys = invocation.namedArguments.keys.toSet();
86+
final roleKeys = roleInvocation.namedArguments.keys.toSet();
87+
final actKeys = invocation.namedArguments.keys.toSet();
8888
if (roleKeys.difference(actKeys).isNotEmpty ||
8989
actKeys.difference(roleKeys).isNotEmpty) {
9090
return false;

packages/mocktail/lib/src/_is_invocation.dart

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ class _InvocationMatcher implements Matcher {
3535

3636
// Returns named arguments as an iterable of '<name>: <value>'.
3737
static Iterable<String> _namedArgsAndValues(Invocation invocation) =>
38-
invocation.namedArguments.keys.map((name) =>
39-
'${_symbolToString(name)}: ${invocation.namedArguments[name]}');
38+
invocation.namedArguments.keys.map(
39+
(name) =>
40+
'${_symbolToString(name)}: ${invocation.namedArguments[name]}',
41+
);
4042

4143
// This will give is a mangled symbol in dart2js/aot with minification
4244
// enabled, but it's safe to assume very few people will use the invocation
@@ -114,16 +116,6 @@ Invocation _useMatchedInvocationIfSet(Invocation invocation) {
114116
/// An Invocation implementation that takes arguments from [_storedArgs] and
115117
/// [_storedNamedArgs].
116118
class _InvocationForMatchedArguments extends Invocation {
117-
_InvocationForMatchedArguments._(
118-
this.memberName,
119-
this.positionalArguments,
120-
this.namedArguments,
121-
this.typeArguments,
122-
this.isGetter,
123-
this.isMethod,
124-
this.isSetter,
125-
);
126-
127119
@override
128120
factory _InvocationForMatchedArguments(Invocation invocation) {
129121
// Handle named arguments first, so that we can provide useful errors for
@@ -147,6 +139,16 @@ class _InvocationForMatchedArguments extends Invocation {
147139
);
148140
}
149141

142+
_InvocationForMatchedArguments._(
143+
this.memberName,
144+
this.positionalArguments,
145+
this.namedArguments,
146+
this.typeArguments,
147+
this.isGetter,
148+
this.isMethod,
149+
this.isSetter,
150+
);
151+
150152
@override
151153
final Symbol memberName;
152154
@override
@@ -192,7 +194,7 @@ class _InvocationForMatchedArguments extends Invocation {
192194
// Iterate through the stored named args, validate them, and add them to
193195
// the return map.
194196
_storedNamedArgs.forEach((name, arg) {
195-
var nameSymbol = Symbol(name);
197+
final nameSymbol = Symbol(name);
196198
if (!invocation.namedArguments.containsKey(nameSymbol)) {
197199
// Clear things out for the next call.
198200
_storedArgs.clear();

packages/mocktail/lib/src/_real_call.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extension on Invocation {
4747
/// improve readability.
4848
String toPrettyString() {
4949
String argString;
50-
var args = positionalArguments.map((dynamic v) => '$v');
50+
final args = positionalArguments.map((dynamic v) => '$v');
5151
if (args.any((arg) => arg.contains('\n'))) {
5252
// As one or more arg contains newlines, put each on its own line, and
5353
// indent each, for better readability.
@@ -82,7 +82,7 @@ extension on Invocation {
8282

8383
method = '$method$typeArgsString($argString)';
8484
} else if (isGetter) {
85-
method = '$method';
85+
// no-op
8686
} else if (isSetter) {
8787
method = '$method=$argString';
8888
} else {

0 commit comments

Comments
 (0)