---
title: "고급 사용법"
description: "Config Composer, 타입 인지 규칙, command codemod, 플러그인 이름 변경, 버전 정책."
---

> Documentation Index
> Fetch the complete documentation index at: https://code-style.pages.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# 고급 사용법

## 타입 인지 규칙

가장 강력한 TypeScript 린트 규칙 일부는 타입 정보가 필요합니다 — 로컬 구문이 어떻게 보이느냐가 아니라 런타임에 어떤 값인지 실제로 resolve해야 합니다. `tsconfig.json`을 가리켜 [타입 인지 린트](https://typescript-eslint.io/linting/typed-linting/)를 opt-in 하세요:

```ts title="eslint.config.ts"
import pleaseai from '@pleaseai/eslint-config'

export default pleaseai({
  typescript: {
    tsconfigPath: 'tsconfig.json',
  },
})
```

:::warning
타입 인지 린트는 ESLint가 매 실행마다 TypeScript 프로그램을 구축해야 하므로 구문만 보는 린트보다 느립니다. 작거나 중간 크기의 프로젝트에서 시작하고, 매우 큰 모노레포에서는 일부 파일에만 적용하는 것을 고려하세요.
:::

## Config Composer

`pleaseai()`는 [`FlatConfigComposer`](https://github.com/antfu/eslint-flat-config-utils#composer)를 반환하므로, 일반 옵션 객체만으로는 충분하지 않을 때 이름이 붙은 config 블록을 유연하게 override, prepend, remove, rename할 수 있습니다:

```ts title="eslint.config.ts"
import pleaseai from '@pleaseai/eslint-config'

export default pleaseai()
  .prepend(
    // 메인 PleaseAI 설정 앞에 들어가는 flat config들
  )
  .override('antfu/stylistic/rules', {
    rules: {
      'style/generator-star-spacing': ['error', { after: true, before: false }],
    },
  })
  .renamePlugins({
    'old-prefix': 'new-prefix',
  })
  .remove('antfu/stylistic')
```

이 API는 다음과 같은 경우에 사용하세요:

- 이름이 붙은 config 블록을 완전히 **remove**하고 싶을 때
- 커스텀 설정을 작성하지 않고 플러그인 prefix를 **rename**해야 할 때
- 특정 이름의 블록 내부 규칙을 **override**하고 싶을 때 (최상위 `overrides`보다 더 정교함)

## `command` Codemod

`@pleaseai/eslint-config`는 [`eslint-plugin-command`](https://github.com/antfu/eslint-plugin-command)를 함께 배포합니다 — triple-slash 주석으로 트리거되는 온디맨드 마이크로 codemod 시스템입니다. 일반적인 린트 규칙이 아니라 사용자가 명시적으로 opt-in 하는 방식입니다.

기본 제공되는 트리거:

- `/// to-function` — arrow function → `function` 선언
- `/// to-arrow` — `function` 선언 → arrow function
- `/// to-for-each` — `for` 루프 → `.forEach()`
- `/// to-for-of` — `.forEach()` → `for-of`
- `/// keep-sorted` — 다음 객체/배열/인터페이스 정렬

전체 카탈로그는 [플러그인 문서](https://github.com/antfu/eslint-plugin-command#built-in-commands)에서 확인하세요.

사용법 — 트리거를 코드 한 줄 위에 배치합니다:

```ts title="before.ts"
/// to-function
const greet = async (name: string): Promise<void> => {
  console.log(`Hello, ${name}`)
}
```

`eslint --fix` 실행 후:

```ts title="after.ts"
async function greet(name: string): Promise<void> {
  console.log(`Hello, ${name}`)
}
```

트리거 주석은 일회성으로, 변환과 함께 제거됩니다.

## Anti-slop 규칙

`antislop`은 `@antfu/eslint-config`의 `antislop` 옵션을 통해 [`eslint-plugin-slop`](https://github.com/antfu/eslint-plugin-slop)의 규칙과 [`eslint-plugin-sonarjs`](https://github.com/SonarSource/SonarJS)에서 골라 둔 일부 규칙을 켭니다. 두 플러그인은 모두 선택적 peer dependency입니다:

```bash
bun add -D eslint-plugin-slop eslint-plugin-sonarjs
```

`antislop`을 지정하지 않으면 설치된 플러그인의 규칙만 켜집니다. 플러그인 없이 업그레이드하면 아무것도 바뀌지 않으며, `please-style`은 새 프로젝트에 두 플러그인을 함께 설치합니다.

`antislop: true`는 두 플러그인이 모두 필요합니다. 객체를 넘기면 명시해서 켠 플러그인(`slop: true` 또는 `slop: { ... }`. `cognitiveComplexity`에 숫자를 지정하면 `sonarjs`를 켠 것으로 봅니다)만 필요하고, 언급하지 않은 플러그인은 설치 여부를 따릅니다. 결과적으로 두 플러그인이 모두 꺼지면 antislop도 꺼집니다. 필요한 플러그인이 없으면 오류가 발생합니다: `` `antislop` requires `eslint-plugin-sonarjs`. Install with `bun add -D eslint-plugin-sonarjs`, or set `antislop: false`. `` 일부만 끄려면 `{ sonarjs: false }` 또는 `{ slop: false }`를, 전부 끄려면 `false`를 지정합니다.

```js
import pleaseai from '@pleaseai/eslint-config'

export default pleaseai({
  antislop: { cognitiveComplexity: 20 },
})
```

- `cognitiveComplexity`는 `sonarjs/cognitive-complexity`의 임계값입니다(기본값 15). `false`로 끌 수 있습니다.
- `slop: { cwd, inspection }`은 `slop` 규칙이 보고할 변경의 범위(파일 전체, 커밋하지 않은 줄, 최근 커밋의 줄)를 정합니다. `inspection`은 `'full'`(기본값), `'uncommitted'`, `'recent-changes'` 중 하나입니다. CI에서는 `'full'`을 유지하세요. 나머지 모드는 git 상태(shallow clone, 깨끗한 checkout)에 좌우되어 로컬과 CI의 결과가 달라집니다.
- `slop/no-em-dash`는 Markdown 파일에서는 경고, 그 외 파일에서는 오류입니다. 자동 수정은 지원하지 않습니다.
- CSS, HTML, Vue, JSON, YAML, TOML, Markdown 같은 non-JS 파일에서는 다른 설정이 이미 파싱하는 파일에만 규칙이 동작합니다. 따라서 `antislop`을 켜도 ESLint가 새로운 파일 유형을 검사하지 않으며, CSS나 HTML에서 파싱 오류가 나지 않습니다.

이 저장소에서 antislop을 처음 켰을 때 193건이 보고되었습니다. `slop/no-em-dash` 174건(Markdown 136건), `sonarjs/cognitive-complexity` 8건, `slop/prefer-jsdoc` 7건(자동 수정 가능), `slop/max-comment-length` 3건, `slop/no-trivial-functions` 1건입니다. 지금은 모두 고쳤고, 이 저장소도 antislop을 켠 상태로 린트합니다. 측정 결과는 [이슈 #76](https://github.com/pleaseai/code-style/issues/76)에 있습니다.

## Quality 규칙

`quality: true`는 [anti-slop](https://github.com/dmmulroy/anti-slop)의 `quality/*` 규칙 12개를 켭니다. 규칙은 [`@nkzw/oxlint-config`](https://github.com/nkzw-tech/oxlint-config)를 거쳐 이 패키지에 vendoring되어 있습니다. 근거가 부족한 타입과 코드 패턴을 잡는 규칙들로, 이미 아는 값을 `unknown`으로 넓혔다가 다시 단언하는 코드, 연쇄 타입 단언, `unknown` 반환 타입과 타입 별칭, 안전하지 않은 딕셔너리 값 타입, `object` 매개변수, 연달아 쓰는 `filter`/`map`, reducer 누적값 복사, `Reflect.get` / `Reflect.apply`, 조건부 빈 객체 spread를 보고합니다. 기본값은 꺼짐이며 추가 패키지는 필요 없습니다.

```js
import pleaseai from '@pleaseai/eslint-config'

export default pleaseai({
  quality: true,
  rules: {
    'quality/no-object-parameters': 'off',
  },
})
```

- 모든 규칙은 JS와 TS 파일에서 오류입니다. Markdown의 코드 블록은 검사하지 않습니다.
- `no-object-parameters`와 `no-unknown-returns`가 가장 주관적인 규칙입니다. 코드에 맞지 않으면 `rules`에서 끄세요.
- `quality/no-chained-type-assertions`는 `antislop`의 `slop/no-chained-type-assertions`와 같은 코드를 보고합니다. 둘 다 켰다면 하나를 끄세요.
- 자동 수정을 지원하는 규칙은 없습니다.

이 저장소에서 `quality: true`를 처음 켰을 때 29건이 보고되었습니다. `no-known-value-widening` 13건, `no-array-filter-map` 10건, `no-unsafe-dictionary-type` 3건, `no-conditional-empty-object-spread` 2건, `no-unknown-returns` 1건입니다. 더 큰 private 모노레포(파일 2,669개)에서는 1,172개 파일에서 4,396건이 보고되었고, 그중 61%가 테스트 코드였습니다. 가장 많은 규칙은 `no-chained-type-assertions`(1,282건), `no-unsafe-dictionary-type`(1,240건), `no-known-value-widening`(745건), `no-conditional-empty-object-spread`(658건)입니다. 이 정도 양이라 기본값을 꺼짐으로 두었습니다. 이 저장소의 보고 건은 모두 고쳤고, 지금은 `quality: true`를 켠 상태로 린트합니다. 측정 결과는 [이슈 #77](https://github.com/pleaseai/code-style/issues/77)에 있습니다.

## Strict 규칙

`strict: true`는 [cloudflare/oxlint-config](https://github.com/cloudflare/oxlint-config)에서 가져온, 타입 정보가 필요 없는 규칙들을 켭니다. 기본값은 꺼짐입니다.

```js
import pleaseai from '@pleaseai/eslint-config'

export default pleaseai({
  strict: true,
  rules: {
    'unicorn/prefer-set-has': 'off',
  },
})
```

- `no-promise-executor-return`은 Promise executor 함수에서 값을 반환하는 코드를 보고합니다.
- `eqeqeq`는 antfu의 `'smart'` 대신 `'always'`로 설정되므로 `value == null`도 보고합니다.
- `unicorn/prefer-set-has`는 멤버십 확인에만 쓰는 배열이라 `Set`으로 바꿀 수 있는 경우를 보고합니다.
- `ts/no-confusing-non-null-assertion`은 `a! == b`처럼 동등 비교나 대입 연산자의 일부처럼 읽히는 non-null 단언을 보고합니다. `canonicalPluginNames`를 켜면 `@typescript-eslint/no-confusing-non-null-assertion`입니다.
- `import/no-self-import`는 자기 자신을 import하는 모듈을 보고합니다.
- 모든 규칙은 JS와 TS 파일에서 오류입니다. Markdown의 코드 블록은 검사하지 않습니다.
- 규칙의 플러그인이 꺼져 있으면 그 규칙은 건너뜁니다. `typescript`가 `false`이면 `ts/*`, `unicorn`이 `false`이면 `unicorn/*`, `imports`가 `false`이면 `import/no-self-import`를 건너뜁니다.
- 기본 모드에서 `import/no-self-import`는 `eslint-plugin-import-x`가 제공합니다. `canonicalPluginNames`를 켜면 `eslint-plugin-import`가 제공합니다. 두 모드 모두 TypeScript 소스는 `eslint-import-resolver-typescript`가 찾습니다. `eslint-plugin-import-x`와 `eslint-import-resolver-typescript`는 일반 dependency라서 `strict`를 켰을 때만 불러오고, `canonicalPluginNames`는 optional peer인 `eslint-plugin-import`를 따로 설치해야 합니다(`bun add -D eslint-plugin-import`). 두 모드 모두 확장자 없는 경로, `.ts` 파일을 가리키는 `.js` 경로, tsconfig `paths` 별칭도 잡습니다. 리졸버는 ESLint를 실행하는 디렉터리에서 `tsconfig.json`을 찾습니다. 설정 중 하나라도 활성 import 플러그인이 읽는 resolver(기본 모드는 `import-x/resolver-next`, `import-x/resolver`, `import-x/resolver-legacy`, `import-x/resolve`, `canonicalPluginNames`를 켜면 `import/resolver`)를 지정하면 strict 리졸버는 모든 파일에서 빠지고, import 해석은 직접 지정한 resolver가 맡습니다.
- 규칙 하나만 끄려면 위 예시처럼 `rules`에서 끄세요. 사용자의 `rules`와 설정이 `strict`보다 우선합니다.
- `eqeqeq`는 `== null`을 자동 수정하지 않습니다. `x === null || x === undefined`로 직접 고치거나, 둘 중 하나만 올 수 있으면 한 가지 검사만 쓰세요.

이 저장소에서 `strict: true`를 처음 켰을 때 18개 파일에서 88건이 보고되었습니다. `eqeqeq` 86건(대부분 `== null`과 `!= null`)과 `unicorn/prefer-set-has` 2건이고, 나머지 규칙은 보고하지 않았습니다. 일부러 자기 자신을 import하는 테스트 fixture에서 `import/no-self-import` 1건이 나왔지만, 이 fixture는 `eslint.config.ts`에서 린트 대상에서 제외합니다. 보고 건은 모두 고쳤고, 지금은 `strict: true`를 켠 상태로 린트합니다. 측정 결과는 [이슈 #96](https://github.com/pleaseai/code-style/issues/96)에 있습니다.

## 플러그인 이름 변경

`@pleaseai/eslint-config`는 더 짧고 일관된 DX를 위해 `@antfu/eslint-config`의 플러그인 이름 변경을 상속받습니다:

| 새 prefix  | 원본 prefix            | 소스 플러그인                                                                                |
| ---------- | ---------------------- | -------------------------------------------------------------------------------------------- |
| `import/*` | `import-lite/*`        | [`eslint-plugin-import-lite`](https://github.com/9romise/eslint-plugin-import-lite)          |
| `node/*`   | `n/*`                  | [`eslint-plugin-n`](https://github.com/eslint-community/eslint-plugin-n)                     |
| `yaml/*`   | `yml/*`                | [`eslint-plugin-yml`](https://github.com/ota-meshi/eslint-plugin-yml)                        |
| `ts/*`     | `@typescript-eslint/*` | [`@typescript-eslint/eslint-plugin`](https://github.com/typescript-eslint/typescript-eslint) |
| `style/*`  | `@stylistic/*`         | [`@stylistic/eslint-plugin`](https://github.com/eslint-stylistic/eslint-stylistic)           |
| `test/*`   | `vitest/*`             | [`@vitest/eslint-plugin`](https://github.com/vitest-dev/eslint-plugin-vitest)                |

따라서 규칙을 오버라이드할 때는 새 prefix를 사용하세요:

```ts title="eslint.config.ts"
import pleaseai from '@pleaseai/eslint-config'

export default pleaseai({
  rules: {
    'ts/consistent-type-definitions': ['error', 'interface'],
    'style/max-statements-per-line': ['error', { max: 2 }],
  },
})
```

## 활성화된 규칙 보기

[`@eslint/config-inspector`](https://github.com/eslint/config-inspector)를 사용하면 완전히 해결된 설정을 브라우저에서 시각화할 수 있습니다 — 활성화된 모든 규칙, 모든 플러그인, 모든 파일 glob까지:

```bash title="Terminal"
npx @eslint/config-inspector
```

로컬 서버가 열리면서 flat config 그래프를 보여줍니다. "왜 이 규칙이 적용되는가" 또는 "어떤 프리셋이 이것을 추가했는가"를 디버깅할 때 없어서는 안 될 도구입니다.

## Re-exports

`@antfu/eslint-config`의 모든 export가 재export 되므로, `pleaseai()` 팩토리를 사용하지 않고 직접 세부 설정을 import해서 조합할 수도 있습니다:

```ts title="eslint.config.ts"
import { combine, javascript, typescript, vue } from '@pleaseai/eslint-config'

export default combine(
  javascript(),
  typescript(),
  vue(),
)
```

## 버전 정책

`@pleaseai/eslint-config`는 [Semantic Versioning](https://semver.org/)을 따르지만, 여러 가지가 얽힌 스타일 프리셋이기 때문에 **규칙 변경은 breaking change로 취급하지 않습니다**.

**Breaking (major 버전 업)**

- Node.js 버전 요구사항 변경
- 다운스트림 설정을 깨뜨릴 수 있는 대규모 리팩터
- 기존 규칙을 깨뜨릴 수 있는 주요 플러그인 업그레이드
- 대부분의 코드베이스에 영향을 미칠 가능성이 높은 변경

**Non-breaking (minor/patch)**

- 개별 규칙 활성화 또는 비활성화 (엄격해지더라도)
- 규칙 옵션 변경
- 의존성 버전 업데이트

규칙 강화로 빌드가 깨진다면 이전 minor 버전으로 고정하고, 트레이드오프를 논의할 수 있도록 [이슈를 열어](https://github.com/pleaseai/code-style/issues) 주세요.

Source: https://code-style.pages.dev/ko/eslint-config/advanced/index.mdx
