oxc/no-this-in-exported-function 의심스러움
작동 방식
내보낸 함수 내에서 this 사용을 금지합니다.
왜 문제인가요?
대부분의 번들러에서는 내보낸 함수에 대한 this의 값이 유지되지 않습니다. 함수가 다른 모듈로 내보내지고 가져올 때, this는 일반적으로 모듈 네임스페이스 객체가 아니라 undefined가 됩니다. 이로 인해 예기치 않은 런타임 오류나 잘못된 동작이 발생할 수 있습니다.
예시
이 규칙에 잘못된 코드 예시:
javascript
export function foo() {
console.log(this);
}
export default function bar() {
this.something();
}
function baz() {
const self = this;
}
export { baz };이 규칙에 올바른 코드 예시:
javascript
function foo() {
console.log(this);
}
export const bar = () => {
console.log(this);
};사용 방법
구성 파일 또는 명령줄 인터페이스를 통해 이 규칙을 활성화하려면 다음을 사용하세요:
json
{
"rules": {
"oxc/no-this-in-exported-function": "error"
}
}bash
oxlint --deny oxc/no-this-in-exported-function