absolute/no-useless-function
Disallow functions that take no parameters and just return an object literal, unless used as a callback.
#Rule Details
Flags a zero-parameter arrow function whose concise body is an object literal (() => ({ ... })). Wrapping a constant object in a parameterless function adds a call with no benefit — export the object directly so callers reference the value, not a thunk.
The important exception is when the arrow is passed directly as a callback argument to a function call. That covers react-spring’s useSpring(() => ({ ... })), where the function form is required. Arrows with parameters, block bodies, or non-object returns are never flagged.
#Examples
const getConfig = () => ({ tension: 200, friction: 20 });// Export the object directly
export const springConfig = { tension: 200, friction: 20 };
const withArg = (x: number) => ({ value: x }); // has a parameterCallback arguments are exempt
// Used as a callback — allowed (covers react-spring)
const [boxSprings, boxApi] = useSpring(() => ({ opacity: 1 }));#Configuration
Enable this rule in your ESLint configuration:
{
rules: {
'absolute/no-useless-function': 'error'
}
}#Related Rules
#When Not To Use It
If you intentionally return fresh object instances to avoid shared-reference mutation (each call producing a new object), keep the function and disable the rule for it.