Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(lint): added new lints and dcm #228

Merged
merged 23 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
94145ec
refactor(lint): added new lints and fixed them
tsinis Oct 5, 2024
c87ebdf
fix(lint): tons of dcm lints adjustments
tsinis Oct 6, 2024
3a68325
refactor(lint): clean-up dcm rules that are included in all preset
tsinis Oct 9, 2024
a54d4c9
chore(deps): bump all dependencies and update related code
tsinis Oct 10, 2024
2effd08
refactor(docs): replace deprecated annotation with meaningful dartdoc
tsinis Oct 10, 2024
1099144
refactor(tests): clean-up in tests package
tsinis Oct 11, 2024
a8b7adc
refactor(tests): clean-up in languages package
tsinis Oct 11, 2024
85159fa
refactor(tests): clean-up in currencies package
tsinis Oct 11, 2024
d689c38
chore(deps): update dart_code_metrics_presets to 2.17.0
tsinis Oct 12, 2024
da5579a
refactor(tests): clean-up in countries package
tsinis Oct 12, 2024
aaa406c
feat(helpers): add maybe-when method in functional platform
tsinis Oct 12, 2024
44c26c8
docs(data): proper code reference in languages
tsinis Oct 12, 2024
22622fa
refactor: fix to-strings and shorter demonyms in countries
tsinis Oct 12, 2024
1d9889c
refactor(tests): clean-up in flags package
tsinis Oct 12, 2024
b4b88ee
refactor: unify asserts in non-flutter packages
tsinis Oct 12, 2024
2ce2fee
refactor(tests): clean-up in world countries package
tsinis Oct 12, 2024
c4db1c1
chore(dependabot): update dependency configurations and clean up comm…
tsinis Oct 12, 2024
bced018
chore(deps): update sdk constraints in world_countries's example
tsinis Oct 13, 2024
ef7c7c0
refactor: simplify search delegate methods
tsinis Oct 13, 2024
0b58a32
chore(deps): update gradle and plugin versions
tsinis Oct 13, 2024
b4c3846
fix(ci): fix codecov for currency super to string
tsinis Oct 13, 2024
7b2be13
chore(tests): integrate sealed world tests and refactor assertions
tsinis Oct 13, 2024
dd426d5
chore(ci): update world_flags workflow
tsinis Oct 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
18 changes: 5 additions & 13 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
version: 2
enable-beta-ecosystems: true
updates:
# Maintain dependencies for GitHub Actions
# Maintain dependencies for GitHub Actions.
- package-ecosystem: "github-actions"
directory: "/"
schedule:
Expand All @@ -12,19 +11,12 @@ updates:
prefix: "chore"
include: "scope"

# Maintain dependencies for Dart
# Maintain dependencies for Dart.
- package-ecosystem: "pub"
versioning-strategy: increase
directories:
- "/packages/tools/"
- "/packages/_sealed_world_tests/"
- "/packages/sealed_languages/"
- "/packages/sealed_currencies/"
- "/packages/sealed_countries/"
- "/packages/world_flags/"
- "/packages/world_flags/example/"
- "/packages/world_countries/"
- "/packages/world_countries/example/"
- packages/**/*
- tools
schedule:
interval: "weekly"
reviewers:
Expand All @@ -33,7 +25,7 @@ updates:
prefix: "chore"
include: "scope"

