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".
You're calling a method named
.mapand passing more than one argument - this is all the rule is looking for. The ESlint rule doesn't understand thatPromiseis the bluebird library but thinks it's an array, and that you're calling the Arraymapmethod, where the second parameter is for thethisargument (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
Promiseas the receiver of the method call.