prefer_use_prefix
v0.4.0 Warning Fix Hook Rules
Flags functions and methods that call hooks internally but do not follow the use prefix naming convention. Custom hooks must start with use (or _use for private functions) so that the hooks framework and other lint rules can identify them as hooks.
Why use this rule
Section titled “Why use this rule”The use prefix is a critical convention in the hooks ecosystem. Without it, lint rules like avoid_conditional_hooks cannot detect that a function is a hook, leading to missed warnings. Consistent naming also helps developers immediately recognize hook functions in code review.
See also: flutter_hooks - Custom hooks
// Top-level function calling hooks without 'use' prefixString myCustomHook() { return useMemoized(() => 'hello');}
// Private function without '_use' prefixint _myPrivateHook() { return useState(0);}
class BadWidget extends HookWidget { int _fetchData() { return useState(42); }
@override Widget build(BuildContext context) { final data = _fetchData(); return Text('$data'); }}// Top-level function with 'use' prefixString useCustomHook() { return useMemoized(() => 'hello');}
// Private function with '_use' prefixint _usePrivateHook() { return useState(0);}
class GoodWidget extends HookWidget { int _useData() { return useState(42); }
@override Widget build(BuildContext context) { final data = _useData(); return Text('$data'); }}
// Regular functions that don't call hooks need no prefix:int regularFunction() => 42;Configuration
Section titled “Configuration”To disable this rule:
plugins: many_lints: diagnostics: prefer_use_prefix: false