This rule raises an issue when array methods like map(), filter(), find(), etc. are called with a thisArg parameter.
JavaScript array methods accept an optional thisArg parameter that sets the this context for the callback function. However, using this parameter often leads to confusion and less readable code.
There are several problems with using thisArg:
Arrow functions ignore thisArg: Arrow functions don’t have their own this context and cannot be bound to a different this value. When you pass a thisArg with an arrow function, it has no effect, making the code misleading.
Regular functions become less explicit: When using regular functions with thisArg, the relationship between the callback and the context object becomes less clear. Readers must understand that the second parameter affects the this binding inside the callback.
Better alternatives exist: Modern JavaScript provides clearer ways to access external values in callbacks. You can directly reference variables from the outer scope, use explicit binding with .bind(), or restructure the code to avoid this altogether.
Using thisArg makes code harder to understand and maintain, especially for developers who may not be familiar with JavaScript’s complex this binding rules.
Using thisArg unnecessarily can lead to:
thisArg, developers might expect the this binding to work, but it doesn’tthis behaviorthis binding without clear indicationRemove the unnecessary thisArg parameter when using arrow functions, since arrow functions ignore the this binding.
const results = items.map(item => transform(item), context); // Noncompliant
const results = items.map(item => transform(item));