'XO Lint Issue Using Promise.map unicorn/no-array-method-this-argument
I am using XO for linting my code, and I cannot figure out why this lint error is being reported for the following code...
import Promise from 'bluebird';
const handler = items => {
return Promise.map(items, item => {
return Promise.resolve(item);
});
};
export default handler;
When I save this to lint-test.js, and then run the following command...
npx xo lint-test.js
I get this error...
lint-test.js:4:29
✖ 4:29 Do not use the this argument in Array#map(). unicorn/no-array-method-this-argument
1 error
The reference for this rule is here... https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-array-method-this-argument.md
I must be missing something simple. I know this is an oversimplified example, but of course, in my real code, I am doing something more interesting with "item".
Solution 1:[1]
You're calling a method named .map
and passing more than one argument - this is all the rule is looking for. The ESlint rule doesn't understand that Promise
is the bluebird library but thinks it's an array, and that you're calling the Array map
method, where the second parameter is for the this
argument (and which the warning says you shouldn't use).
It's a false positive.
Remove the rule from your settings, ignore it for that line, or make a PR to add an exception for Promise
as the receiver of the method call.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Bergi |