Skip to content

Commit 86f7280

Browse files
committed
Implement lints
1 parent 87a32c5 commit 86f7280

File tree

12 files changed

+341
-49
lines changed

12 files changed

+341
-49
lines changed
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
# Copyright 2021 The Chromium Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# in the LICENSE file.
4+
5+
linter:
6+
rules:
7+
- always_declare_return_types
8+
- always_put_control_body_on_new_line
9+
- always_put_required_named_parameters_first
10+
- always_require_non_null_named_parameters
11+
- always_specify_types
12+
- always_use_package_imports
13+
- annotate_overrides
14+
- avoid_annotating_with_dynamic
15+
- avoid_as
16+
- avoid_bool_literals_in_conditional_expressions
17+
- avoid_catches_without_on_clauses
18+
- avoid_catching_errors
19+
- avoid_classes_with_only_static_members
20+
- avoid_double_and_int_checks
21+
- avoid_empty_else
22+
- avoid_equals_and_hash_code_on_mutable_classes
23+
- avoid_escaping_inner_quotes
24+
- avoid_field_initializers_in_const_classes
25+
- avoid_function_literals_in_foreach_calls
26+
- avoid_implementing_value_types
27+
- avoid_init_to_null
28+
- avoid_js_rounded_ints
29+
- avoid_null_checks_in_equality_operators
30+
- avoid_positional_boolean_parameters
31+
- avoid_print
32+
- avoid_private_typedef_functions
33+
- avoid_redundant_argument_values
34+
- avoid_relative_lib_imports
35+
- avoid_renaming_method_parameters
36+
- avoid_return_types_on_setters
37+
- avoid_returning_null
38+
- avoid_returning_null_for_future
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_types_on_closure_parameters
48+
- avoid_unnecessary_containers
49+
- avoid_unused_constructor_parameters
50+
- avoid_void_async
51+
- avoid_web_libraries_in_flutter
52+
- await_only_futures
53+
- camel_case_extensions
54+
- camel_case_types
55+
- cancel_subscriptions
56+
- cascade_invocations
57+
- cast_nullable_to_non_nullable
58+
- close_sinks
59+
- comment_references
60+
- constant_identifier_names
61+
- control_flow_in_finally
62+
- curly_braces_in_flow_control_structures
63+
- diagnostic_describe_all_properties
64+
- directives_ordering
65+
- do_not_use_environment
66+
- empty_catches
67+
- empty_constructor_bodies
68+
- empty_statements
69+
- exhaustive_cases
70+
- file_names
71+
- flutter_style_todos
72+
- hash_and_equals
73+
- implementation_imports
74+
- invariant_booleans
75+
- iterable_contains_unrelated_type
76+
- join_return_with_assignment
77+
- leading_newlines_in_multiline_strings
78+
- library_names
79+
- library_prefixes
80+
- lines_longer_than_80_chars
81+
- list_remove_unrelated_type
82+
- literal_only_boolean_expressions
83+
- missing_whitespace_between_adjacent_strings
84+
- no_adjacent_strings_in_list
85+
- no_default_cases
86+
- no_duplicate_case_values
87+
- no_logic_in_create_state
88+
- no_runtimeType_toString
89+
- non_constant_identifier_names
90+
- null_check_on_nullable_type_parameter
91+
- null_closures
92+
- omit_local_variable_types
93+
- one_member_abstracts
94+
- only_throw_errors
95+
- overridden_fields
96+
- package_api_docs
97+
- package_names
98+
- package_prefixed_library_names
99+
- parameter_assignments
100+
- prefer_adjacent_string_concatenation
101+
- prefer_asserts_in_initializer_lists
102+
- prefer_asserts_with_message
103+
- prefer_collection_literals
104+
- prefer_conditional_assignment
105+
- prefer_const_constructors
106+
- prefer_const_constructors_in_immutables
107+
- prefer_const_declarations
108+
- prefer_const_literals_to_create_immutables
109+
- prefer_constructors_over_static_methods
110+
- prefer_contains
111+
- prefer_double_quotes
112+
- prefer_equal_for_default_values
113+
- prefer_expression_function_bodies
114+
- prefer_final_fields
115+
- prefer_final_in_for_each
116+
- prefer_final_locals
117+
- prefer_for_elements_to_map_fromIterable
118+
- prefer_foreach
119+
- prefer_function_declarations_over_variables
120+
- prefer_generic_function_type_aliases
121+
- prefer_if_elements_to_conditional_expressions
122+
- prefer_if_null_operators
123+
- prefer_initializing_formals
124+
- prefer_inlined_adds
125+
- prefer_int_literals
126+
- prefer_interpolation_to_compose_strings
127+
- prefer_is_empty
128+
- prefer_is_not_empty
129+
- prefer_is_not_operator
130+
- prefer_iterable_whereType
131+
- prefer_mixin
132+
- prefer_null_aware_operators
133+
- prefer_relative_imports
134+
- prefer_single_quotes
135+
- prefer_spread_collections
136+
- prefer_typing_uninitialized_variables
137+
- prefer_void_to_null
138+
- provide_deprecation_message
139+
- public_member_api_docs
140+
- recursive_getters
141+
- sized_box_for_whitespace
142+
- slash_for_doc_comments
143+
- sort_child_properties_last
144+
- sort_constructors_first
145+
- sort_pub_dependencies
146+
- sort_unnamed_constructors_first
147+
- test_types_in_equals
148+
- throw_in_finally
149+
- tighten_type_of_initializing_formals
150+
- type_annotate_public_apis
151+
- type_init_formals
152+
- unawaited_futures
153+
- unnecessary_await_in_return
154+
- unnecessary_brace_in_string_interps
155+
- unnecessary_const
156+
- unnecessary_final
157+
- unnecessary_getters_setters
158+
- unnecessary_lambdas
159+
- unnecessary_new
160+
- unnecessary_null_aware_assignments
161+
- unnecessary_null_checks
162+
- unnecessary_null_in_if_null_operators
163+
- unnecessary_nullable_for_final_variable_declarations
164+
- unnecessary_overrides
165+
- unnecessary_parenthesis
166+
- unnecessary_raw_strings
167+
- unnecessary_statements
168+
- unnecessary_string_escapes
169+
- unnecessary_string_interpolations
170+
- unnecessary_this
171+
- unrelated_type_equality_checks
172+
- unsafe_html
173+
- use_full_hex_values_for_flutter_colors
174+
- use_function_type_syntax_for_parameters
175+
- use_is_even_rather_than_modulo
176+
- use_key_in_widget_constructors
177+
- use_late_for_private_fields_and_variables
178+
- use_raw_strings
179+
- use_rethrow_when_possible
180+
- use_setters_to_change_properties
181+
- use_string_buffers
182+
- use_to_and_as_if_applicable
183+
- valid_regexps
184+
- void_checks
Lines changed: 104 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,107 @@
1-
# This is a temporary file to allow us to land a new set of linter rules in a
2-
# series of manageable patches instead of one gigantic PR. It disables some of
3-
# the new lints that are already failing on this plugin, for this plugin. It
4-
# should be deleted and the failing lints addressed as soon as possible.
5-
6-
include: ../../analysis_options.yaml
1+
# Copyright 2021 The Chromium Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# in the LICENSE file.
74

