close

no-this-assignment

Unreleased

Configuration

PresetConfigured Value
✅ unicornPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/no-this-assignment': 'error',
    },
  },
]);

Rule Details

Disallow assigning this directly to a variable. Use this directly, an arrow function, or Function#bind() instead.

Examples of incorrect code for this rule:

const self = this;

setTimeout(function () {
  self.run();
});

Examples of correct code for this rule:

setTimeout(() => {
  this.run();
});

setTimeout(
  function () {
    this.run();
  }.bind(this),
);

Original Documentation