Cross-file rule. This rule runs in falcon's whole-project pass, analyzing relationships across every file rather than one file at a time. Configure it under the top-level cross-file key, and expect it to do more work on large projects than a single-file rule.
Report public top-level declarations that nothing references.
Flags a public top-level declaration in lib/ — a class, mixin, enum,
typedef, extension type, function, or variable — whose name appears nowhere
else in the project, neither in another file nor elsewhere in its own file.
An unreferenced public API is usually dead code that outlived its callers,
but removing something still in use is worse than missing one, so the rule is
tuned to avoid false positives: it exempts main, annotated declarations,
members of re-exported files, and unnamed extensions, treats any same-name
identifier anywhere as usage, and skips files that failed to parse. Private
(_-prefixed) declarations are out of scope. This is a cross-file rule: it
runs in the cross-file pass over the whole analyzed file set and is
configured under the top-level cross-file section rather than linter.
Invalid
api.dartdart
// Public API surface exercising unused-code.// Referenced from main.dart → live.classPublicUsed {}
// Never referenced anywhere else → dead public class.classPublicUnused {}
// Private: never a candidate, regardless of usage.class _PrivateClass {}
// Annotated declarations are exempt (annotations often imply framework use).@Deprecated('legacy')
classAnnotatedUnused {}
// Referenced from main.dart → live.void usedFn() {}
// Never referenced elsewhere → dead public function.void publicUnusedFn() {}
// Referenced within THIS file (by _useLocal) → used, not dead. dcl counts// same-file references as usage, so this must NOT be flagged.classOnlyLocal {}
// Never referenced anywhere, including its own file → dead public class.classNeverReferenced {}
void _useLocal() {
OnlyLocal();
_PrivateClass();
}
// Referenced only from a string interpolation in THIS file → still used. The// lexer folds interpolated identifiers into the string token, so the rule must// look inside `${...}`; otherwise this is a false positive.classInterpolatedOnly {}
String _describe() => 'value: ${InterpolatedOnly()}';
api.dartPublic class 'PublicUnused' is never referenced anywhere in the project; remove it
6// Never referenced anywhere else → dead public class.
7classPublicUnused {}
∙
api.dartPublic declaration 'publicUnusedFn' is never referenced anywhere in the project; remove it
19// Never referenced elsewhere → dead public function.
20void publicUnusedFn() {}
∙
api.dartPublic class 'NeverReferenced' is never referenced anywhere in the project; remove it
26// Never referenced anywhere, including its own file → dead public class.
27classNeverReferenced {}
∙
How to configure
Set the severity of unused-code in your falcon.json under the cross-file section: