Skip to content

Commit 6da4cab

Browse files
committed
chore: add option to define logger, improve code style
1 parent 40b6b86 commit 6da4cab

11 files changed

Lines changed: 244 additions & 130 deletions

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"cSpell.words": [
3+
"Cupertino",
34
"IMAP",
4-
"inappwebview"
5+
"inappwebview",
6+
"Toptype"
57
]
68
}

analysis_options.yaml

Lines changed: 101 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,148 @@
1+
# This file configures the analyzer, which statically analyzes Dart code to
2+
# check for errors, warnings, and lints.
3+
#
4+
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5+
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6+
# invoked from the command line by running `flutter analyze`.
7+
8+
# The following line activates a set of recommended lints for Flutter apps,
9+
# packages, and plugins designed to encourage good coding practices.
10+
include: package:flutter_lints/flutter.yaml
11+
12+
# cSpell:disable
113
analyzer:
2-
errors:
3-
todo: ignore
414
plugins:
515
- dart_code_metrics # https://github.com/dart-code-checker/dart-code-metrics
16+
#- custom_lint
17+
errors:
18+
todo: ignore # use separate tooling to display todos (eg Todo Tree in VSCode)
19+
exclude:
20+
- '**/*.g.*'
21+
22+
dart_code_metrics:
23+
anti-patterns:
24+
- long-method
25+
- long-parameter-list
26+
metrics:
27+
cyclomatic-complexity: 20
28+
maximum-nesting-level: 7
29+
number-of-parameters: 10
30+
source-lines-of-code: 100
31+
metrics-exclude:
32+
- test/**
33+
rules:
34+
- newline-before-return
35+
- no-boolean-literal-compare
36+
- no-empty-block
37+
- prefer-trailing-comma
38+
- prefer-conditional-expressions
39+
- no-equal-then-else
40+
- avoid-non-null-assertion
41+
642
linter:
743
rules:
844
- always_declare_return_types
9-
- always_put_control_body_on_new_line
10-
# - always_put_required_named_parameters_first # not useful for Flutter widgets
11-
#- always_specify_types # This would enforce to write types literally everywhere.
45+
# - always_put_control_body_on_new_line # No real benefit. Readability is better without
46+
# - always_put_required_named_parameters_first # We mostly put optional "Key" first.
47+
- always_require_non_null_named_parameters
48+
# - always_specify_types # No - Then we need to add types everywhere
49+
# - always_use_package_imports # We are using relative Imports inside of the LIB
1250
- annotate_overrides
13-
#- avoid_annotating_with_dynamic # Explicit annotation of dynamic as type is preferable. Also exclusive with type_annotate_public_apis
14-
#- avoid_as - deprecated, breaks lint
51+
# - avoid_annotating_with_dynamic # We want to be explicit if we do use dynamic
1552
- avoid_bool_literals_in_conditional_expressions
16-
#- avoid_catches_without_on_clauses # Do not enable this as enough_mail needs to handle several underlying exceptions and errors
53+
# - avoid_catches_without_on_clauses
1754
- avoid_catching_errors
18-
#- avoid_classes_with_only_static_members # Useful for some non-global helper cases
55+
# - avoid_classes_with_only_static_members # We follow this approach for DSTextStyles and DSIcons. We can enable it if we change that.
1956
- avoid_double_and_int_checks
57+
- avoid_dynamic_calls
2058
- avoid_empty_else
59+
- avoid_equals_and_hash_code_on_mutable_classes
60+
- avoid_escaping_inner_quotes
2161
- avoid_field_initializers_in_const_classes
2262
- avoid_function_literals_in_foreach_calls
2363
- avoid_implementing_value_types
2464
- avoid_init_to_null
2565
- avoid_js_rounded_ints
66+
- avoid_multiple_declarations_per_line
2667
- avoid_null_checks_in_equality_operators
27-
- avoid_positional_boolean_parameters
68+
# - avoid_positional_boolean_parameters # disabled to allow methods that can be directly assigned to ValueChanged<bool> callbacks.
69+
- avoid_print
2870
- avoid_private_typedef_functions
29-
- avoid_renaming_method_parameters
71+
- avoid_redundant_argument_values
3072
- avoid_relative_lib_imports
73+
- avoid_renaming_method_parameters
3174
- avoid_return_types_on_setters
75+
- avoid_returning_null
76+
- avoid_returning_null_for_future
3277
- avoid_returning_null_for_void
3378
- avoid_returning_this
3479
- avoid_setters_without_getters
3580
- avoid_shadowing_type_parameters
3681
- avoid_single_cascade_in_expression_statements
3782
- avoid_slow_async_io
83+
- avoid_type_to_string
3884
- avoid_types_as_parameter_names
39-
- avoid_types_on_closure_parameters
85+
# - avoid_types_on_closure_parameters # Sometimes it is useful to define the type.
86+
- avoid_unnecessary_containers
4087
- avoid_unused_constructor_parameters
4188
- avoid_void_async
42-
- avoid_web_libraries_in_flutter
89+
# - avoid_web_libraries_in_flutter # We currently need them
4390
- await_only_futures
91+
- camel_case_extensions
4492
- camel_case_types
4593
- cancel_subscriptions
4694
- cascade_invocations
4795
- cast_nullable_to_non_nullable
4896
- close_sinks
49-
- comment_references
97+
- collection_methods_unrelated_type
98+
# - comment_references # We want proper/cross-file linking in the docs
5099
- constant_identifier_names
51100
- control_flow_in_finally
52101
- curly_braces_in_flow_control_structures
53-
#- diagnostic_describe_all_properties # We do not use diagnostics atm
102+
- deprecated_consistency
103+
# - diagnostic_describe_all_properties # We do not use diagnostics atm
54104
- directives_ordering
105+
- do_not_use_environment
106+
- empty_catches
55107
- empty_constructor_bodies
56108
- empty_statements
57-
- empty_catches
109+
- exhaustive_cases
58110
- file_names
59-
#- flutter_style_todos # Flutter todos are to verbose for our requirements.
111+
- flutter_style_todos
60112
- hash_and_equals
61113
- implementation_imports
62-
- iterable_contains_unrelated_type
63-
# - join_return_with_assignment # leads to less readable code IMHO
114+
- join_return_with_assignment
115+
- leading_newlines_in_multiline_strings
64116
- library_names
65117
- library_prefixes
66118
- lines_longer_than_80_chars
67-
- list_remove_unrelated_type
68119
- literal_only_boolean_expressions
120+
- missing_whitespace_between_adjacent_strings
69121
- no_adjacent_strings_in_list
122+
- no_default_cases
70123
- no_duplicate_case_values
124+
- no_logic_in_create_state
125+
- no_runtimeType_toString
71126
- non_constant_identifier_names
127+
- null_check_on_nullable_type_parameter
72128
- null_closures
73-
- omit_local_variable_types
129+
# - omit_local_variable_types # Do not enable this. We want to specify the types in lambdas (e.g. to get auto completion).
74130
- one_member_abstracts
75131
- only_throw_errors
76132
- overridden_fields
77133
- package_api_docs
78134
- package_names
79135
- package_prefixed_library_names
80136
- parameter_assignments
81-
- prefer_adjacent_string_concatenation
82137
- prefer_asserts_in_initializer_lists
83-
- prefer_asserts_with_message
138+
# - prefer_asserts_with_message # Keep this optional for complex cases but do not require it.
84139
- prefer_collection_literals
85140
- prefer_conditional_assignment
86-
- prefer_const_constructors
87-
- prefer_const_constructors_in_immutables
141+
# - prefer_const_constructors # might be something for the future - skip for now.
142+
# - prefer_const_constructors_in_immutables # might be something for the future - skip for now.
88143
- prefer_const_declarations
89144
- prefer_const_literals_to_create_immutables
90-
- prefer_constructors_over_static_methods
145+
# - prefer_constructors_over_static_methods # this currently interfers with our current theming approach as we use static methods there to create instances.- prefer_adjacent_string_concatenation
91146
- prefer_contains
92147
- prefer_expression_function_bodies
93148
- prefer_final_fields
@@ -98,12 +153,14 @@ linter:
98153
- prefer_function_declarations_over_variables
99154
- prefer_generic_function_type_aliases
100155
- prefer_if_elements_to_conditional_expressions
156+
- prefer_if_null_operators
101157
- prefer_initializing_formals
102158
- prefer_inlined_adds
103-
# - prefer_int_literals # more customary to use doubles eg in paddings
159+
- prefer_int_literals
104160
- prefer_interpolation_to_compose_strings
105161
- prefer_is_empty
106162
- prefer_is_not_empty
163+
- prefer_is_not_operator
107164
- prefer_iterable_whereType
108165
- prefer_mixin
109166
- prefer_null_aware_operators
@@ -115,12 +172,16 @@ linter:
115172
- provide_deprecation_message
116173
- public_member_api_docs
117174
- recursive_getters
175+
- sized_box_for_whitespace
118176
- slash_for_doc_comments
177+
- sort_child_properties_last
119178
- sort_constructors_first
120179
- sort_pub_dependencies
121180
- sort_unnamed_constructors_first
181+
- use_super_parameters
122182
- test_types_in_equals
123183
- throw_in_finally
184+
- tighten_type_of_initializing_formals
124185
- type_annotate_public_apis
125186
- type_init_formals
126187
- unawaited_futures
@@ -131,29 +192,30 @@ linter:
131192
- unnecessary_lambdas
132193
- unnecessary_new
133194
- unnecessary_null_aware_assignments
195+
- unnecessary_null_checks
134196
- unnecessary_null_in_if_null_operators
197+
- unnecessary_nullable_for_final_variable_declarations
135198
- unnecessary_overrides
136199
- unnecessary_parenthesis
200+
- unnecessary_raw_strings
137201
- unnecessary_statements
202+
- unnecessary_string_escapes
203+
- unnecessary_string_interpolations
138204
- unnecessary_this
139205
- unrelated_type_equality_checks
206+
- unsafe_html
207+
- use_build_context_synchronously
140208
- use_full_hex_values_for_flutter_colors
141209
- use_function_type_syntax_for_parameters
210+
- use_if_null_to_convert_nulls_to_bools
211+
- use_is_even_rather_than_modulo
212+
- use_key_in_widget_constructors
213+
- use_late_for_private_fields_and_variables
214+
- use_named_constants
215+
- use_raw_strings
142216
- use_rethrow_when_possible
143217
- use_setters_to_change_properties
144218
- use_string_buffers
145219
- use_to_and_as_if_applicable
146220
- valid_regexps
147221
- void_checks
148-
dart_code_metrics:
149-
metrics:
150-
# disable metrics
151-
cyclomatic-complexity: 50
152-
maximum-nesting-level: 50
153-
number-of-parameters: 50
154-
source-lines-of-code: 500
155-
number-of-methods: 100
156-
metrics-exclude:
157-
- test/**
158-
rules:
159-
- avoid-non-null-assertion # comply to engineering standards and avoid !

example/enough_mail_flutter_example.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Widget buildViewerForMessage(MimeMessage mimeMessage, MailClient mailClient) =>
1616
mimeMessage: mimeMessage,
1717
mailClient: mailClient,
1818
onDownloaded: onMessageDownloaded,
19-
blockExternalImages: false,
2019
mailtoDelegate: handleMailto,
2120
);
2221

@@ -31,19 +30,20 @@ void onMessageDownloaded(MimeMessage mimeMessage) {
3130
Widget buildViewerForDownloadedMessage(MimeMessage mimeMessage) =>
3231
MimeMessageViewer(
3332
mimeMessage: mimeMessage,
34-
blockExternalImages: false,
3533
mailtoDelegate: handleMailto,
3634
);
3735

3836
/// Example implementation for a mailto delegate
3937
Future handleMailto(Uri mailto, MimeMessage mimeMessage) {
4038
// in reality you would get this from your account data
41-
final fromAddress = MailAddress('My Name', 'email@domain.com');
39+
const fromAddress = MailAddress('My Name', 'email@domain.com');
4240
final messageBuilder =
4341
MessageBuilder.prepareMailtoBasedMessage(mailto, fromAddress);
4442
// in reality navigate to compose screen, e.g.
45-
// return locator<NavigationService>()
46-
// .push(Routes.mailCompose, arguments: messageBuilder);
43+
// return GoRouter.of(context)
44+
// .pushNamed(Routes.mailCompose, extra: messageBuilder);
45+
// ignore: avoid_print
4746
print('generated message: ${messageBuilder.buildMimeMessage()}');
47+
4848
return Future.value();
4949
}

lib/enough_mail_flutter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ library enough_mail_flutter;
33

44
export 'package:enough_mail_html/enough_mail_html.dart';
55
export 'package:enough_media/enough_media.dart';
6-
export 'package:url_launcher/url_launcher.dart';
76
export 'package:flutter_inappwebview/flutter_inappwebview.dart';
7+
export 'package:url_launcher/url_launcher.dart';
88

99
export 'src/mime_media_provider.dart';
1010
export 'src/mime_message_downloader.dart';

lib/src/logger.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import 'package:logger/logger.dart';
2+
3+
/// The logger used by the library by default
4+
final defaultLogger = Logger();

lib/src/mime_media_provider.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ class MimeMediaProviderFactory {
1515
name.isNotEmpty) {
1616
mediaType = MediaType.guessFromFileName(name);
1717
}
18+
1819
return mediaType.isText
1920
? TextMediaProvider(
20-
name, mediaType.text, mimePart.decodeContentText() ?? '')
21+
name,
22+
mediaType.text,
23+
mimePart.decodeContentText() ?? '',
24+
)
2125
: MemoryMediaProvider(
2226
name,
2327
mediaType.text,

0 commit comments

Comments
 (0)