src/content/docs/linter/rules/use-spread.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> :::caution This rule is part of the [nursery](/linter/#nursery) group. This means that it is experimental and the behavior can change at any time. ::: ## Summary - Rule available since: `v2.3.6` - Diagnostic Category: [`lint/nursery/useSpread`](/reference/diagnostics#diagnostic-category) - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`prefer-spread`](https://eslint.org/docs/latest/rules/prefer-spread) - Inspired from [`e18e/prefer-spread-syntax`](https://github.com/e18e/eslint-plugin){
"linter": {
"rules": {
"nursery": {
"useSpread": "error"
}
}
}
}
Enforce the use of the spread operator over .apply().
The apply() method is used to call a function with a given this value and arguments provided as an array.
The spread operator ... can be used to achieve the same result, which is more concise and easier to read.
foo.apply(null, args);
foo.apply(null, [1, 2, 3]);
foo.apply(undefined, args);
obj.foo.apply(obj, args);
foo(...args);
obj.foo(...args);
foo.apply(obj, [1, 2, 3]);