unicorn/no-this-assignment Pedantic
무엇을 하는가
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();사용 방법
구성 파일이나 명령줄 인터페이스에서 이 규칙을 활성화하려면 다음을 사용할 수 있습니다:
json
{
"rules": {
"unicorn/no-this-assignment": "error"
}
}bash
oxlint --deny unicorn/no-this-assignment