5+
include: all_lint_rules.yaml
86
analyzer:
7+
# TODO(rrousselGit): disable implicit-cast/implicit-dynamic
98
errors:
10-
public_member_api_docs: ignore
11-
unawaited_futures: ignore
9+
import_of_legacy_library_into_null_safe: ignore
10+
# Otherwise cause the import of all_lint_rules to warn because of some rules conflicts.
11+
# We explicitly enabled even conflicting rules and are fixing the conflict
12+
# in this file
13+
included_file_warning: ignore
14+
15+
linter:
16+
rules:
17+
## Disabled rules because the repository doesn't respect them (yet)
18+
19+
directives_ordering: false
20+
prefer_final_fields: false
21+
comment_references: false
22+
sort_constructors_first: false
23+
sort_unnamed_constructors_first: false
24+
always_put_control_body_on_new_line: false
25+
omit_local_variable_types: false
26+
prefer_constructors_over_static_methods: false
27+
prefer_final_locals: false
28+
only_throw_errors: false
29+
prefer_relative_imports: false
30+
non_constant_identifier_names: false
31+
avoid_returning_this: false
32+
avoid_catching_errors: false
33+
constant_identifier_names: false
34+
prefer_function_declarations_over_variables: false
35+
avoid_classes_with_only_static_members: false
36+
avoid_function_literals_in_foreach_calls: false
37+
use_key_in_widget_constructors: false
38+
prefer_mixin: false
39+
public_member_api_docs: false
40+
41+
#############
42+
43+
# Personal preference. I don't find it more readable
44+
cascade_invocations: false
45+
46+
# Conflicts with `prefer_single_quotes`
47+
# Single quotes are easier to type and don't compromise on readability.
48+
prefer_double_quotes: false
49+
50+
# Conflicts with `omit_local_variable_types` and other rules.
51+
# As per Dart guidelines, we want to avoid unnecessary types to make the code
52+
# more readable.
53+
# See https://dart.dev/guides/language/effective-dart/design#avoid-type-annotating-initialized-local-variables
54+
always_specify_types: false
55+
56+
# Incompatible with `prefer_final_locals`
57+
# Having immutable local variables makes larger functions more predictible
58+
# so we will use `prefer_final_locals` instead.
59+
unnecessary_final: false
60+
61+
# Not quite suitable for Flutter, which may have a `build` method with a single
62+
# return, but that return is still complex enough that a "body" is worth it.
63+
prefer_expression_function_bodies: false
64+
65+
# Conflicts with the convention used by flutter, which puts `Key key`
66+
# and `@required Widget child` last.
67+
always_put_required_named_parameters_first: false
68+
69+
# `as` is not that bad (especially with the upcoming non-nullable types).
70+
# Explicit exceptions is better than implicit exceptions.
71+
avoid_as: false
72+
73+
# This project doesn't use Flutter-style todos
74+
flutter_style_todos: false
75+
76+
# There are situations where we voluntarily want to catch everything,
77+
# especially as a library.
78+
avoid_catches_without_on_clauses: false
79+
80+
# Boring as it sometimes force a line of 81 characters to be split in two.
81+
# As long as we try to respect that 80 characters limit, going slightly
82+
# above is fine.
83+
lines_longer_than_80_chars: false
84+
85+
# Conflicts with disabling `implicit-dynamic`
86+
avoid_annotating_with_dynamic: false
87+
88+
# conflicts with `prefer_relative_imports`
89+
always_use_package_imports: false
90+
91+
# Disabled for now until we have NNBD as it otherwise conflicts with `missing_return`
92+
no_default_cases: false
93+
94+
# False positive, null checks don't need a message
95+
prefer_asserts_with_message: false
96+
97+
# Cumbersome with `context.select`
98+
avoid_types_on_closure_parameters: false
99+
100+
# Too many false positive (builders)
101+
diagnostic_describe_all_properties: false
102+
103+
# false positives (setter-like functions)
104+
avoid_positional_boolean_parameters: false
105+
106+
# Does not apply to providers
107+
prefer_const_constructors_in_immutables: false
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright 2021 The Chromium Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# in the LICENSE file.
4+
5+
include: ../analysis_options.yaml
6+
linter:
7+
rules:
8+
avoid_print: false

