gspot/no-trivial-functions
Reports named functions with two statements or fewer at the default limit.
- The count includes nested callbacks.
- Exempts inline function values, recursive functions, and type predicates.
- Accessors, overrides, and decorated methods retain their language contracts.
- Constructors that set state remain exempt.
- The inherited-method exemption needs type information.
- A function used in two or more places, or exported, is not reported.
The all config turns it on.
An unnecessary function adds another name and another place to read.
What to do
Section titled “What to do”Inline the function at its call sites and delete it.
Example
Section titled “Example”The function function one() { return 1; } reports trivial at the default limit of two statements. Replace its calls with the value 1 and delete the function. A function written inline as an argument keeps its place, because the call takes a function.
Options
Section titled “Options”| Option | Type | Default | What it does |
|---|---|---|---|
trivialStatements |
Whole number | 2 |
Functions with this many statements or fewer are reported. |