Skip to content

Commit 4c8f2d9

Browse files
committed
Configure linter, fix linter issues (#55)
1 parent 9562304 commit 4c8f2d9

File tree

8 files changed

+270
-58
lines changed

8 files changed

+270
-58
lines changed

analysis_options.yaml

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
## This file is copied from
2+
## https://raw.githubusercontent.com/mockturtl/tidy/master/lib/analysis_options.2.17.0.yaml
3+
## Differences are then marked with '##'.
4+
5+
analyzer:
6+
errors:
7+
missing_required_param: error
8+
9+
linter:
10+
rules:
11+
- always_declare_return_types
12+
# - always_put_control_body_on_new_line # conflicts: curly_braces_in_flow_control_structures
13+
# - always_put_required_named_parameters_first # conflicts: use_key_in_widget_constructors, sort_child_properties_last
14+
- always_require_non_null_named_parameters
15+
# - always_specify_types # conflicts: omit_local_variable_types
16+
# - always_use_package_imports # conflicts: prefer_relative_imports
17+
- annotate_overrides
18+
- avoid_annotating_with_dynamic
19+
- avoid_bool_literals_in_conditional_expressions
20+
- avoid_catches_without_on_clauses
21+
- avoid_catching_errors
22+
- avoid_classes_with_only_static_members
23+
- avoid_double_and_int_checks
24+
- avoid_dynamic_calls
25+
- avoid_empty_else
26+
- avoid_equals_and_hash_code_on_mutable_classes
27+
# - avoid_escaping_inner_quotes # note: escape characters are fine
28+
- avoid_field_initializers_in_const_classes
29+
- avoid_final_parameters # conflicts: prefer_final_parameters
30+
- avoid_function_literals_in_foreach_calls
31+
- avoid_implementing_value_types
32+
- avoid_init_to_null
33+
- avoid_js_rounded_ints
34+
- avoid_multiple_declarations_per_line
35+
- avoid_null_checks_in_equality_operators
36+
# - avoid_positional_boolean_parameters # note: one is fine. Do use named params otherwise.
37+
- avoid_print
38+
- avoid_private_typedef_functions
39+
- avoid_redundant_argument_values
40+
- avoid_relative_lib_imports
41+
- avoid_renaming_method_parameters
42+
- avoid_return_types_on_setters
43+
- avoid_returning_null
44+
- avoid_returning_null_for_future
45+
- avoid_returning_null_for_void
46+
- avoid_returning_this
47+
- avoid_setters_without_getters
48+
- avoid_shadowing_type_parameters
49+
- avoid_single_cascade_in_expression_statements
50+
- avoid_slow_async_io
51+
- avoid_type_to_string
52+
- avoid_types_as_parameter_names
53+
## - avoid_types_on_closure_parameters
54+
- avoid_unnecessary_containers
55+
- avoid_unused_constructor_parameters
56+
- avoid_void_async
57+
- avoid_web_libraries_in_flutter
58+
- await_only_futures
59+
- camel_case_extensions
60+
- camel_case_types
61+
- cancel_subscriptions
62+
- cascade_invocations
63+
- cast_nullable_to_non_nullable
64+
- close_sinks
65+
- comment_references
66+
- conditional_uri_does_not_exist
67+
- constant_identifier_names
68+
- control_flow_in_finally
69+
- curly_braces_in_flow_control_structures
70+
- depend_on_referenced_packages
71+
- deprecated_consistency
72+
# - diagnostic_describe_all_properties # note: for Flutter
73+
- directives_ordering
74+
- do_not_use_environment
75+
- empty_catches
76+
- empty_constructor_bodies
77+
- empty_statements
78+
- eol_at_end_of_file
79+
- exhaustive_cases
80+
- file_names
81+
## - flutter_style_todos
82+
- hash_and_equals
83+
- implementation_imports
84+
- invariant_booleans
85+
- iterable_contains_unrelated_type
86+
- join_return_with_assignment
87+
# - leading_newlines_in_multiline_strings # note: optional
88+
- library_names
89+
- library_prefixes
90+
- library_private_types_in_public_api
91+
# - lines_longer_than_80_chars # note: false positive with long doc comments
92+
- list_remove_unrelated_type
93+
- literal_only_boolean_expressions
94+
- missing_whitespace_between_adjacent_strings
95+
- no_adjacent_strings_in_list
96+
- no_default_cases
97+
- no_duplicate_case_values
98+
- no_leading_underscores_for_library_prefixes
99+
- no_leading_underscores_for_local_identifiers
100+
- no_logic_in_create_state
101+
- no_runtimeType_toString
102+
- non_constant_identifier_names
103+
- noop_primitive_operations
104+
- null_check_on_nullable_type_parameter
105+
- null_closures
106+
## - omit_local_variable_types
107+
- one_member_abstracts
108+
- only_throw_errors
109+
- overridden_fields
110+
- package_api_docs
111+
- package_names
112+
- package_prefixed_library_names
113+
## - parameter_assignments
114+
- prefer_adjacent_string_concatenation
115+
- prefer_asserts_in_initializer_lists
116+
- prefer_asserts_with_message
117+
- prefer_collection_literals
118+
- prefer_conditional_assignment
119+
- prefer_const_constructors
120+
- prefer_const_constructors_in_immutables
121+
- prefer_const_declarations
122+
- prefer_const_literals_to_create_immutables
123+
- prefer_constructors_over_static_methods
124+
- prefer_contains
125+
# - prefer_double_quotes # conflicts: prefer_single_quotes
126+
- prefer_equal_for_default_values
127+
## - prefer_expression_function_bodies
128+
- prefer_final_fields
129+
# - prefer_final_in_for_each # conflicts: unnecessary_final
130+
# - prefer_final_locals # conflicts: unnecessary_final
131+
# - prefer_final_parameters # conflicts: unnecessary_final, avoid_final_parameters
132+
- prefer_for_elements_to_map_fromIterable
133+
- prefer_foreach
134+
- prefer_function_declarations_over_variables
135+
- prefer_generic_function_type_aliases
136+
## - prefer_if_elements_to_conditional_expressions
137+
- prefer_if_null_operators
138+
- prefer_initializing_formals
139+
- prefer_inlined_adds
140+
- prefer_int_literals
141+
- prefer_interpolation_to_compose_strings
142+
- prefer_is_empty
143+
- prefer_is_not_empty
144+
- prefer_is_not_operator
145+
- prefer_iterable_whereType
146+
- prefer_mixin
147+
- prefer_null_aware_method_calls
148+
- prefer_null_aware_operators
149+
- prefer_relative_imports
150+
- prefer_single_quotes
151+
- prefer_spread_collections
152+
- prefer_typing_uninitialized_variables
153+
- prefer_void_to_null
154+
- provide_deprecation_message
155+
# - public_member_api_docs # note: consider overriding as API stabilizes
156+
- recursive_getters
157+
# - require_trailing_commas # note: let `dart format` wrap closing brackets
158+
- secure_pubspec_urls
159+
- sized_box_for_whitespace
160+
- sized_box_shrink_expand
161+
- slash_for_doc_comments
162+
- sort_child_properties_last
163+
# - sort_constructors_first # conflicts with auto-sorting all members, per [Fuschia style guide](https://fuchsia.dev/fuchsia-src/development/languages/dart/style#do_order_members_using_the_dart_analyzer)
164+
# - sort_pub_dependencies # conflicts with grouping local packages separately. Do keep groups sorted.
165+
- sort_unnamed_constructors_first
166+
- test_types_in_equals
167+
- throw_in_finally
168+
- tighten_type_of_initializing_formals
169+
- type_annotate_public_apis # note: use Object not to conflict with avoid_annotating_with_dynamic
170+
- type_init_formals
171+
- unawaited_futures
172+
- unnecessary_await_in_return
173+
- unnecessary_brace_in_string_interps
174+
- unnecessary_const
175+
- unnecessary_constructor_name
176+
## - unnecessary_final
177+
- unnecessary_getters_setters
178+
- unnecessary_lambdas
179+
- unnecessary_late
180+
- unnecessary_new
181+
- unnecessary_null_aware_assignments
182+
- unnecessary_null_checks
183+
- unnecessary_null_in_if_null_operators
184+
- unnecessary_nullable_for_final_variable_declarations
185+
- unnecessary_overrides
186+
- unnecessary_parenthesis
187+
- unnecessary_raw_strings
188+
- unnecessary_statements
189+
- unnecessary_string_escapes
190+
- unnecessary_string_interpolations
191+
- unnecessary_this
192+
- unrelated_type_equality_checks
193+
- unsafe_html
194+
- use_build_context_synchronously
195+
- use_colored_box
196+
- use_decorated_box
197+
- use_enums
198+
- use_full_hex_values_for_flutter_colors
199+
- use_function_type_syntax_for_parameters
200+
- use_if_null_to_convert_nulls_to_bools
201+
- use_is_even_rather_than_modulo
202+
# - use_key_in_widget_constructors # note: consider enabling for published libraries
203+
- use_late_for_private_fields_and_variables
204+
- use_named_constants
205+
- use_raw_strings
206+
- use_rethrow_when_possible
207+
- use_setters_to_change_properties
208+
- use_string_buffers
209+
- use_super_parameters
210+
- use_test_throws_matchers
211+
- use_to_and_as_if_applicable
212+
- valid_regexps
213+
- void_checks

lib/src/code_field/code_controller.dart

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import '../code_theme/code_theme.dart';
1313
import '../code_theme/code_theme_data.dart';
1414
import 'editor_params.dart';
1515

16-
const _MIDDLE_DOT = '·';
16+
const _middleDot = '·';
1717

1818
class CodeController extends TextEditingController {
1919
Mode? _language;
@@ -90,10 +90,10 @@ class CodeController extends TextEditingController {
9090
this.patternMap,
9191
this.stringMap,
9292
this.params = const EditorParams(),
93-
this.modifiers = const <CodeModifier>[
94-
const IntendModifier(),
95-
const CloseBlockModifier(),
96-
const TabModifier(),
93+
this.modifiers = const [
94+
IntendModifier(),
95+
CloseBlockModifier(),
96+
TabModifier(),
9797
],
9898
this.webSpaceFix = true,
9999
this.onChange,
@@ -102,9 +102,9 @@ class CodeController extends TextEditingController {
102102
this.language = language;
103103

104104
// Create modifier map
105-
modifiers.forEach((el) {
105+
for (final el in modifiers) {
106106
modifierMap[el.char] = el;
107-
});
107+
}
108108
}
109109

110110
/// Sets a specific cursor position in the text
@@ -131,7 +131,7 @@ class CodeController extends TextEditingController {
131131
}
132132

133133
final sel = selection;
134-
text = text.replaceRange(selection.start - 1, selection.start, "");
134+
text = text.replaceRange(selection.start - 1, selection.start, '');
135135

136136
selection = sel.copyWith(
137137
baseOffset: sel.start - 1,
@@ -142,7 +142,7 @@ class CodeController extends TextEditingController {
142142
/// Remove the selected text
143143
void removeSelection() {
144144
final sel = selection;
145-
text = text.replaceRange(selection.start, selection.end, "");
145+
text = text.replaceRange(selection.start, selection.end, '');
146146

147147
selection = sel.copyWith(
148148
baseOffset: sel.start,
@@ -161,7 +161,7 @@ class CodeController extends TextEditingController {
161161

162162
KeyEventResult onKey(RawKeyEvent event) {
163163
if (event.isKeyPressed(LogicalKeyboardKey.tab)) {
164-
text = text.replaceRange(selection.start, selection.end, "\t");
164+
text = text.replaceRange(selection.start, selection.end, '\t');
165165
return KeyEventResult.handled;
166166
}
167167

@@ -170,12 +170,12 @@ class CodeController extends TextEditingController {
170170

171171
/// See webSpaceFix
172172
static String _spacesToMiddleDots(String str) {
173-
return str.replaceAll(" ", _MIDDLE_DOT);
173+
return str.replaceAll(' ', _middleDot);
174174
}
175175

176176
/// See webSpaceFix
177177
static String _middleDotsToSpaces(String str) {
178-
return str.replaceAll(_MIDDLE_DOT, " ");
178+
return str.replaceAll(_middleDot, ' ');
179179
}
180180

181181
/// Get untransformed text
@@ -192,13 +192,13 @@ class CodeController extends TextEditingController {
192192
bool get _webSpaceFix => kIsWeb && webSpaceFix;
193193

194194
static String _genId() {
195-
const _chars = 'abcdefghijklmnopqrstuvwxyz1234567890';
196-
final _rnd = Random();
195+
const chars = 'abcdefghijklmnopqrstuvwxyz1234567890';
196+
final rnd = Random();
197197

198198
return String.fromCharCodes(
199199
Iterable.generate(
200200
10,
201-
(_) => _chars.codeUnitAt(_rnd.nextInt(_chars.length)),
201+
(_) => chars.codeUnitAt(rnd.nextInt(chars.length)),
202202
),
203203
);
204204
}
@@ -236,11 +236,9 @@ class CodeController extends TextEditingController {
236236
newValue = newValue.copyWith(text: _spacesToMiddleDots(newValue.text));
237237
}
238238

239-
if (onChange != null) {
240-
onChange!(
241-
_webSpaceFix ? _middleDotsToSpaces(newValue.text) : newValue.text,
242-
);
243-
}
239+
onChange?.call(
240+
_webSpaceFix ? _middleDotsToSpaces(newValue.text) : newValue.text,
241+
);
244242

245243
super.value = newValue;
246244
}
@@ -320,19 +318,17 @@ class CodeController extends TextEditingController {
320318
stack.add(currentSpans);
321319
currentSpans = tmp;
322320

323-
nodeChildren.forEach((n) {
321+
for (final n in nodeChildren) {
324322
_traverse(n);
325323
if (n == nodeChildren.last) {
326324
currentSpans = stack.isEmpty ? children : stack.removeLast();
327325
}
328-
});
326+
}
329327
}
330328
}
331329

332330
if (nodes != null) {
333-
for (var node in nodes) {
334-
_traverse(node);
335-
}
331+
nodes.forEach(_traverse);
336332
}
337333

338334
return TextSpan(style: style, children: children);
@@ -348,8 +344,8 @@ class CodeController extends TextEditingController {
348344
final patternList = <String>[];
349345

350346
if (_webSpaceFix) {
351-
patternList.add("(" + _MIDDLE_DOT + ")");
352-
styleList.add(TextStyle(color: Colors.transparent));
347+
patternList.add('($_middleDot)');
348+
styleList.add(const TextStyle(color: Colors.transparent));
353349
}
354350

355351
if (stringMap != null) {
@@ -358,7 +354,7 @@ class CodeController extends TextEditingController {
358354
}
359355

360356
if (patternMap != null) {
361-
patternList.addAll(patternMap!.keys.map((e) => "(" + e + ")"));
357+
patternList.addAll(patternMap!.keys.map((e) => '($e)'));
362358
styleList.addAll(patternMap!.values);
363359
}
364360

0 commit comments

Comments
 (0)