packages/firebase_performance/example/lib/main.dart

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ import 'dart:async';
88

99
import 'package:http/http.dart';
1010
import 'package:flutter/material.dart';
11+
import 'package:pedantic/pedantic.dart';
1112

1213
import 'package:firebase_performance/firebase_performance.dart';
1314

14-
void main() => runApp(MyApp());
15+
void main() => runApp(const MyApp());
1516

1617
class MyApp extends StatefulWidget {
18+
const MyApp({Key key}) : super(key: key);
19+
1720
@override
1821
_MyAppState createState() => _MyAppState();
1922
}
@@ -78,9 +81,9 @@ class _MyAppState extends State<MyApp> {
7881
_traceHasRan = false;
7982
});
8083

81-
final Trace trace = _performance.newTrace("test");
82-
trace.incrementMetric("metric1", 16);
83-
trace.putAttribute("favorite_color", "blue");
84+
final Trace trace = _performance.newTrace('test');
85+
unawaited(trace.incrementMetric('metric1', 16));
86+
unawaited(trace.putAttribute('favorite_color', 'blue'));
8487

8588
await trace.start();
8689

@@ -105,11 +108,11 @@ class _MyAppState extends State<MyApp> {
105108
final _MetricHttpClient metricHttpClient = _MetricHttpClient(Client());
106109

107110
final Request request = Request(
108-
"SEND",
109-
Uri.parse("https://www.google.com"),
111+
'SEND',
112+
Uri.parse('https://www.google.com'),
110113
);
111114

112-
metricHttpClient.send(request);
115+
unawaited(metricHttpClient.send(request));
113116

114117
setState(() {
115118
_httpMetricHasRan = true;
@@ -118,8 +121,7 @@ class _MyAppState extends State<MyApp> {
118121

119122
@override
120123
Widget build(BuildContext context) {
121-
final TextStyle textStyle =
122-
const TextStyle(color: Colors.lightGreenAccent, fontSize: 25.0);
124+
const textStyle = TextStyle(color: Colors.lightGreenAccent, fontSize: 25);
123125
return MaterialApp(
124126
home: Scaffold(
125127
appBar: AppBar(

0 commit comments

Comments
 (0)