This repository was archived by the owner on Jul 16, 2023. It is now read-only.
This repository was archived by the owner on Jul 16, 2023. It is now read-only.
[BUG] unused_code doesn't recognize code used with conditional imports #1083
Closed
Description
- Dart code metrics version: 5.0.1
- Dart sdk version: 2.18.5
Please show your full configuration:
Default configuration, i've just added code metrics to the project
What did you do? Please include the source code example causing the issue.
Here is a sample project with reproducible issue. I've split implementation for Web & IO, using conditional import:
import 'client.dart'
if (dart.library.html) 'client_web.dart'
if (dart.library.io) 'client_io.dart';
and used fabric method like this
SomeClient createClient() => throw Exception('Stub factory');
to create specific client for each env. However, if i run check-unused-code
, it fails, considering these fabrics aren't used
code_metrics_conditional_import % flutter pub run dart_code_metrics:metrics check-unused-code lib
✔ Analysis is completed. Preparing the results: 6.4s
lib/client_io.dart:
⚠ unused function createClient
at /Users/lavinov/Development/Flutter/code_metrics_conditional_import/lib/client_io.dart:4:1
lib/client_web.dart:
⚠ unused function createClient
at /Users/lavinov/Development/Flutter/code_metrics_conditional_import/lib/client_web.dart:5:1
✖ total unused code (classes, functions, variables, extensions, enums, mixins and type aliases) - 2
pub finished with exit code 1
What did you expect to happen?
These methods should be considered as used
What actually happened?
Error above
Are you willing to submit a pull request to fix this bug?
No, currently it easily can be worked around using // ignore: unused-code