# Maintain dependencies for Android (example)
# Maintain dependencies for Android (examples).
- package-ecosystem: "gradle"
directories:
- "/packages/world_countries/example/android/"
Expand Down
5 changes: 1 addition & 4 deletions packages/_sealed_world_tests/lib/tests/advanced_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const _defaultRetryCount = 1; // For performance tests.
@isTest
void performanceTest(
String description,
// ignore: avoid-dynamic, strict_raw_type, it's a copy of regular test method.
FutureOr<void> Function() body, {
num durationLimit = _defaultDurationLimitInMs,
String? testOn,
Expand All @@ -41,7 +40,6 @@ void performanceTest(
void randomElementTest<T extends Object>(
String description,
Iterable<T> iterable,
// ignore: avoid-dynamic, strict_raw_type, it's a copy of regular test method.
FutureOr<void> Function(T) body, {
num durationLimit = _defaultDurationLimitInMs,
String? testOn,
Expand Down Expand Up @@ -74,7 +72,6 @@ void assertTest(
String description,
Object? Function() createInstance, {
bool shouldThrow = true,
// ignore: avoid-dynamic, strict_raw_type, it's a copy of regular test method.
FutureOr<void> Function()? alsoExpect,
String? testOn,
Timeout? timeout,
Expand All @@ -84,7 +81,7 @@ void assertTest(
int? retry,
}) =>
test(
"throws $AssertionError on $description",
description,
() async {
expect(
createInstance,
Expand Down
12 changes: 7 additions & 5 deletions packages/_sealed_world_tests/lib/tools/memory_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import "package:vm_service/vm_service_io.dart" show vmServiceConnectUri;
class MemoryTools extends MemoryUsage {
MemoryTools({super.externalUsage, super.heapCapacity, super.heapUsage});

Future<MemoryTools?> getMemoryUsage() async {
Future<MemoryTools?> get memoryUsage async {
final info = await Service.getInfo();
if (info.serverWebSocketUri == null) return null;
final service =
// ignore: avoid-nullable-tostring, this is helper method.
await vmServiceConnectUri(info.serverWebSocketUri.toString());
final virtualMachine = await service.getVM();
final isolateId = virtualMachine.isolates?.firstOrNull?.id;
Expand All @@ -28,9 +29,9 @@ class MemoryTools extends MemoryUsage {
}

Future<MemoryTools?> compareTo(MemoryTools? other) async {
final memNow = await getMemoryUsage();
final memNow = await memoryUsage;

return memNow != null ? memNow - other : null;
return memNow == null ? null : memNow - other;
}

// Define a method to calculate the difference between two MemoryTools
Expand All @@ -46,6 +47,7 @@ class MemoryTools extends MemoryUsage {
bytes == null ? 0 : (bytes / (1024 * 1024)).roundToDouble();

@override
String toString() =>
"""Memory(externalUsage: ${toMB(externalUsage)} MB, heapCapacity: ${toMB(heapCapacity)} MB, heapUsage: ${toMB(heapUsage)} MB)""";
String toString() => "Memory(externalUsage: ${toMB(externalUsage)} MB, "
"heapCapacity: ${toMB(heapCapacity)} MB, "
"heapUsage: ${toMB(heapUsage)} MB)";
}
13 changes: 7 additions & 6 deletions packages/_sealed_world_tests/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ repository: https://github.com/tsinis/sealed_world/tree/main/packages/_sealed_wo
issue_tracker: https://github.com/tsinis/sealed_world/issues

environment:
sdk: ^3.0.0
sdk: ^3.5.3

dependencies:
meta: ^1.12.0 # From Google
test: ^1.25.2 # From Google
vm_service: ^14.2.1 # From Google
meta: ^1.15.0 # Specific version for the flags package. From Google
test: ^1.25.7 # Specific version for the flags package. From Google
vm_service: ^14.2.5 # Specific version for the flags package. From Google

dev_dependencies:
dart_code_linter: ^1.1.3 # Ex-DCM.
lints: ^4.0.0 # From Google
dart_code_linter: ^1.1.5 # Ex-DCM.
dart_code_metrics_presets: ^2.17.0
lints: ^5.0.0 # From Google
115 changes: 71 additions & 44 deletions packages/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ analyzer:
- dart_code_metrics

dart_code_metrics:
extends:
- package:dart_code_metrics_presets/all.yaml
anti-patterns:
- long-parameter-list:
ignore-optional: true
Expand All @@ -58,10 +60,56 @@ dart_code_metrics:
metrics-exclude:
- test/**
rules:
# Disabled:
- arguments-ordering: false # This will be a breaking change.
- avoid-collection-equality-checks: false # Doesn't work for models exclude.
- avoid-collection-mutating-methods: false # Mostly false positives.
- avoid-duplicate-collection-elements: false # They are being used on purpose.
- avoid-ignoring-return-values: false # Mostly, collection methods are ignored.
- avoid-inferrable-type-arguments: false # Against prefer-explicit-type-arguments.
- avoid-long-files: false # A lot of data and collections.
- avoid-long-functions: false # Cannot get exclude to work with tests...
- avoid-nullable-interpolation: false # Doesn't work for toString() methods.
- avoid-unsafe-collection-methods: false # They are being used on purpose.
- enum-constants-ordering: false # This might be a breaking change.
- match-getter-setter-field-names: false # Most of those are just aliases.
- no-equal-arguments: false # Not our use-case here.
- no-magic-number: false # Packages contain a lot of numbers.
- no-magic-string: false # Packages contain a lot of strings.
- parameters-ordering: false # This will be a breaking change.
- prefer-boolean-prefixes: false # This will be a breaking change.
- prefer-correct-throws: false # No meta in Dart packages.
- prefer-explicit-parameter-names: false # This will be dev. defined.
- prefer-prefixed-global-constants: false # This will be a breaking change.
- prefer-single-declaration-per-file: false # Data is stored in one file.
- prefer-test-matchers: false # Introduces coupling in tests.
# Enabled:
- avoid-high-cyclomatic-complexity:
threshold: 40
- prefer-named-parameters:
max-number: 3
- avoid-nested-conditional-expressions:
acceptable-level: 2
acceptable-level: 2
- prefer-correct-identifier-length:
exceptions: ["i", "x", "y", "sb"] # i for index, x/y for math operations, sb for StringBuffer.
# i for index, x/y for math operations, sb for StringBuffer, io for IO,
# bc for BuildContext, a and b are convenient for sorting, e for the element,
# k for key, v for value.
exceptions: ["a", "b", "e", "i", "k", "v", "x", "y", "io", "bc", "sb"]
- avoid-long-parameter-list:
ignore-optional: true
- prefer-widget-private-members:
ignore-static: true
- avoid-type-casts:
exclude:
- "*_json.dart"
- prefer-typedefs-for-callbacks:
ignore-fields: true
ignore-parameters: true
ignore-type-arguments: false
ignore-return-types: false
- avoid-passing-self-as-argument:
exclude:
- test/**
- avoid-top-level-members-in-tests:
exclude:
- test/data/*.dart
Expand All @@ -72,9 +120,16 @@ dart_code_metrics:
include-assertions:
- verify
- verifyZeroInteractions
- assertTest
- testPickerBody
- testPickerInDialog
- testPickerInSearch
- testPickerInModal
- avoid-passing-async-when-sync-expected:
exclude:
- test/**
- avoid-returning-widgets:
allow-nullable: true
- avoid-redundant-async:
exclude:
- test/**
Expand All @@ -98,64 +153,32 @@ dart_code_metrics:
exclude:
- "**/data/**.data.dart"
- "**/translations/**.l10n.dart"
- arguments-ordering:
child-last: true
- avoid-banned-imports: true
- avoid-cascade-after-if-null: true
- avoid-collection-methods-with-unrelated-types: true
- avoid-double-slash-imports: true
- avoid-duplicate-exports: true
- avoid-dynamic: true
- avoid-global-state: true
- avoid-missing-enum-constant-in-map: true
- avoid-non-null-assertion: true
- avoid-substring: true
- avoid-throw-in-catch-block: true
- avoid-unnecessary-conditionals: true
- avoid-unnecessary-type-assertions: true
- avoid-unnecessary-type-casts: true
- avoid-unrelated-type-assertions: true
- avoid-unused-parameters: true
- ban-name: true
- binary-expression-operand-order: true
- double-literal-format: true
- list-all-equatable-fields: true
- newline-before-return: true
- no-boolean-literal-compare: true
- no-empty-block: true
- no-equal-then-else: true
- no-object-declaration: true
- prefer-async-await: true
- prefer-commenting-analyzer-ignores: true
- prefer-conditional-expressions: true
- prefer-correct-test-file-name: true
- prefer-correct-type-name: true
- prefer-enums-by-name: true
- prefer-first: true
- prefer-immediate-return: true
- prefer-iterable-of: true
- prefer-last: true
- prefer-moving-to-variable: true
- prefer-trailing-comma: true
- tag-name: true

linter:
rules:
# Disabled:
always_put_control_body_on_new_line: false # Makes code harder to read.
omit_local_variable_types: false # Conflicts with: prefer-type-over-var.
always_specify_types: false # Conflicts with: omit_local_variable_types.
always_use_package_imports: false # Conflicts with: prefer_relative_imports.
avoid_classes_with_only_static_members: false # Conflicts with: prefer-static-class
avoid_equals_and_hash_code_on_mutable_classes: false # We have no access to meta here.
flutter_style_todos: false # Not a Flutter team.
# omit_obvious_local_variable_types: true # Conflicts with: specify_nonobvious_local_variable_types. #TODO! After Dart 3.6 is released.
prefer_final_parameters: false # Conflicts with: avoid_final_parameters.
prefer_single_quotes: false # Conflicts with: prefer_double_quotes.
unnecessary_final: false # Conflicts with: prefer_final_locals.
unnecessary_library_name: false # To prevent breaking changes for those who use this libs.

# Enabled:
always_declare_return_types: true
always_put_required_named_parameters_first: true
always_require_non_null_named_parameters: true
annotate_overrides: true
annotate_redeclares: true
avoid_annotating_with_dynamic: true
avoid_bool_literals_in_conditional_expressions: true
avoid_catches_without_on_clauses: true
avoid_catching_errors: true
avoid_double_and_int_checks: true
avoid_dynamic_calls: true
Expand Down Expand Up @@ -207,10 +230,10 @@ linter:
depend_on_referenced_packages: true
deprecated_consistency: true
deprecated_member_use_from_same_package: true
diagnostic_describe_all_properties: true
directives_ordering: true
discarded_futures: true
do_not_use_environment: true
document_ignores: true
empty_catches: true
empty_constructor_bodies: true
empty_statements: true
Expand All @@ -223,6 +246,7 @@ linter:
implicit_call_tearoffs: true
implicit_reopen: true
invalid_case_patterns: true
invalid_runtime_check_with_js_interop_types: true
join_return_with_assignment: true
leading_newlines_in_multiline_strings: true
library_annotations: true
Expand All @@ -232,6 +256,7 @@ linter:
lines_longer_than_80_chars: true
literal_only_boolean_expressions: true
matching_super_parameters: true
missing_code_block_language_in_doc_comment: true
missing_whitespace_between_adjacent_strings: true
no_adjacent_strings_in_list: true
no_default_cases: true
Expand All @@ -246,7 +271,6 @@ linter:
noop_primitive_operations: true
null_check_on_nullable_type_parameter: true
null_closures: true
omit_local_variable_types: true
one_member_abstracts: true
only_throw_errors: true
overridden_fields: true
Expand Down Expand Up @@ -301,13 +325,15 @@ linter:
sort_constructors_first: true
sort_pub_dependencies: true
sort_unnamed_constructors_first: true
# specify_nonobvious_local_variable_types: true #TODO! After Dart 3.6 is released.
test_types_in_equals: true
throw_in_finally: true
tighten_type_of_initializing_formals: true
type_annotate_public_apis: true
type_init_formals: true
type_literal_in_constant_pattern: true
unawaited_futures: true
unintended_html_in_doc_comment: true
unnecessary_await_in_return: true
unnecessary_brace_in_string_interps: true
unnecessary_breaks: true
Expand Down Expand Up @@ -348,5 +374,6 @@ linter:
use_super_parameters: true
use_test_throws_matchers: true
use_to_and_as_if_applicable: true
# use_truncating_division: true #TODO! After Dart 3.6 is released.
valid_regexps: true
void_checks: true
33 changes: 11 additions & 22 deletions packages/flutter_analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,24 @@ include: analysis_options.yaml

dart_code_metrics:
rules:
- always-remove-listener: true
- avoid-border-all: true
- avoid-expanded-as-spacer: true
- avoid-returning-widgets: true
- avoid-shrink-wrap-in-lists: true
- avoid-unnecessary-setstate: true
- avoid-wrapping-in-padding: true
- check-for-equals-in-render-object-setters: true
- consistent-update-render-object: true
- prefer-const-border-radius: true
- prefer-correct-edge-insets-constructor: true
- prefer-define-hero-tag: true
- prefer-extracting-callbacks: true
- prefer-intl-name: true
- prefer-single-widget-per-file: true
- prefer-using-list-view: true
- provide-correct-intl-args: true
- use-setstate-synchronously: true
# Disabled:
- avoid-duplicate-cascades: false # Conflicts with CustomPainters.
# Enabled:
- avoid-long-files:
exclude:
- lib/**/*_painter.dart
- avoid-similar-names:
similarity-threshold: 0.8
ignored-names:
- path

linter:
rules:
avoid_equals_and_hash_code_on_mutable_classes: true
avoid_unnecessary_containers: true
avoid_web_libraries_in_flutter: true
diagnostic_describe_all_properties: false # TODO? Enable and fix this in the far-future.
no_logic_in_create_state: true
public_member_api_docs: true
sized_box_for_whitespace: true
sized_box_shrink_expand: true
sort_child_properties_last: true
Expand All @@ -36,6 +28,3 @@ linter:
use_decorated_box: true
use_full_hex_values_for_flutter_colors: true
use_key_in_widget_constructors: true

# TODO? Enable and fix this in the far-future.
diagnostic_describe_all_properties: false
Loading
Loading