@studnicky/inline-trivial-logic
Disallows functions whose entire body is a single return (or expression body) of a trivially forwarded value: an identifier, a call expression, an awaited expression, or a chain. Functions that construct new objects (new, {}, []), access this members, or return literals are not trivial and are allowed. The auto-fix inlines the return expression.
Fixable: Yes (inlines the expression) · Options: allowLiterals, allowMemberExpressions · Suggested severity: error
✗ Incorrect
ts
// Trivial call-through
function getUser(id: string): Promise<User> {
return repository.findById(id);
}ts
// Trivial identifier forward
const wrapValue = (v: string) => v;ts
// Trivial await forward
async function fetchData(url: string): Promise<Data> {
return await http.get(url);
}✓ Correct
ts
// Adds validation logic before delegating
function getUser(id: string): Promise<User> {
validateId(id);
return repository.findById(id);
}ts
// Constructs a new object — not trivial
function createUser(name: string): User {
return new User(name);
}Options
json
{
"@studnicky/inline-trivial-logic": ["error", {
"allowLiterals": false,
"allowMemberExpressions": false
}]
}| Option | Type | Default | Description |
|---|---|---|---|
allowLiterals | boolean | false | Allow functions that return a literal value. |
allowMemberExpressions | boolean | false | Allow functions that return a member expression (e.g. obj.prop). |