no-this
Disallow this usage.
Targeted pattern scopeâ
This rule targets ThisExpression nodes.
What this rule reportsâ
- Any usage of
this
Why this rule existsâ
Explicit parameters and return values make dependencies clear and improve referential transparency.
â Incorrectâ
this.value += 1;
â Correctâ
const increment = (value: number) => value + 1;
Additional examplesâ
// â Implicit dependency on this-context
const account = {
balance: 100,
withdraw(amount: number) {
this.balance -= amount;
return this.balance;
},
};
// â
Explicit state transition function
const withdraw = (balance: number, amount: number) => balance - amount;
const nextBalance = withdraw(100, 25);
ESLint flat config exampleâ
import immutable from "eslint-plugin-immutable-2";
export default [
{
files: ["**/*.{js,mjs,cjs,ts,mts,cts,tsx}"],
plugins: { immutable },
rules: {
"immutable/no-this": "error",
},
},
];
When not to use itâ
Disable this rule for code that relies on framework-managed this binding (for example class-based decorators, Vue Options API, or legacy class components). In modern function-first modules, keeping the rule enabled improves dependency visibility.
Rule catalog ID: R910