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' prefixValueNotifier<int> _myPrivateHook() { return useState(0);}
class BadWidget extends HookWidget { ValueNotifier<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”This rule is in the pedantic preset, so it is enabled by preset: pedantic or by name:
rules: prefer_use_prefix: trueTo turn it off again:
rules: prefer_use_prefix: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”prefer_use_callback— Use ‘useCallback’ instead of ‘useMemoized’ for memoizing functions.avoid_hooks_outside_build— Only call hooks from a hook context.avoid_misused_hooks— Don’t call hooks inside loops.avoid_unnecessary_enum_prefix— Drop an enum name repeated in its own constants.