Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

feat: add check unused code command #649

Merged
merged 7 commits into from
Jan 17, 2022
Merged

feat: add check unused code command #649

merged 7 commits into from
Jan 17, 2022

Conversation

incendial
Copy link
Member

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[ ] Bug fix
[ ] New rule
[ ] Changes an existing rule
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[X] Other, please explain: new command

What changes did you make? (Give an overview)

This implementation is a first iteration of unused code check, it checks for top level declarations usage, such as:

  • top level variables
  • top level functions
  • enums
  • classes
  • mixins
  • extensions
  • type aliases (a.k.a. typedefs)

In the next iterations we should add checks for specific class method / properties / getters usage, but this command already brings a lot of value to our users, so let's not block the release on this.

@incendial incendial added type: enhancement New feature or request area-commands labels Jan 15, 2022
@incendial incendial added this to the 4.10.0 milestone Jan 15, 2022
@incendial incendial self-assigned this Jan 15, 2022
@incendial
Copy link
Member Author

@diegoveloper @lukepighetti hope it's the command you were looking for. Do you want to "beta-test" it?

@diegoveloper
Copy link
Contributor

@diegoveloper @lukepighetti hope it's the command you were looking for. Do you want to "beta-test" it?

Ohh nice!! We'll try the next week

@github-actions
Copy link

github-actions bot commented Jan 15, 2022

Dart Code Metrics unused files report of dart_code_metrics. ✅

Summary

  • Scanned package folders: bin, example, lib
  • No unused files found! ✅

@github-actions
Copy link

github-actions bot commented Jan 15, 2022

Dart Code Metrics analyze report of dart_code_metrics. ✅

Summary

  • Scanned folders: bin, example, lib, test

  • Total scanned files: 375

  • Total lines of source code: 6739

  • Total classes: 251

  • Average Cyclomatic Number per line of code: 0.35 / 1

  • Average Source Lines of Code per method: 6

  • Total tech debt: 1094.0 hours

  • Found issues: 6 ⚠

@codecov
Copy link

codecov bot commented Jan 15, 2022

Codecov Report

Merging #649 (e655d1e) into master (26ca53e) will decrease coverage by 0.16%.
The diff coverage is 83.80%.

❗ Current head e655d1e differs from pull request most recent head 756ffe8. Consider uploading reports for the commit 756ffe8 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #649      +/-   ##
==========================================
- Coverage   86.17%   86.01%   -0.17%     
==========================================
  Files         235      247      +12     
  Lines        5049     5319     +270     
==========================================
+ Hits         4351     4575     +224     
- Misses        698      744      +46     
Impacted Files Coverage Δ
...ib/src/cli/commands/check_unused_code_command.dart 55.88% <55.88%> (ø)
...lyzers/unused_code_analyzer/used_code_visitor.dart 63.88% <63.88%> (ø)
lib/src/config_builder/config_builder.dart 82.60% <75.00%> (-1.61%) ⬇️
...yzers/unused_code_analyzer/unused_code_config.dart 80.00% <80.00%> (ø)
...ers/unused_code_analyzer/unused_code_analyzer.dart 98.71% <98.71%> (ø)
.../src/analyzers/lint_analyzer/rules/rule_utils.dart 100.00% <100.00%> (ø)
...used_code_analyzer/models/file_elements_usage.dart 100.00% <100.00%> (ø)
..._code_analyzer/models/unused_code_file_report.dart 100.00% <100.00%> (ø)
...unused_code_analyzer/models/unused_code_issue.dart 100.00% <100.00%> (ø)
...zers/unused_code_analyzer/public_code_visitor.dart 100.00% <100.00%> (ø)
... and 53 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 26ca53e...756ffe8. Read the comment docs.

..addFlag(
FlagNames.fatalOnUnused,
help: 'Treat find unused file as fatal.',
// TODO(dkrutrkikh): activate on next major version
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@incendial I think for new commands we can activate immediately

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep all commands in sync

@dkrutskikh
Copy link
Member

@incendial please add test like test/src/cli/commands/check_unused_files_command_test.dart and update readme.md at line 123

@incendial incendial requested a review from dkrutskikh January 17, 2022 17:47
@dkrutskikh dkrutskikh merged commit 818358d into master Jan 17, 2022
@dkrutskikh dkrutskikh deleted the check-unused-code branch January 17, 2022 18:39
@diegoveloper
Copy link
Contributor

hey @incendial , thanks for this new command, one question, is the excluding files working?

I ran the command : flutter pub run dart_code_metrics:metrics check-unused-code lib (4.10.0-dev.1).

And the output contains a lot of *.g.dart: files. Checking the documentation https://dartcodemetrics.dev/docs/cli/check-unused-code

Screen Shot 2022-01-18 at 11 49 14 AM

It says that the it's excluding those files by default.

@dkrutskikh
Copy link
Member

@diegoveloper can we move discussion to the issue #653 ?

@incendial
Copy link
Member Author

@diegoveloper hi, this should fix the problem #654

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants