Skip to content

Commit e8a48d1

Browse files
authored
Merge pull request #93 from rainyl/better-lints
update lint rules and format
2 parents cecaf1f + 75afcab commit e8a48d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1072
-714
lines changed

analysis_options.yaml

Lines changed: 230 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,231 @@
1-
include: package:flutter_lints/flutter.yaml
1+
# include: package:solid_lints/analysis_options.yaml
22

3-
# Additional information about this file can be found at
4-
# https://dart.dev/guides/language/analysis-options
3+
# https://github.com/solid-software/solid_lints/blob/master/lib/analysis_options.yaml
4+
analyzer:
5+
plugins:
6+
- custom_lint
7+
exclude:
8+
# General generated files
9+
- '**/*.g.dart'
10+
- '**/*.gr.dart'
11+
12+
# Flutter
13+
- 'lib/generated_plugin_registrant.dart'
14+
15+
# mockito
16+
- '*.mocks.dart'
17+
- '**/*.mocks.dart'
18+
19+
# freezed
20+
- '**/*.freezed.dart'
21+
22+
# protobuf
23+
- '**/*.pb.dart'
24+
25+
# test_coverage
26+
- test/.test_coverage.dart
27+
28+
language:
29+
# We've seen errors tied to use of implicit operations similar to the ones described in
30+
# https://dart.dev/guides/language/analysis-options#enabling-additional-type-checks.
31+
# When we do things explicitly there is less room for errors.
32+
strict-casts: true
33+
# strict-raw-types: true
34+
35+
errors:
36+
missing_required_param: error
37+
missing_return: error
38+
parameter_assignments: error
39+
linter:
40+
rules:
41+
- always_declare_return_types
42+
- always_put_required_named_parameters_first
43+
# - always_use_package_imports
44+
- annotate_overrides
45+
- avoid_bool_literals_in_conditional_expressions
46+
- avoid_catching_errors
47+
- avoid_double_and_int_checks
48+
- avoid_dynamic_calls
49+
- avoid_empty_else
50+
- avoid_escaping_inner_quotes
51+
- avoid_field_initializers_in_const_classes
52+
# We are already using the `parameter_assignments` lint.
53+
# Adding final to parameters has the same effect as `parameter_assignments`
54+
# so it doesn't make sense to use final parameters with `parameter_assignments`.
55+
- avoid_final_parameters
56+
- avoid_function_literals_in_foreach_calls
57+
- avoid_implementing_value_types
58+
- avoid_init_to_null
59+
# - avoid_multiple_declarations_per_line
60+
- avoid_null_checks_in_equality_operators
61+
# - avoid_positional_boolean_parameters
62+
- avoid_print
63+
- avoid_private_typedef_functions
64+
# - avoid_redundant_argument_values
65+
- avoid_relative_lib_imports
66+
- avoid_renaming_method_parameters
67+
- avoid_return_types_on_setters
68+
- avoid_returning_null_for_void
69+
- avoid_setters_without_getters
70+
- avoid_shadowing_type_parameters
71+
- avoid_single_cascade_in_expression_statements
72+
- avoid_type_to_string
73+
- avoid_types_as_parameter_names
74+
- avoid_unnecessary_containers
75+
- avoid_unused_constructor_parameters
76+
- avoid_void_async
77+
- await_only_futures
78+
- camel_case_extensions
79+
- camel_case_types
80+
- cancel_subscriptions
81+
# Similar to avoid-non-null-assertion, which is already used,
82+
# basically it suggests to not ignore possible null value
83+
- cast_nullable_to_non_nullable
84+
- close_sinks
85+
- comment_references
86+
- conditional_uri_does_not_exist
87+
- constant_identifier_names
88+
- control_flow_in_finally
89+
- curly_braces_in_flow_control_structures
90+
- depend_on_referenced_packages
91+
- deprecated_consistency
92+
# - diagnostic_describe_all_properties
93+
- directives_ordering
94+
# Pretty much agree with Passy & linter package.
95+
# Our use case for Flutter for web where there are no flavors yet.
96+
# So using dart-define is helpful.
97+
#- do_not_use_environment
98+
- empty_catches
99+
- empty_constructor_bodies
100+
- empty_statements
101+
- eol_at_end_of_file
102+
- exhaustive_cases
103+
- file_names
104+
- hash_and_equals
105+
- implementation_imports
106+
# deprecated rule in Flutter 3.7
107+
# - invariant_booleans
108+
# - iterable_contains_unrelated_type
109+
- collection_methods_unrelated_type
110+
- join_return_with_assignment
111+
- leading_newlines_in_multiline_strings
112+
- library_names
113+
- library_prefixes
114+
# - lines_longer_than_80_chars
115+
# - list_remove_unrelated_type
116+
- literal_only_boolean_expressions
117+
- no_adjacent_strings_in_list
118+
- no_duplicate_case_values
119+
- no_leading_underscores_for_library_prefixes
120+
- no_leading_underscores_for_local_identifiers
121+
- no_logic_in_create_state
122+
- no_runtimeType_toString
123+
- non_constant_identifier_names
124+
- noop_primitive_operations
125+
- null_check_on_nullable_type_parameter
126+
- overridden_fields
127+
- package_names
128+
- package_prefixed_library_names
129+
- parameter_assignments
130+
- prefer_adjacent_string_concatenation
131+
- prefer_asserts_in_initializer_lists
132+
- prefer_collection_literals
133+
- prefer_conditional_assignment
134+
- prefer_const_constructors
135+
- prefer_const_constructors_in_immutables
136+
- prefer_const_declarations
137+
- prefer_const_literals_to_create_immutables
138+
- prefer_constructors_over_static_methods
139+
- prefer_contains
140+
# These two are incompatible, and one should be selected depending on your project's style.
141+
# - prefer_double_quotes
142+
# - prefer_single_quotes
143+
# removed in Dart 3.0.0
144+
# - prefer_equal_for_default_values
145+
# Not used, as the default app template has a single statement return code generated.
146+
# While this could be beneficial for Dart projects and maintaining code style, we are unaware
147+
# of any substantial evidence that improves code when using expression function body
148+
# vs single statement return. We are considering including this in Dart only lints.
149+
# - prefer_expression_function_bodies
150+
- prefer_final_fields
151+
- prefer_final_in_for_each
152+
- prefer_final_locals
153+
# While it is similar to `unnecessary_lambdas`,
154+
# it forcefully replaces structural/procedural semantics with
155+
# their functional counterparts.
156+
# We think this is a stylistic choice and will leave it up to users.
157+
# - prefer_foreach
158+
- prefer_for_elements_to_map_fromIterable
159+
- prefer_function_declarations_over_variables
160+
- prefer_generic_function_type_aliases
161+
- prefer_if_elements_to_conditional_expressions
162+
- prefer_if_null_operators
163+
- prefer_initializing_formals
164+
- prefer_inlined_adds
165+
- prefer_interpolation_to_compose_strings
166+
- prefer_is_empty
167+
- prefer_is_not_empty
168+
- prefer_is_not_operator
169+
- prefer_iterable_whereType
170+
- prefer_null_aware_method_calls
171+
- prefer_null_aware_operators
172+
- prefer_spread_collections
173+
- prefer_typing_uninitialized_variables
174+
- prefer_void_to_null
175+
- provide_deprecation_message
176+
# - public_member_api_docs
177+
- recursive_getters
178+
- require_trailing_commas
179+
- secure_pubspec_urls
180+
- sized_box_for_whitespace
181+
- sized_box_shrink_expand
182+
- slash_for_doc_comments
183+
- sort_child_properties_last
184+
# We tend to use class organization close to standard Java convention, where fields come first.
185+
# Martin, R. C. & Coplien, J. O. (2013), Chapter 10: Classes. Clean code: a handbook of agile software craftsmanship , Prentice Hall , Upper Saddle River, NJ [etc.] . 136
186+
# - sort_constructors_first
187+
# - sort_pub_dependencies
188+
# - sort_unnamed_constructors_first
189+
- test_types_in_equals
190+
- throw_in_finally
191+
- tighten_type_of_initializing_formals
192+
- type_annotate_public_apis
193+
- type_init_formals
194+
- unawaited_futures
195+
- unnecessary_await_in_return
196+
- unnecessary_brace_in_string_interps
197+
- unnecessary_breaks
198+
- unnecessary_const
199+
- unnecessary_getters_setters
200+
- unnecessary_lambdas
201+
- unnecessary_new
202+
- unnecessary_null_aware_assignments
203+
- unnecessary_null_checks
204+
- unnecessary_null_in_if_null_operators
205+
- unnecessary_nullable_for_final_variable_declarations
206+
- unnecessary_overrides
207+
- unnecessary_parenthesis
208+
- unnecessary_raw_strings
209+
- unnecessary_statements
210+
- unnecessary_string_escapes
211+
- unnecessary_string_interpolations
212+
- unnecessary_this
213+
- unnecessary_to_list_in_spreads
214+
- unrelated_type_equality_checks
215+
- unsafe_html
216+
- use_build_context_synchronously
217+
- use_colored_box
218+
- use_decorated_box
219+
- use_full_hex_values_for_flutter_colors
220+
- use_function_type_syntax_for_parameters
221+
- use_if_null_to_convert_nulls_to_bools
222+
- use_is_even_rather_than_modulo
223+
- use_named_constants
224+
- use_raw_strings
225+
- use_rethrow_when_possible
226+
- use_setters_to_change_properties
227+
- use_string_buffers
228+
- use_super_parameters
229+
- use_test_throws_matchers
230+
- valid_regexps
231+
- void_checks

