[BUG] check-unused-code unexpected behavior when used with injectable lib #1196
Description
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.