100개가 넘는 강력한 ESLint 규칙을 제공하는 ESLint 플러그인입니다.
100개가 넘는 강력한 ESLint 규칙
이 플러그인을 포함하는 XO도 확인해보세요.
shnpm install --save-dev eslint eslint-plugin-unicorn
ESLint >=9.20.0, 플랫(Flat) 설정, 그리고 ESM이 필요합니다.
프리셋 설정을 사용하거나 eslint.config.js에서 각 규칙을 직접 설정하세요.
프리셋을 사용하지 않는다면, 아래와 동일한 languageOptions 설정을 사용했는지 확인하세요.
jsimport eslintPluginUnicorn from 'eslint-plugin-unicorn'; import globals from 'globals'; export default [ { languageOptions: { globals: globals.builtin, }, plugins: { unicorn: eslintPluginUnicorn, }, rules: { 'unicorn/better-regex': 'error', 'unicorn/…': 'error', }, }, // … ];
💼 Configurations enabled in.
✅ recommended configuration에서 설정됨.
☑️ unopinionated configuration에서 설정됨.
🔧 --fix CLI 옵션으로 자동 수정 가능.
💡 에디터 제안(editor suggestions)으로 수동 수정 가능.
| 이름 | 설명 | 💼 | 🔧 | 💡 |
|---|---|---|---|---|
| better-regex | 정규식을 더 짧고 일관되며 안전하게 개선합니다. | 🔧 | ||
| catch-error-name | catch 절에서 특정 매개변수 이름을 강제합니다. | ✅ | 🔧 | |
| consistent-assert | node:assert로 일관된 assertion 스타일을 강제합니다. | ✅ | 🔧 | |
| consistent-date-clone | 복제할 때 생성자에 Date를 직접 전달하는 것을 선호합니다. | ✅ ☑️ | 🔧 | |
| consistent-destructuring | 프로퍼티 대신 구조 분해한 변수를 사용합니다. | 💡 | ||
| consistent-empty-array-spread | 배열 리터럴에서 삼항 연산자를 펼칠 때 일관된 타입을 선호합니다. | ✅ | 🔧 | |
| consistent-existence-index-check | indexOf(), lastIndexOf(), findIndex(), findLastIndex()를 이용한 요소 존재성 검사 스타일을 일관되게 강제합니다. | ✅ ☑️ | 🔧 | |
| consistent-function-scoping | 함수 정의를 가능한 가장 높은 스코프로 이동합니다. | ✅ | ||
| custom-error-definition | 올바른 Error 서브클래싱을 강제합니다. | 🔧 | ||
| empty-brace-spaces | 중괄호 사이에 공백이 없도록 강제합니다. | ✅ | 🔧 | |
| error-message | 내장 오류를 만들 때 message 값을 전달하도록 강제합니다. | ✅ ☑️ | ||
| escape-case | 이스케이프 시퀀스가 대문자 또는 소문자 값을 사용하도록 요구합니다. | ✅ ☑️ | 🔧 | |
| expiring-todo-comments | TODO 주석에 만료 조건을 추가합니다. | ✅ ☑️ | ||
| explicit-length-check | 값의 length 또는 size 프로퍼티를 명시적으로 비교하도록 강제합니다. | ✅ | 🔧 | 💡 |
| filename-case | 파일명에 대한 케이스 스타일을 강제합니다. | ✅ | ||
| import-style | 모듈별로 특정 import 스타일을 강제합니다. | ✅ ☑️ | ||
| new-for-builtins | String, Number, Boolean, Symbol, BigInt를 제외한 모든 built-in에 대해 new 사용을 강제합니다. | ✅ ☑️ | 🔧 | 💡 |
| no-abusive-eslint-disable | eslint-disable 주석에서 비활성화할 규칙을 지정하도록 강제합니다. | ✅ ☑️ | ||
| no-accessor-recursion | getter/setter 안에서 this에 재귀적으로 접근하는 것을 금지합니다. | ✅ ☑️ | ||
| no-anonymous-default-export | 기본 export로 익명 함수/클래스를 사용하는 것을 금지합니다. | ✅ ☑️ | 💡 | |
| no-array-callback-reference | 이터레이터 메서드에 함수 참조를 직접 전달하는 것을 방지합니다. | ✅ | 💡 | |
| no-array-for-each | forEach 메서드 대신 for…of를 선호합니다. | ✅ ☑️ | 🔧 | 💡 |
| no-array-method-this-argument | 배열 메서드에서 this 인자를 사용하는 것을 금지합니다. | ✅ ☑️ | 🔧 | 💡 |
| no-array-reduce | Array#reduce()와 Array#reduceRight()를 금지합니다. | ✅ | ||
| no-array-reverse | Array#reverse() 대신 Array#toReversed()를 선호합니다. | ✅ ☑️ | 💡 | |
| no-array-sort | Array#sort() 대신 Array#toSorted()를 선호합니다. | ✅ ☑️ | 💡 | |
| no-await-expression-member | await 표현식에서 멤버 접근을 금지합니다. | ✅ | 🔧 | |
| no-await-in-promise-methods | Promise 메서드의 매개변수에서 await 사용을 금지합니다. | ✅ ☑️ | 💡 | |
| no-console-spaces | console.log 매개변수 사이의 선행/후행 공백을 사용하지 않습니다. | ✅ ☑️ | 🔧 | |
| no-document-cookie | document.cookie를 직접 사용하지 않습니다. | ✅ ☑️ | ||
| no-empty-file | 빈 파일을 금지합니다. | ✅ ☑️ | ||
| no-for-loop | for-of로 대체할 수 있는 for 루프를 사용하지 않습니다. | ✅ | 🔧 | 💡 |
| no-hex-escape | 16진수 이스케이프 대신 유니코드 이스케이프 사용을 강제합니다. | ✅ ☑️ | 🔧 | |
| no-immediate-mutation | 변수 할당 직후의 즉시 변경을 금지합니다. | ✅ | 🔧 | 💡 |
| no-instanceof-builtins | 내장 객체에 instanceof를 사용하는 것을 금지합니다. | ✅ ☑️ | 🔧 | 💡 |
| no-invalid-fetch-options | fetch() 및 new Request()에서 잘못된 옵션을 금지합니다. | ✅ ☑️ | ||
| no-invalid-remove-event-listener | 표현식 결과로 EventTarget#removeEventListener()를 호출하는 것을 방지합니다. | ✅ ☑️ | ||
| no-keyword-prefix | 식별자가 new 또는 class로 시작하는 것을 금지합니다. | |||
| no-lonely-if | else 없이 if 블록의 유일한 문장으로 if가 있는 것을 금지합니다. | ✅ ☑️ | 🔧 | |
| no-magic-array-flat-depth | Array#flat(…)의 depth 인자로 매직 넘버를 사용하는 것을 금지합니다. | ✅ ☑️ | ||
| no-named-default | default import/export를 이름 붙여 사용하는 것을 금지합니다. | ✅ ☑️ | 🔧 | |
| no-negated-condition | 부정(negated) 조건을 금지합니다. | ✅ ☑️ | 🔧 | |
| no-negation-in-equality-check | 동등 비교에서 부정 표현식을 금지합니다. | ✅ ☑️ | 💡 | |
| no-nested-ternary | 중첩된 삼항 표현식을 금지합니다. | ✅ | 🔧 | |
| no-new-array | new Array()를 금지합니다. | ✅ ☑️ | 🔧 | 💡 |
| no-new-buffer | 더 이상 권장되지 않는 new Buffer() 대신 Buffer.from() 및 Buffer.alloc() 사용을 강제합니다. | ✅ ☑️ | 🔧 | 💡 |
| no-null | null 리터럴 사용을 금지합니다. | ✅ | 🔧 | 💡 |
| no-object-as-default-parameter | 기본 매개변수로 객체를 사용하는 것을 금지합니다. | ✅ ☑️ | ||
| no-process-exit | process.exit()를 금지합니다. | ✅ ☑️ | ||
| no-single-promise-in-promise-methods | Promise 메서드에 단일 요소 배열을 전달하는 것을 금지합니다. | ✅ ☑️ | 🔧 | 💡 |
| no-static-only-class | 정적 멤버만 가진 클래스를 금지합니다. | ✅ ☑️ | 🔧 | |
| no-thenable | then 프로퍼티를 금지합니다. | ✅ ☑️ | ||
| no-this-assignment | this를 변수에 할당하는 것을 금지합니다. | ✅ ☑️ | ||
| no-typeof-undefined | typeof로 undefined를 비교하는 것을 금지합니다. | ✅ ☑️ | 🔧 | 💡 |
| no-unnecessary-array-flat-depth | Array#flat()의 depth 인자로 1을 사용하는 것을 금지합니다. | ✅ ☑️ | 🔧 | |
| no-unnecessary-array-splice-count | Array#{splice,toSpliced}()의 deleteCount 또는 skipCount 인자로 .length 또는 Infinity를 사용하는 것을 금지합니다. | ✅ ☑️ | 🔧 | |
| no-unnecessary-await | 프로미스가 아닌 값에 대해 await 하는 것을 금지합니다. | ✅ ☑️ | 🔧 | |
| no-unnecessary-polyfills | 불필요한 폴리필 대신 내장 메서드 사용을 강제합니다. | ✅ ☑️ | ||
| no-unnecessary-slice-end | {Array,String,TypedArray}#slice()의 end 인자로 .length 또는 Infinity를 사용하는 것을 금지합니다. | ✅ ☑️ | 🔧 | |
| no-unreadable-array-destructuring | 읽기 어려운 배열 구조 분해를 금지합니다. | ✅ ☑️ | 🔧 | |
| no-unreadable-iife | 읽기 어려운 IIFE를 금지합니다. | ✅ ☑️ | ||
| no-unused-properties | 사용되지 않는 객체 프로퍼티를 금지합니다. | |||
| no-useless-collection-argument | Set, Map, WeakSet, WeakMap에서 쓸모없는 값 또는 폴백을 금지합니다. | ✅ ☑️ | 🔧 | |
| no-useless-error-capture-stack-trace | 불필요한 Error.captureStackTrace(…)를 금지합니다. | ✅ ☑️ | 🔧 | |
| no-useless-fallback-in-spread | 객체 리터럴에서 펼치기(spread) 시 쓸모없는 폴백을 금지합니다. | ✅ ☑️ | 🔧 | |
| no-useless-length-check | 쓸모없는 배열 길이 검사를 금지합니다. | ✅ ☑️ | 🔧 | |
| no-useless-promise-resolve-reject | async 함수 또는 프로미스 콜백에서 Promise.resolve/reject()를 반환/산출하는 것을 금지합니다. | ✅ ☑️ | 🔧 | |
| no-useless-spread | 불필요한 spread를 금지합니다. | ✅ ☑️ | 🔧 | |
| no-useless-switch-case | switch 문에서 쓸모없는 case를 금지합니다. | ✅ ☑️ | 💡 | |
| no-useless-undefined | 쓸모없는 undefined를 금지합니다. | ✅ ☑️ | 🔧 | |
| no-zero-fractions | 소수 부분이 0이거나 점이 매달린(dangling) 숫자 리터럴을 금지합니다. | ✅ ☑️ | 🔧 | |
| number-literal-case | 숫자 리터럴의 올바른 대/소문자를 강제합니다. | ✅ ☑️ | 🔧 | |
| numeric-separators-style | 숫자 구분자 스타일을 올바르게 자릿수 그룹화하도록 강제합니다. | ✅ ☑️ | 🔧 | |
| prefer-add-event-listener | on-함수보다 .addEventListener()와 .removeEventListener()를 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-array-find | .filter(…)의 첫/마지막 요소를 쓰는 것보다 .find(…)와 .findLast(…)를 선호합니다. | ✅ ☑️ | 🔧 | 💡 |
| prefer-array-flat | 배열을 평탄화할 때 레거시 기법보다 Array#flat()을 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-array-flat-map | .map(…).flat()보다 .flatMap(…)을 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-array-index-of | 항목의 인덱스를 찾을 때 Array#{findIndex,findLastIndex}()보다 Array#{indexOf,lastIndexOf}()를 선호합니다. | ✅ ☑️ | 🔧 | 💡 |
| prefer-array-some | 존재 여부 확인 시 .filter(…).length 검사 및 .{find,findLast,findIndex,findLastIndex}(…)보다 .some(…)를 선호합니다. | ✅ ☑️ | 🔧 | 💡 |
| prefer-at | 인덱스 접근 및 String#charAt()에 .at() 메서드를 선호합니다. | ✅ ☑️ | 🔧 | 💡 |
| prefer-bigint-literals | 생성자보다 BigInt 리터럴을 선호합니다. | ✅ ☑️ | 🔧 | 💡 |
| prefer-blob-reading-methods | FileReader#readAsArrayBuffer(…)보다 Blob#arrayBuffer(), FileReader#readAsText(…)보다 Blob#text()를 선호합니다. | ✅ ☑️ | ||
| prefer-class-fields | 생성자에서 this 할당보다 클래스 필드 선언을 선호합니다. | ✅ ☑️ | 🔧 | 💡 |
| prefer-classlist-toggle | 클래스 이름 토글에 Element#classList.toggle() 사용을 선호합니다. | ✅ ☑️ | 🔧 | 💡 |
| prefer-code-point | String#charCodeAt(…)보다 String#codePointAt(…), String.fromCharCode(…)보다 String.fromCodePoint(…)를 선호합니다. | ✅ ☑️ | 💡 | |
| prefer-date-now | 유닉스 에포크 이후 밀리초를 얻기 위해 Date.now()를 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-default-parameters | 재할당보다 기본 매개변수를 선호합니다. | ✅ ☑️ | 💡 | |
| prefer-dom-node-append | Node#appendChild()보다 Node#append()를 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-dom-node-dataset | 속성 메서드 호출보다 DOM 요소의 .dataset 사용을 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-dom-node-remove | parentNode.removeChild(childNode)보다 childNode.remove()를 선호합니다. | ✅ ☑️ | 🔧 | 💡 |
| prefer-dom-node-text-content | .innerText보다 .textContent를 선호합니다. | ✅ ☑️ | 💡 | |
| prefer-event-target | EventEmitter보다 EventTarget을 선호합니다. | ✅ ☑️ | ||
| prefer-export-from | 재-내보내기(re-export) 시 export…from을 선호합니다. | ✅ | 🔧 | 💡 |
| prefer-global-this | window, self, global보다 globalThis를 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-import-meta-properties | 파일 경로를 얻기 위한 레거시 기법보다 import.meta.{dirname,filename}를 선호합니다. | 🔧 | ||
| prefer-includes | 존재/부재 확인 시 .indexOf(), .lastIndexOf(), Array#some()보다 .includes()를 선호합니다. | ✅ ☑️ | 🔧 | 💡 |
| prefer-json-parse-buffer | JSON 파일을 버퍼로 읽는 것을 선호합니다. | 🔧 | ||
| prefer-keyboard-event-key | KeyboardEvent#keyCode보다 KeyboardEvent#key를 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-logical-operator-over-ternary | 삼항 연산자보다 논리 연산자 사용을 선호합니다. | ✅ ☑️ | 💡 | |
| prefer-math-min-max | 단순 비교에서는 삼항 연산자보다 Math.min()과 Math.max()를 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-math-trunc | 비트 연산자 대신 Math.trunc 사용을 강제합니다. | ✅ ☑️ | 🔧 | 💡 |
| prefer-modern-dom-apis | .insertBefore()보다 .before(), .replaceChild()보다 .replaceWith()를 선호하며, insertAdjacentText()/insertAdjacentElement()보다 .before(), .after(), .append(), .prepend() 중 하나를 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-modern-math-apis | 레거시 패턴보다 현대적인 Math API를 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-module | CommonJS보다 자바스크립트 모듈(ESM)을 선호합니다. | ✅ ☑️ | 🔧 | 💡 |
| prefer-native-coercion-functions | String, Number, BigInt, Boolean, Symbol을 직접 사용하는 것을 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-negative-index | 가능하다면 .length - index보다 음수 인덱스를 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-node-protocol | Node.js 내장 모듈을 import할 때 node: 프로토콜 사용을 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-number-properties | 전역 값보다 Number의 정적 프로퍼티를 선호합니다. | ✅ ☑️ | 🔧 | 💡 |
| prefer-object-from-entries | 키-값 쌍 목록을 객체로 변환할 때 Object.fromEntries(…) 사용을 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-optional-catch-binding | catch 바인딩 매개변수를 생략하는 것을 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-prototype-methods | 인스턴스에서 메서드를 직접 쓰기보다 프로토타입에서 메서드를 빌려오는 것을 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-query-selector | .getElementById()보다 .querySelector(), .getElementsByClassName()/.getElementsByTagName()/.getElementsByName()보다 .querySelectorAll()을 선호합니다. | ✅ | 🔧 | |
| prefer-reflect-apply | Function#apply()보다 Reflect.apply()를 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-regexp-test | String#match()와 RegExp#exec()보다 RegExp#test()를 선호합니다. | ✅ ☑️ | 🔧 | 💡 |
| prefer-response-static-json | new Response(JSON.stringify())보다 Response.json()을 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-set-has | 존재/부재 확인 시 Array#includes()보다 Set#has()를 선호합니다. | ✅ ☑️ | 🔧 | 💡 |
| prefer-set-size | Array#length 대신 Set#size 사용을 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-single-call | 여러 번의 Array#push(), Element#classList.{add,remove}(), importScripts() 호출을 한 번의 호출로 합치도록 강제합니다. | ✅ ☑️ | 🔧 | 💡 |
| prefer-spread | Array.from(…), Array#concat(…), Array#{slice,toSpliced}(), String#split('')보다 스프레드 연산자를 선호합니다. | ✅ | 🔧 | 💡 |
| prefer-string-raw | \ 이스케이프를 피하기 위해 String.raw 태그 사용을 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-string-replace-all | 전역 플래그가 있는 정규식 검색보다 String#replaceAll()을 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-string-slice | String#substr() 및 String#substring()보다 String#slice()를 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-string-starts-ends-with | RegExp#test()보다 String#startsWith()와 String#endsWith()를 선호합니다. | ✅ ☑️ | 🔧 | 💡 |
| prefer-string-trim-start-end | String#trimLeft()/String#trimRight()보다 String#trimStart()/String#trimEnd()를 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-structured-clone | 깊은 복사(deep clone)를 만들기 위해 structuredClone 사용을 선호합니다. | ✅ ☑️ | 💡 | |
| prefer-switch | 여러 개의 else-if보다 switch를 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-ternary | 단순한 if-else 문보다 삼항 표현식을 선호합니다. | ✅ ☑️ | 🔧 | |
| prefer-top-level-await | 최상위 프로미스 및 async 함수 호출보다 최상위 await를 선호합니다. | ✅ ☑️ | 💡 | |
| prefer-type-error | 타입 검사 조건에서 TypeError를 던지도록 강제합니다. | ✅ ☑️ | 🔧 | |
| prevent-abbreviations | 약어 사용을 방지합니다. | ✅ | 🔧 | |
| relative-url-style | 상대 URL 스타일의 일관성을 강제합니다. | ✅ ☑️ | 🔧 | 💡 |
| require-array-join-separator | Array#join()에서 separator 인자 사용을 강제합니다. | ✅ ☑️ | 🔧 | |
| require-module-attributes | import 및 export에 대해 비어 있지 않은 모듈 속성(module attributes)을 요구합니다. | ✅ ☑️ | 🔧 | |
| require-module-specifiers | import 및 export 문에서 비어 있지 않은 specifier 목록을 요구합니다. | ✅ ☑️ | 🔧 | 💡 |
| require-number-to-fixed-digits-argument | Number#toFixed()에서 digits 인자 사용을 강제합니다. | ✅ ☑️ | 🔧 | |
| require-post-message-target-origin | window.postMessage()에서 targetOrigin 인자 사용을 강제합니다. | 💡 | ||
| string-content | 더 나은 문자열 내용을 강제합니다. | 🔧 | 💡 | |
| switch-case-braces | case 절에 대해 일관된 중괄호 스타일을 강제합니다. | ✅ | 🔧 | |
| template-indent | 공백에 둔감한 템플릿 들여쓰기를 수정합니다. | ✅ | 🔧 | |
| text-encoding-identifier-case | 텍스트 인코딩 식별자의 대/소문자 일관성을 강제합니다. | ✅ ☑️ | 🔧 | 💡 |
| throw-new-error | 오류를 만들 때 new를 요구합니다. | ✅ ☑️ | 🔧 |
목록을 확인하세요.
설정 파일 확장에 대한 자세한 내용은 ESLint 문서를 참고하세요.
참고: 프리셋 설정은 올바른 language options도 함께 활성화합니다.
이 플러그인은 모범 사례를 강제하는 recommended 설정을 내보냅니다.
jsimport eslintPluginUnicorn from 'eslint-plugin-unicorn'; export default [ // … eslintPluginUnicorn.configs.recommended, { rules: { 'unicorn/better-regex': 'warn', }, }, ];
이 플러그인은 (deprecated 규칙을 제외한) 모든 규칙을 사용하는 all 설정도 내보냅니다.
jsimport eslintPluginUnicorn from 'eslint-plugin-unicorn'; export default [ // … eslintPluginUnicorn.configs.all, { rules: { 'unicorn/better-regex': 'warn', }, }, ];