useSpreadOverApply (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.3.6 - Diagnostic Category:
lint/style/useSpreadOverApply - This rule isn’t recommended, so you need to enable it.
- This rule has an unsafe fix.
- The default severity of this rule is information.
- Sources:
- Same as
prefer-spread - Inspired from
e18e/prefer-spread-syntax
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "style": { "useSpreadOverApply": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”foo.apply(null, args);code-block.js:1:1 lint/style/useSpreadOverApply FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Use the spread operator instead of apply().
> 1 │ foo.apply(null, args);
│ ^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ apply() calls a function with arguments provided as an array. The spread operator does the same and is easier to read.
ℹ Unsafe fix: Use the spread operator.
1 │ - foo.apply(null,·args);
1 │ + foo(...args);
2 2 │
foo.apply(null, [1, 2, 3]);code-block.js:1:1 lint/style/useSpreadOverApply FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Use the spread operator instead of apply().
> 1 │ foo.apply(null, [1, 2, 3]);
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ apply() calls a function with arguments provided as an array. The spread operator does the same and is easier to read.
ℹ Unsafe fix: Use the spread operator.
1 │ - foo.apply(null,·[1,·2,·3]);
1 │ + foo(...[1,·2,·3]);
2 2 │
foo.apply(undefined, args);code-block.js:1:1 lint/style/useSpreadOverApply FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Use the spread operator instead of apply().
> 1 │ foo.apply(undefined, args);
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ apply() calls a function with arguments provided as an array. The spread operator does the same and is easier to read.
ℹ Unsafe fix: Use the spread operator.
1 │ - foo.apply(undefined,·args);
1 │ + foo(...args);
2 2 │
obj.foo.apply(obj, args);code-block.js:1:1 lint/style/useSpreadOverApply FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Use the spread operator instead of apply().
> 1 │ obj.foo.apply(obj, args);
│ ^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ apply() calls a function with arguments provided as an array. The spread operator does the same and is easier to read.
ℹ Unsafe fix: Use the spread operator.
1 │ - obj.foo.apply(obj,·args);
1 │ + obj.foo(...args);
2 2 │
foo(...args);
obj.foo(...args);
foo.apply(obj, [1, 2, 3]);Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.