dart-code-metrics
dart-code-metrics copied to clipboard
[BUG] - `flutter pub run dart_code_metrics:metrics check-unused-files lib` never finishes
-
Dart code metrics version: 4.14.0
-
Dart sdk version:
Dart SDK version: 2.16.2 (stable) (Tue Mar 22 13:15:13 2022 +0100) on "macos_x64"
Please show your full configuration:
Configuration
include: package:flutter_lints/flutter.yaml
analyzer:
plugins:
- dart_code_metrics
strong-mode:
implicit-casts: false
implicit-dynamic: true
errors:
undefined_prefixed_name: ignore
linter:
rules:
always_put_required_named_parameters_first: true
always_use_package_imports: true
avoid_bool_literals_in_conditional_expressions: true
avoid_classes_with_only_static_members: true
avoid_double_and_int_checks: true
avoid_dynamic_calls: true
avoid_escaping_inner_quotes: true
avoid_field_initializers_in_const_classes: true
avoid_js_rounded_ints: true
avoid_multiple_declarations_per_line: true
avoid_null_checks_in_equality_operators: true
avoid_private_typedef_functions: true
avoid_redundant_argument_values: true
avoid_returning_null_for_future: true
avoid_setters_without_getters: true
avoid_shadowing_type_parameters: true
avoid_slow_async_io: true
avoid_type_to_string: true
avoid_types_on_closure_parameters: true
avoid_unused_constructor_parameters: true
avoid_void_async: true
cancel_subscriptions: true
cascade_invocations: true
cast_nullable_to_non_nullable: true
close_sinks: true
comment_references: true
conditional_uri_does_not_exist: true
depend_on_referenced_packages: true
directives_ordering: true
empty_constructor_bodies: true
eol_at_end_of_file: true
flutter_style_todos: true
invariant_booleans: true
join_return_with_assignment: true
leading_newlines_in_multiline_strings: true
lines_longer_than_80_chars: false # We use 160: true
literal_only_boolean_expressions: true
missing_whitespace_between_adjacent_strings: true
no_adjacent_strings_in_list: true
no_logic_in_create_state: true
no_runtimeType_toString: true
noop_primitive_operations: true
null_check_on_nullable_type_parameter: true
omit_local_variable_types: true
one_member_abstracts: false # Flutter disabled it because it is useful to have abstract classes with only one member
only_throw_errors: true
package_api_docs: true
parameter_assignments: true
prefer_asserts_in_initializer_lists: true
prefer_constructors_over_static_methods: true
prefer_final_in_for_each: true
prefer_final_locals: true
prefer_foreach: true
prefer_if_elements_to_conditional_expressions: true
prefer_null_aware_method_calls: true
prefer_null_aware_operators: true
prefer_mixin: false # Has false positives, see https://github.com/dart-lang/linter/issues/3018.
prefer_single_quotes: true
public_member_api_docs: true
sized_box_shrink_expand: true
sort_child_properties_last: true
sort_constructors_first: true
sort_pub_dependencies: true
sort_unnamed_constructors_first: true
test_types_in_equals: true
throw_in_finally: true
tighten_type_of_initializing_formals: true
unawaited_futures: true
unnecessary_await_in_return: true
unnecessary_constructor_name: true
unnecessary_lambdas: true
unnecessary_late: true
unnecessary_null_aware_assignments: true
unnecessary_null_checks: true
unnecessary_nullable_for_final_variable_declarations: true
unnecessary_parenthesis: true
unnecessary_raw_strings: true
unnecessary_statements: true
unsafe_html: true
use_decorated_box: true
use_if_null_to_convert_nulls_to_bools: true
use_is_even_rather_than_modulo: true
use_key_in_widget_constructors: false
use_late_for_private_fields_and_variables: true
use_named_constants: true
use_raw_strings: true
use_setters_to_change_properties: true
use_test_throws_matchers: true
valid_regexps: true
void_checks: true
dart_code_metrics:
anti-patterns:
- long-method
- long-parameter-list
metrics:
cyclomatic-complexity: 20
maximum-nesting-level: 5
number-of-parameters: 4
source-lines-of-code: 50
metrics-exclude:
- "lib/generated_plugin_registrant.dart" # This file is automatically created when you debug on web
- "**/*.g.dart"
- "**/*.gql.dart"
rules:
- avoid-nested-conditional-expressions
- no-boolean-literal-compare
- no-empty-block:
exclude:
- test/** # we often pass empty callbacks in tests when they are required
- prefer-trailing-comma:
severity: style # default is warning and that would fail on Bitrise
- no-equal-then-else
- avoid-border-all
- avoid-returning-widgets
# It is a rule name.
# cSpell:disable-next-line
- avoid-unnecessary-setstate
- avoid-wrapping-in-padding
- prefer-const-border-radius
- avoid-missing-enum-constant-in-map
- format-comment
- no-magic-number
- prefer-async-await
- prefer-commenting-analyzer-ignores
- prefer-first
- prefer-last
What did you do? Please include the source code example causing the issue.
flutter pub run dart_code_metrics:metrics check-unused-files lib
What did you expect to happen? Something
What actually happened?
Nothing, there is no log at all.
Are you willing to submit a pull request to fix this bug?
Why not, but I have not looked at the code.
hi @incendial , you were too fast for me. I opened the issue https://github.com/dart-code-checker/dart-code-metrics/issues/810 with the wrong account
Here is the one I meant to create. Sorry for the trouble.
To answer your question https://github.com/dart-code-checker/dart-code-metrics/issues/810#issuecomment-1108229521
@ValentinVignalNovade hi, thanks for reporting the issue! It's really hard to tell, what's went wrong. Any chance, you can provide a reproduction?
I'm willing to give you more information, how do you want me to do that ? A repo ?
@ValentinVignal yes, a repo would be the best way so that I'll be able to clone it and debug this bug locally
Hello @incendial, I'm having hard time to reproduced it with a dummy/small repo. I wonder if this is because our project is starting to be quite big. Do you have some suggestion on how I could narrow down what is wrong?
@ValentinVignal could you run the command on parts of your project and check when it becomes infinite?
@ValentinVignal a kind reminder, looking forward for repro 🙂
I'm working non it. The issue is that it is happening on my company's repo which is not open source and I cannot share 😕 So I have to manage to understand where/why it is blocked. I'm currently running it in sub-folders and I'm starting to wonder if it was just very long and I wasn't patient enough.
Our lib folder has 2676 dart files, is there a possibility that this is too many for the complexity of the command?
if it was just very long and I wasn't patient enough.
That's might be true, actually. We don't have any progress indication yet.
Our lib folder has 2676 dart files, is there a possibility that this is too many for the complexity of the command?
I'm not sure, coz no one reported this problem before.
I think we can add a progress indication of some sort and you'll be able to recheck properly.
I think we can add a progress indication of some sort and you'll be able to recheck properly.
this could be a good first step yeah
![image](https://user-images.githubusercontent.com/84758580/177070573-6eb375ff-18cd-4057-a858-05f6d3b0f338.png)
@chenbokun97 any chance you can create a reproduction?
I also have this issue. I just discovered the issue occurs with analyzer
4.2.0, but downgrading analyzer
to 4.1.0 works.
I'm also seeing this issue when using
flutter pub run dart_code_metrics:metrics analyze --fatal-style --fatal-performance --fatal-warnings lib test scripts
@JCQuintas what version of dart_code_metrics and analyzer do you have?
dart_code_metrics: ^4.14.0
analyzer: 4.1.0
Can anyone create an example with this problem? I can't reproduce it locally.
https://github.com/chenbokun/flutter
@incendial I created a new flutter project and added analyzer and run flutter pub run dart_code_metrics:metrics analyze lib --set-exit-on-violation-level=warning
then it will reproduce
flutter v2.10.5
macOS 12.4
@chenbokun97 cloned the repo and downgraded to 2.10.5 - still getting the output ✔ no issues found!
. It's not instant, but still finishes
@incendial I found that there is no default exit after runCommand in AnalyzeCommand, can it be the reason?
@incendial I found that there is no default exit after runCommand in AnalyzeCommand, can it be the reason?
It should not affect the invocation anyhow, but since you have the local clone, can you add exit(0) to the end of https://github.com/dart-code-checker/dart-code-metrics/blob/b4bc57b0a82c7d09bffe87ad9d35ea145c7d8354/lib/src/cli/cli_runner.dart#L40 ?
sure, I add exit(0) and it works, now it will finish immediately I'm wondering that maybe the command timeout duration in your computer is too short so it can be done in several seconds? I have to wait for minutes until it ends
sure, I add exit(0) and it works, now it will finish immediately I'm wondering that maybe the command timeout duration in your computer is too short so it can be done in several seconds? I have to wait for minutes until it ends
Very interesting, thanks for pointing this out! Will add it to the next release
If you want to contribute, feel free to open a PR
Thanks so much, I will upgrade and test it once it releases
So glad this is finally addressed! Could you maybe push this onto another dev release so we can use it right away? We are using dart code metrics heavily, and especially the pre-commit hook takes minutes to complete due to this issue.
@inf0rmatix we plan to release the new version today, so there is no need for dev release
4.17.0 is out right now, please check if the issue is fixed
@incendial Unfortunately, this issue is still occurring for us with Dart Code Metrics 4.17.0 + Flutter 3.0.5 + analyzer 4.3.1
![]()
Also happened to me, it will never exit the command
@maxlapides you see the same result? Or not even the "no issues found" output?
@incendial updated the package, works like a charm now, proper exit code used :) thank you so much!
@incendial This is what I'm seeing in our CI system now:
> flutter pub run dart_code_metrics:metrics check-unused-files lib test packages/*/lib packages/*/test --fatal-unused --exclude='lib/**/*.pb*.dart' > danger/metrics-unused-files
pub finished with exit code -[9]