Skip to content

Commit 6628875

Browse files
committed
Fix lint
1 parent 521f954 commit 6628875

12 files changed

+204
-160
lines changed

analysis_options.yaml

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
linter:
4+
rules:
5+
- always_declare_return_types
6+
- always_put_control_body_on_new_line: false
7+
- always_put_required_named_parameters_first: false
8+
- always_require_non_null_named_parameters: false # deprecated
9+
- always_specify_types: false
10+
- always_use_package_imports
11+
- annotate_redeclares
12+
- avoid_annotating_with_dynamic: false # May conflict with always_declare_return_types
13+
- avoid_bool_literals_in_conditional_expressions
14+
# - avoid_catches_without_on_clauses
15+
# - avoid_catching_errors
16+
- avoid_classes_with_only_static_members: false
17+
- avoid_double_and_int_checks
18+
- avoid_dynamic_calls
19+
- avoid_equals_and_hash_code_on_mutable_classes
20+
- avoid_escaping_inner_quotes
21+
- avoid_field_initializers_in_const_classes
22+
- avoid_final_parameters
23+
- avoid_implementing_value_types
24+
- avoid_js_rounded_ints
25+
- avoid_multiple_declarations_per_line
26+
- avoid_positional_boolean_parameters: false
27+
- avoid_private_typedef_functions
28+
- avoid_redundant_argument_values: false
29+
- avoid_returning_null: false # deprecated
30+
- avoid_returning_null_for_future
31+
- avoid_returning_this
32+
- avoid_setters_without_getters: false
33+
- avoid_slow_async_io
34+
- avoid_type_to_string
35+
- avoid_types_on_closure_parameters
36+
- avoid_unstable_final_fields
37+
- avoid_unused_constructor_parameters
38+
- avoid_void_async
39+
- cancel_subscriptions
40+
# - cascade_invocations
41+
- cast_nullable_to_non_nullable
42+
- close_sinks
43+
- collection_methods_unrelated_type
44+
- combinators_ordering
45+
- comment_references
46+
- conditional_uri_does_not_exist
47+
- dangling_library_doc_comments: false
48+
- deprecated_consistency
49+
- deprecated_member_use_from_same_package: false
50+
# - diagnostic_describe_all_properties
51+
- directives_ordering
52+
- discarded_futures: false
53+
- do_not_use_environment
54+
- eol_at_end_of_file
55+
- flutter_style_todos: false
56+
- implicit_call_tearoffs
57+
- implicit_reopen
58+
- invalid_case_patterns
59+
- join_return_with_assignment
60+
- leading_newlines_in_multiline_strings
61+
- library_annotations
62+
- lines_longer_than_80_chars: false
63+
- literal_only_boolean_expressions
64+
- matching_super_parameters
65+
- missing_whitespace_between_adjacent_strings
66+
- no_adjacent_strings_in_list
67+
- no_default_cases: false
68+
- no_literal_bool_comparisons
69+
- no_runtimeType_toString
70+
- no_self_assignments
71+
- no_wildcard_variable_uses
72+
- noop_primitive_operations
73+
- omit_local_variable_types
74+
- one_member_abstracts
75+
- only_throw_errors
76+
- package_api_docs: false
77+
- parameter_assignments
78+
- prefer_asserts_in_initializer_lists
79+
- prefer_asserts_with_message
80+
- prefer_constructors_over_static_methods
81+
- prefer_double_quotes: false # Conflicts with prefer_single_quotes
82+
- prefer_expression_function_bodies: false
83+
- prefer_final_in_for_each
84+
- prefer_final_locals
85+
- prefer_final_parameters: false
86+
- prefer_foreach
87+
- prefer_if_elements_to_conditional_expressions
88+
- prefer_int_literals
89+
- prefer_mixin
90+
- prefer_null_aware_method_calls
91+
- prefer_relative_imports: false
92+
- prefer_single_quotes
93+
# - public_member_api_docs
94+
- require_trailing_commas: false
95+
- secure_pubspec_urls
96+
- sized_box_shrink_expand
97+
- sort_constructors_first
98+
- sort_pub_dependencies
99+
- sort_unnamed_constructors_first
100+
- test_types_in_equals
101+
- throw_in_finally
102+
- tighten_type_of_initializing_formals
103+
# - type_annotate_public_apis
104+
- type_literal_in_constant_pattern
105+
- unawaited_futures
106+
- unnecessary_await_in_return
107+
- unnecessary_breaks
108+
- unnecessary_final: false
109+
- unnecessary_lambdas
110+
- unnecessary_library_directive
111+
- unnecessary_null_aware_operator_on_extension_on_nullable
112+
- unnecessary_null_checks
113+
- unnecessary_parenthesis
114+
- unnecessary_raw_strings
115+
- unnecessary_statements
116+
- unnecessary_to_list_in_spreads
117+
- unreachable_from_main: false
118+
- unsafe_html
119+
- use_colored_box
120+
- use_decorated_box
121+
- use_enums
122+
- use_if_null_to_convert_nulls_to_bools: false
123+
- use_is_even_rather_than_modulo
124+
- use_late_for_private_fields_and_variables
125+
- use_named_constants
126+
- use_raw_strings
127+
# - use_setters_to_change_properties
128+
- use_string_buffers
129+
- use_string_in_part_of_directives
130+
- use_super_parameters
131+
- use_test_throws_matchers
132+
- use_to_and_as_if_applicable
133+
134+
analyzer:
135+
exclude:
136+
- build/**
137+
- '**/**.freezed.dart'
138+
- 'lib/**.g.dart'
139+
- 'lib/**.graphql.dart'
140+
- 'lib/ui/djungo_custom_icons.dart'
141+
- '**/l10n/app_localizations*.dart'
142+
errors:
143+
invalid_annotation_target: ignore
144+
145+
dart_code_metrics:
146+
anti-patterns:
147+
- long-method
148+
- long-parameter-list
149+
metrics:
150+
cyclomatic-complexity: 20
151+
maximum-nesting-level: 5
152+
number-of-parameters: 4
153+
source-lines-of-code: 50
154+
metrics-exclude:
155+
- test/**
156+
rules:
157+
- no-boolean-literal-compare
158+
- no-empty-block
159+
- prefer-trailing-comma
160+
- no-equal-then-else
161+
162+
# Additional information about this file can be found at
163+
# https://dart.dev/guides/language/analysis-options

example/analysis_options.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
include: ../analysis_options.yaml
2+
3+
linter:
4+
rules:
5+
- avoid_print: false

example/integration_test/local_timezone_test.dart

+4-7
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@ void main() {
77
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
88

99
group('getLocalTimezone', () {
10-
final expected = const String.fromEnvironment('EXPECTED_TZ');
10+
// ignore: do_not_use_environment
11+
const expected = String.fromEnvironment('EXPECTED_TZ');
1112

1213
testWidgets('check that the local timezone is $expected', (tester) async {
13-
await tester.pumpWidget(MyApp());
14+
await tester.pumpWidget(const MyApp());
1415
await tester.pumpAndSettle();
1516

16-
Text tzTextWidget = find
17-
.byKey(const ValueKey('timeZoneLabel'))
18-
.evaluate()
19-
.first
20-
.widget as Text;
17+
final tzTextWidget = find.byKey(const ValueKey('timeZoneLabel')).evaluate().first.widget as Text;
2118

2219
expect(tzTextWidget.data, expected);
2320
});

example/lib/main.dart

+4-12
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,9 @@ class _MyAppState extends State<MyApp> {
2323
}
2424

2525
Future<void> _initData() async {
26-
try {
27-
_timezone = await FlutterTimezone.getLocalTimezone();
28-
} catch (e) {
29-
print('Could not get the local timezone');
30-
}
31-
try {
32-
_availableTimezones = await FlutterTimezone.getAvailableTimezones();
33-
_availableTimezones.sort();
34-
} catch (e) {
35-
print('Could not get available timezones');
36-
}
26+
_timezone = await FlutterTimezone.getLocalTimezone();
27+
_availableTimezones = await FlutterTimezone.getAvailableTimezones();
28+
_availableTimezones.sort();
3729
if (mounted) {
3830
setState(() {});
3931
}
@@ -48,7 +40,7 @@ class _MyAppState extends State<MyApp> {
4840
child: const Icon(Icons.refresh),
4941
),
5042
body: Padding(
51-
padding: const EdgeInsets.all(12.0),
43+
padding: const EdgeInsets.all(12),
5244
child: Column(
5345
crossAxisAlignment: CrossAxisAlignment.start,
5446
children: <Widget>[

example/pubspec.yaml

+3-65
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,23 @@
11
name: flutter_timezone_example
22
description: "Demonstrates how to use the flutter_timezone plugin."
3-
# The following line prevents the package from being accidentally published to
4-
# pub.dev using `flutter pub publish`. This is preferred for private packages.
53
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
64

75
environment:
86
sdk: '>=3.4.0 <4.0.0'
97

10-
# Dependencies specify other packages that your package needs in order to work.
11-
# To automatically upgrade your package dependencies to the latest versions
12-
# consider running `flutter pub upgrade --major-versions`. Alternatively,
13-
# dependencies can be manually updated by changing the version numbers below to
14-
# the latest version available on pub.dev. To see which dependencies have newer
15-
# versions available, run `flutter pub outdated`.
168
dependencies:
179
flutter:
1810
sdk: flutter
1911

2012
flutter_timezone:
21-
# When depending on this package from a real application you should use:
22-
# flutter_timezone: ^x.y.z
23-
# See https://dart.dev/tools/pub/dependencies#version-constraints
24-
# The example app is bundled with the plugin so we use a path dependency on
25-
# the parent directory to use the current plugin's version.
2613
path: ../
2714

28-
# The following adds the Cupertino Icons font to your application.
29-
# Use with the CupertinoIcons class for iOS style icons.
30-
cupertino_icons: ^1.0.6
31-
3215
dev_dependencies:
33-
integration_test:
34-
sdk: flutter
16+
flutter_lints: ^3.0.0
3517
flutter_test:
3618
sdk: flutter
19+
integration_test:
20+
sdk: flutter
3721

38-
# The "flutter_lints" package below contains a set of recommended lints to
39-
# encourage good coding practices. The lint set provided by the package is
40-
# activated in the `analysis_options.yaml` file located at the root of your
41-
# package. See that file for information about deactivating specific lint
42-
# rules and activating additional ones.
43-
flutter_lints: ^3.0.0
44-
45-
# For information on the generic Dart part of this file, see the
46-
# following page: https://dart.dev/tools/pub/pubspec
47-
48-
# The following section is specific to Flutter packages.
4922
flutter:
50-
51-
# The following line ensures that the Material Icons font is
52-
# included with your application, so that you can use the icons in
53-
# the material Icons class.
5423
uses-material-design: true
55-
56-
# To add assets to your application, add an assets section, like this:
57-
# assets:
58-
# - images/a_dot_burr.jpeg
59-
# - images/a_dot_ham.jpeg
60-
61-
# An image asset can refer to one or more resolution-specific "variants", see
62-
# https://flutter.dev/assets-and-images/#resolution-aware
63-
64-
# For details regarding adding assets from package dependencies, see
65-
# https://flutter.dev/assets-and-images/#from-packages
66-
67-
# To add custom fonts to your application, add a fonts section here,
68-
# in this "flutter" section. Each entry in this list should have a
69-
# "family" key with the font family name, and a "fonts" key with a
70-
# list giving the asset and other descriptors for the font. For
71-
# example:
72-
# fonts:
73-
# - family: Schyler
74-
# fonts:
75-
# - asset: fonts/Schyler-Regular.ttf
76-
# - asset: fonts/Schyler-Italic.ttf
77-
# style: italic
78-
# - family: Trajan Pro
79-
# fonts:
80-
# - asset: fonts/TrajanPro.ttf
81-
# - asset: fonts/TrajanPro_Bold.ttf
82-
# weight: 700
83-
#
84-
# For details regarding fonts from package dependencies,
85-
# see https://flutter.dev/custom-fonts/#from-packages

example/test/widget_test.dart

+2-6
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,16 @@
77

88
import 'package:flutter/material.dart';
99
import 'package:flutter_test/flutter_test.dart';
10-
1110
import 'package:flutter_timezone_example/main.dart';
1211

1312
void main() {
14-
testWidgets('Verify Platform version', (WidgetTester tester) async {
13+
testWidgets('Verify Platform version', (tester) async {
1514
// Build our app and trigger a frame.
1615
await tester.pumpWidget(const MyApp());
1716

1817
// Verify that platform version is retrieved.
1918
expect(
20-
find.byWidgetPredicate(
21-
(Widget widget) => widget is Text &&
22-
widget.data!.startsWith('Running on:'),
23-
),
19+
find.byWidgetPredicate((widget) => widget is Text && widget.data!.startsWith('Running on:')),
2420
findsOneWidget,
2521
);
2622
});

example_spm/analysis_options.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
include: ../analysis_options.yaml
1+
include: ../analysis_options.yaml
2+
3+
linter:
4+
rules:
5+
- avoid_print: false

example_spm/lib/main.dart

+4-12
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,9 @@ class _MyAppState extends State<MyApp> {
2323
}
2424

2525
Future<void> _initData() async {
26-
try {
27-
_timezone = await FlutterTimezone.getLocalTimezone();
28-
} catch (e) {
29-
print('Could not get the local timezone');
30-
}
31-
try {
32-
_availableTimezones = await FlutterTimezone.getAvailableTimezones();
33-
_availableTimezones.sort();
34-
} catch (e) {
35-
print('Could not get available timezones');
36-
}
26+
_timezone = await FlutterTimezone.getLocalTimezone();
27+
_availableTimezones = await FlutterTimezone.getAvailableTimezones();
28+
_availableTimezones.sort();
3729
if (mounted) {
3830
setState(() {});
3931
}
@@ -48,7 +40,7 @@ class _MyAppState extends State<MyApp> {
4840
child: const Icon(Icons.refresh),
4941
),
5042
body: Padding(
51-
padding: const EdgeInsets.all(12.0),
43+
padding: const EdgeInsets.all(12),
5244
child: Column(
5345
crossAxisAlignment: CrossAxisAlignment.start,
5446
children: <Widget>[

0 commit comments

Comments
 (0)