Skip to content

Latest commit

Β 

History

History
56 lines (42 loc) Β· 2.71 KB

File metadata and controls

56 lines (42 loc) Β· 2.71 KB

Disallow using the this argument in array methods

πŸ’Ό This rule is enabled in the following configs: βœ… recommended, β˜‘οΈ unopinionated.

πŸ”§πŸ’‘ This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.

The rule disallows using the thisArg argument in array methods:

  • If the callback is an arrow function or a bound function, the thisArg won't affect it.
  • If you intent to use a custom this in the callback, it's better to use the variable directly or use callback.bind(thisArg).

This rule checks following array methods accepts thisArg:

This rule is fixable when the callback is an arrow function and the thisArg argument has no side effect.

Examples

// ❌
const foo = bar.find(element => isUnicorn(element), baz);

// βœ…
const foo = bar.find(element => isUnicorn(element));
// ❌
const foo = bar.map(function (element) {
	return this.unicorn(element);
}, baz);

// βœ…
const foo = bar.map(function (element) => {
	return baz.unicorn(element);
});

// βœ…
const foo = bar.map(function (element) => {
	return this.unicorn(element);
}.bind(baz));