bin/setup.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import 'package:args/command_runner.dart';
33
import 'setup_commands.dart';
44

55
void main(List<String> args) async {
6-
CommandRunner("setup", "Setup for opencv_dart")
6+
final cmd = CommandRunner("setup", "Setup for opencv_dart")
77
..addCommand(WindowsSetupCommand())
88
..addCommand(LinuxSetupCommand())
99
..addCommand(MacOsSetupCommand())
1010
..addCommand(AndroidSetupCommand())
11-
..addCommand(IosSetupCommand())
12-
..run(args);
11+
..addCommand(IosSetupCommand());
12+
await cmd.run(args);
1313
}

bin/setup_commands.dart

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import 'dart:io';
44

5-
import 'package:stack_trace/stack_trace.dart';
65
import 'package:archive/archive_io.dart';
76
import 'package:args/command_runner.dart';
8-
import 'package:yaml/yaml.dart';
97
import 'package:path/path.dart' as p;
8+
import 'package:stack_trace/stack_trace.dart';
9+
import 'package:yaml/yaml.dart';
1010

1111
const setupPkgName = "opencv_dart";
1212

@@ -19,10 +19,10 @@ abstract class BaseSetupCommand extends Command {
1919

2020
String get arch {
2121
final arch_ = argResults?["arch"] as String;
22-
return ARCH_MAP[os]?[arch_] ?? arch_;
22+
return ARCH_MAP[os]?[arch_] as String? ?? arch_;
2323
}
2424

25-
String get pkgRoot => Frame.caller(1).uri.resolve("..").toFilePath();
25+
String get pkgRoot => Frame.caller().uri.resolve("..").toFilePath();
2626

2727
bool get force => argResults?.flag("force") ?? false;
2828
String get os => name;
@@ -32,28 +32,18 @@ abstract class BaseSetupCommand extends Command {
3232
print(asInfo('Using package:$setupPkgName from $opencvRoot'));
3333

3434
final doc = loadYaml(File(p.join(opencvRoot, "pubspec.yaml")).readAsStringSync());
35-
final version = doc["binary_version"] as String;
35+
// ignore: avoid_dynamic_calls
36+
final String version = doc["binary_version"] as String;
3637
final libTarName = "libopencv_dart-$os-$downArch.tar.gz";
3738

38-
if (extractPath == null) {
39-
switch (os) {
40-
case OS.windows:
41-
extractPath = p.join(opencvRoot, "windows");
42-
break;
43-
case OS.linux:
44-
extractPath = p.join(opencvRoot, "linux");
45-
break;
46-
case OS.android:
47-
extractPath = p.join(opencvRoot, "android", "src", "main", "jniLibs", downArch);
48-
case OS.macos:
49-
extractPath = p.join(opencvRoot, "macos");
50-
case OS.ios:
51-
extractPath = p.join(opencvRoot, "ios");
52-
case OS.fuchsia:
53-
default:
54-
throw UnsupportedError(asError("Platform $os not supported"));
55-
}
56-
}
39+
extractPath ??= switch (os) {
40+
OS.windows => p.join(opencvRoot, "windows"),
41+
OS.linux => p.join(opencvRoot, "windows"),
42+
OS.android => p.join(opencvRoot, "android", "src", "main", "jniLibs", downArch),
43+
OS.macos => p.join(opencvRoot, "macos"),
44+
OS.ios => p.join(opencvRoot, "ios"),
45+
_ => throw UnsupportedError(asError("Platform $os not supported"))
46+
};
5747

5848
if (!Directory(extractPath).existsSync()) {
5949
Directory(extractPath).createSync(recursive: true);
@@ -65,7 +55,7 @@ abstract class BaseSetupCommand extends Command {
6555
if (force || !saveFile.existsSync()) {
6656
if (!saveFile.parent.existsSync()) saveFile.parent.createSync(recursive: true);
6757

68-
String url = "https://github.com/rainyl/opencv_dart/releases/download/v$version/$libTarName";
58+
final String url = "https://github.com/rainyl/opencv_dart/releases/download/v$version/$libTarName";
6959
print(asInfo("Downloading $url"));
7060
try {
7161
final request = await HttpClient().getUrl(Uri.parse(url));
@@ -86,11 +76,13 @@ abstract class BaseSetupCommand extends Command {
8676
// Check if libs already existed, avoid double-extract
8777
if (Directory(extractPath)
8878
.listSync()
89-
.map((e) =>
90-
e.path.endsWith(".so") ||
91-
e.path.endsWith(".dll") ||
92-
e.path.endsWith(".dylib") ||
93-
e.path.endsWith(".framework"))
79+
.map(
80+
(e) =>
81+
e.path.endsWith(".so") ||
82+
e.path.endsWith(".dll") ||
83+
e.path.endsWith(".dylib") ||
84+
e.path.endsWith(".framework"),
85+
)
9486
.any((e) => e)) {
9587
print(asWarning("Libs already exists in $extractPath, Skipping..."));
9688
return;
@@ -104,7 +96,7 @@ abstract class BaseSetupCommand extends Command {
10496
}
10597

10698
@override
107-
void run() async {
99+
Future<void> run() async {
108100
print(asInfo("opencv_dart: working for $os $arch"));
109101
await downloadAndExtract(arch);
110102
print(asInfo("Finished"));
@@ -126,7 +118,7 @@ class MacOsSetupCommand extends BaseSetupCommand {
126118
allowed: ["x86_64", "x64", "arm64"],
127119
mandatory: true,
128120
);
129-
argParser.addFlag("force", abbr: "f", defaultsTo: false, help: "Force download and extract");
121+
argParser.addFlag("force", abbr: "f", help: "Force download and extract");
130122
}
131123
}
132124

@@ -139,7 +131,7 @@ class WindowsSetupCommand extends BaseSetupCommand {
139131

140132
WindowsSetupCommand() {
141133
argParser.addOption("arch", abbr: "a", allowed: ["x86_64", "x64"], mandatory: true);
142-
argParser.addFlag("force", abbr: "f", defaultsTo: false, help: "Force download and extract");
134+
argParser.addFlag("force", abbr: "f", help: "Force download and extract");
143135
}
144136
}
145137

@@ -152,7 +144,7 @@ class LinuxSetupCommand extends BaseSetupCommand {
152144

153145
LinuxSetupCommand() {
154146
argParser.addOption("arch", abbr: "a", allowed: ["x86_64", "x64"], mandatory: true);
155-
argParser.addFlag("force", abbr: "f", defaultsTo: false, help: "Force download and extract");
147+
argParser.addFlag("force", abbr: "f", help: "Force download and extract");
156148
}
157149
}
158150

@@ -170,7 +162,7 @@ class AndroidSetupCommand extends BaseSetupCommand {
170162
allowed: ["x86_64", "arm64-v8a", "armeabi-v7a"],
171163
mandatory: true,
172164
);
173-
argParser.addFlag("force", abbr: "f", defaultsTo: false, help: "Force download and extract");
165+
argParser.addFlag("force", abbr: "f", help: "Force download and extract");
174166
}
175167
}
176168

@@ -188,7 +180,7 @@ class IosSetupCommand extends BaseSetupCommand {
188180
allowed: ["x86_64", "x64", "arm64", "os64"],
189181
mandatory: true,
190182
);
191-
argParser.addFlag("force", abbr: "f", defaultsTo: false, help: "Force download and extract");
183+
argParser.addFlag("force", abbr: "f", help: "Force download and extract");
192184
}
193185
}
194186

0 commit comments

Comments
 (0)