unicorn/no-this-assignment 細かい
何をするか
this を変数に代入することを禁止します。
なぜ悪いのか
this を変数に代入することは不要で、混乱を招きます。
例
このルールに違反する不適切なコードの例:
javascript
const foo = this;
class Bar {
method() {
foo.baz();
}
}
new Bar().method();このルールに準拠する適切なコードの例:
javascript
class Bar {
constructor(fooInstance) {
this.fooInstance = fooInstance;
}
method() {
this.fooInstance.baz();
}
}
new Bar(this).method();使用方法
設定ファイルまたは CLI でこのルールを有効化するには、次のようにします:
json
{
"rules": {
"unicorn/no-this-assignment": "error"
}
}bash
oxlint --deny unicorn/no-this-assignment