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

[BUG] check-unused-code unexpected behavior when used with injectable lib #1196

Closed
1 task
ivan-semkin opened this issue Feb 22, 2023 · 11 comments
Closed
1 task
Assignees
Labels
area-unused-code type: bug Something isn't working waiting for release Will be available after new version is released
Milestone

Comments

@ivan-semkin
Copy link

ivan-semkin commented Feb 22, 2023

Environment and configuration

DCM version: 5.5.1
Dart SDK version: 2.19.2

What did you do?

I have a project that consists of the main lib/ folder, and several sub-packages in common/ and stuff/ folders.
When running flutter pub run dart_code_metrics:metrics check-unused-code with both --monorepo and without it, the linter seemed to only analyze the contents of the main package (i.e. the lib/ folder).

So I figured that I might use this command to achieve my desired result of analyzing all the subpackages by listing them manually:
flutter pub run dart_code_metrics:metrics check-unused-code lib common/ stuff/

And it did the trick. For some time at least.

What did you expect to happen?

I expected the tool to analyze my entire project.

What actually happened?

When used together with the injectable library, check-unused-code marks the -Impl classes in stuff/ subpackage as unused, even though it's being referenced in the main package as folows:

lib/di/injectors.config.dart:

    gh.factory<_i31.ExampleDataHolder>(() =>
        _i941.ExampleDataHolderImpl(gh<_i939.PreferencesEditor>()));

stuff/example_data_holder.dart:

@Injectable(as: ExampleDataHolder)
class ExampleDataHolderImpl extends BaseExampleDataHolder
    implements ExampleDataHolder {
  const ExampleDataHolderImpl(super.preferencesEditor);
}

injectors.config.dart is auto-generated, but does not follow the pattern specified in the docs: {/**.g.dart,/**.freezed.dart}

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

I'd also like to know whether my approach to analyzing all sub-packages is valid and correct.

Let me know if you need a more comprehensive sample, I will create a repo with a reproduction.

@ivan-semkin ivan-semkin added the type: bug Something isn't working label Feb 22, 2023
@incendial
Copy link
Member

Thank you for submitting the bug, looks like _i941.ExampleDataHolderImpl reference is not picked up correctly. Could you please create a repro so I can run my tests on it?

I'd also like to know whether my approach to analyzing all sub-packages is valid and correct.

You need to list the folders manually, there is no such thing as "autodiscoverability" for any folder, except lib.

@incendial incendial added area-unused-code awaiting info Requires more information from the customer to progress labels Feb 23, 2023
@incendial
Copy link
Member

@ivan-semkin-gismart any chance you can create a repro?

@ivan-semkin
Copy link
Author

@incendial I will. Sorry for the delay, been busy at work

@github-actions github-actions bot removed the awaiting info Requires more information from the customer to progress label Feb 27, 2023
@incendial
Copy link
Member

No problem and thank you! Waiting for the repro then.

@vanyasem
Copy link

(I am the same person that reported this issue initially)

I finally figured this out. This only happens when the analyzed file is a part of of some other file

@vanyasem
Copy link

vanyasem commented Mar 11, 2023

https://github.com/vanyasem/dart-code-metrics-issue-repro

I made an incredibly small reproduction there ^

There is no meaningful code there, you don't even need to launch it. It's just a default flutter counter app. It's specifically made to showcase an issue in check-unused-code cli command with part of files.

Please do not run generation manually, the precompiled files are already included in the repo.

You'd just need to pub get in the root project, and run pub get in the stuff subproject.

@incendial
Copy link
Member

Thanks for the repro! Good news that the Teams version works fine on this example.
I'll check whether this difference is portable to this version.

@incendial
Copy link
Member

Fixed, thanks again for the report + repro. Will become available in the next release.

@incendial incendial added the waiting for release Will be available after new version is released label Mar 20, 2023
@incendial incendial added this to the 5.7.0 milestone Mar 20, 2023
@ivan-semkin
Copy link
Author

ivan-semkin commented Mar 20, 2023

thank you, much appreciated. I will close the issue for now, will reopen if I still manage to reproduce it later

@ivan-semkin
Copy link
Author

can confirm, the issue was fixed in 5.7.0. thank you once again

@incendial
Copy link
Member

Thank you, great to hear!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-unused-code type: bug Something isn't working waiting for release Will be available after new version is released
Projects
None yet
Development

No branches or pull requests

3 participants