-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Describe the rule you'd like to see implemented
If a library has an entrypoint, I'd like to report any publicly accessible elements which are not used within the library as unused.
An entrypoint is a top-level main
function, or a function annotated with @pragma(vm:entry-point)
. These files are typically:
- a VM script in
bin/
, - a web app in
web/
, - a VM tool in
tool/
, - a test like
test/**/*_test.dart
,
I think there will be very very few false positives. And perhaps any false positive indicates a code smell in library arrangement (the analyzer codebase I believe has some test files which reference another test file, each of which has a main
).
Any element which is not publicly visible should already be reported with analyzer's unused_local_variable
, unused_element
, or unused_field
diagnostics. This lint would cover publicly visible elements:
- Any public class instance members (fields, methods, constructors), even those on private classes and mixins.
- Any public top-level functions, variables, classes, enums, mixins, extensions, and typedefs.
Examples
// foo_test.dart
void main() {
test(...);
}
// Unused class
class MockStream extends Mock implements Stream {
// Unused field
int y = 7;
// Unused method
void m() {}
}
// Unused top-level function
void helper() {}
// Unused top-level variable
const x = 1;
Additional context