[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -1,88 +1,212 @@
|
||||
---
|
||||
id: wiki-2026-0508-es-lint-configuration
|
||||
title: Es Lint Configuration
|
||||
title: ESLint Configuration
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: []
|
||||
aliases: [ESLint Config, eslint.config.js, Flat Config]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 1.0
|
||||
tags: ["JavaScript|[JavaScript", Tooling, ESLint, StaticAnalysis]
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [eslint, linting, javascript, typescript, tooling]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-04-20
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
tech_stack:
|
||||
language: unspecified
|
||||
framework: unspecified
|
||||
language: javascript
|
||||
framework: eslint
|
||||
---
|
||||
|
||||
# [[Es-Lint-Configuration|Es-Lint-Configuration]] (ESLint 설정 가이드)
|
||||
# ESLint Configuration
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> "천 명의 개발자가 한 명의 개발자처럼 코딩하게 만드는 규칙의 파수꾼." 소스 코드를 정적으로 분석하여 잠재적 버그를 찾고, 팀 내 합의된 코딩 컨벤션을 강제로 집행하는 도구다.
|
||||
## 매 한 줄
|
||||
> **"매 ESLint v9+ flat config (`eslint.config.js`) 는 array-of-config-objects 의 explicit composition"**. Legacy `.eslintrc.*` 의 deprecated. 매 modern setup 의 typescript-eslint, prettier integration, framework presets (Next, React) 의 mix.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
- **Configuration Layers**:
|
||||
- **[[Parser|Parser]]**: TS, Babel 등 최신 문법을 분석할 수 있게 변환.
|
||||
- **Plugins**: 특정 프레임워크 전용 규칙 추가 (React, NestJS 등).
|
||||
- **Extends**: 구글, 에어비앤비 등에서 검증된 설정 세트를 그대로 상속.
|
||||
- **Rules**: 'off', 'warn', 'error' 3단계로 개별 규칙의 엄격도 조절.
|
||||
- **Auto-fix**: 저장 시점에 세미콜론 누락, 안 쓰는 변수 제거 등을 자동으로 교정하여 생산성 향상.
|
||||
## 매 핵심
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- 최신 ESLint(v9+)는 설정 파일 형식이 완전히 바뀐 'Flat Config' 시대로 진입했다. 기존 `eslintrc.*` 방식은 레거시가 되었으므로, 새로운 프로젝트에서는 `eslint.config.js`를 사용해야 한다. 또한 포맷팅 전용 도구인 [[Prettier|Prettier]]와 충돌하지 않도록 역할 분담(Linter: 논리검사, Formatter: 모양검사)을 명확히 하는 것이 핵심이다.
|
||||
### 매 Flat Config (v9+)
|
||||
- Single `eslint.config.js` (or `.mjs`) at project root.
|
||||
- Exports array; each entry: `{ files, ignores, languageOptions, plugins, rules, ... }`.
|
||||
- No `extends` — use `...config` spread.
|
||||
- No `env` — use `globals` from `globals` package.
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- Related: Prettier-Configuration , [[Custom-ESLint-Rules-Development|Custom-ESLint-Rules-Development]]
|
||||
- Part of: [[SAST (Static Application Security Testing)|SAST (Static Application Security [[Testing]])]]
|
||||
### 매 Core Concepts
|
||||
- **languageOptions**: parser, parserOptions, globals.
|
||||
- **plugins**: object map (`{ pluginName: pluginObject }`).
|
||||
- **rules**: 'off' / 'warn' / 'error' (or 0/1/2), with config tuple `['error', opts]`.
|
||||
- **files**: glob array (e.g. `['**/*.ts']`) — scope rules.
|
||||
- **ignores**: replaces `.eslintignore`.
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
### 매 응용
|
||||
1. TypeScript project linting (typescript-eslint).
|
||||
2. React/Next.js framework rules.
|
||||
3. Monorepo per-package overrides.
|
||||
4. Prettier integration (eslint-config-prettier).
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
## 💻 패턴
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
### Minimal Modern Config
|
||||
```js
|
||||
// eslint.config.js (ESM)
|
||||
import js from '@eslint/js';
|
||||
import tseslint from 'typescript-eslint';
|
||||
import globals from 'globals';
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
|
||||
## 💻 코드 패턴 (Code Patterns)
|
||||
|
||||
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
|
||||
|
||||
```text
|
||||
# TODO
|
||||
export default [
|
||||
{ ignores: ['dist/**', 'node_modules/**', '.next/**'] },
|
||||
js.configs.recommended,
|
||||
...tseslint.configs.recommended,
|
||||
{
|
||||
languageOptions: {
|
||||
ecmaVersion: 2024,
|
||||
sourceType: 'module',
|
||||
globals: { ...globals.browser, ...globals.node },
|
||||
},
|
||||
rules: {
|
||||
'no-console': ['warn', { allow: ['warn', 'error'] }],
|
||||
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
||||
},
|
||||
},
|
||||
];
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
### React + TypeScript
|
||||
```js
|
||||
import js from '@eslint/js';
|
||||
import tseslint from 'typescript-eslint';
|
||||
import react from 'eslint-plugin-react';
|
||||
import reactHooks from 'eslint-plugin-react-hooks';
|
||||
import jsxA11y from 'eslint-plugin-jsx-a11y';
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
export default [
|
||||
js.configs.recommended,
|
||||
...tseslint.configs.recommendedTypeChecked,
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
languageOptions: {
|
||||
parserOptions: { project: './tsconfig.json' },
|
||||
},
|
||||
plugins: { react, 'react-hooks': reactHooks, 'jsx-a11y': jsxA11y },
|
||||
settings: { react: { version: 'detect' } },
|
||||
rules: {
|
||||
...react.configs.recommended.rules,
|
||||
...reactHooks.configs.recommended.rules,
|
||||
'react/react-in-jsx-scope': 'off', // not needed in React 17+
|
||||
'react/prop-types': 'off', // TS handles this
|
||||
},
|
||||
},
|
||||
];
|
||||
```
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
### Next.js (15+)
|
||||
```js
|
||||
import next from '@next/eslint-plugin-next';
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
export default [
|
||||
// ... base configs
|
||||
{
|
||||
plugins: { '@next/next': next },
|
||||
rules: {
|
||||
...next.configs.recommended.rules,
|
||||
...next.configs['core-web-vitals'].rules,
|
||||
},
|
||||
},
|
||||
];
|
||||
```
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
### Prettier Integration
|
||||
```bash
|
||||
npm i -D eslint-config-prettier
|
||||
```
|
||||
```js
|
||||
import prettier from 'eslint-config-prettier';
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
export default [
|
||||
// ... your configs
|
||||
prettier, // MUST be last — disables ESLint formatting rules
|
||||
];
|
||||
```
|
||||
|
||||
### Per-File Overrides
|
||||
```js
|
||||
export default [
|
||||
// base
|
||||
{
|
||||
files: ['**/*.test.{ts,tsx}'],
|
||||
languageOptions: { globals: { ...globals.jest } },
|
||||
rules: { '@typescript-eslint/no-explicit-any': 'off' },
|
||||
},
|
||||
{
|
||||
files: ['scripts/**/*.js'],
|
||||
languageOptions: { sourceType: 'commonjs' },
|
||||
},
|
||||
];
|
||||
```
|
||||
|
||||
### Type-Aware Rules
|
||||
```js
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
languageOptions: {
|
||||
parser: tseslint.parser,
|
||||
parserOptions: {
|
||||
project: true, // auto-find nearest tsconfig
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
'@typescript-eslint/no-floating-promises': 'error',
|
||||
'@typescript-eslint/await-thenable': 'error',
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
### package.json Scripts
|
||||
```json
|
||||
{
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "eslint . --fix",
|
||||
"lint:cache": "eslint . --cache --cache-location .cache/eslint"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| New project (2026) | Flat config (v9+) |
|
||||
| Legacy `.eslintrc` | Migrate via `@eslint/migrate-config` |
|
||||
| Formatting | Prettier; eslint-config-prettier last |
|
||||
| Type-aware rules | parserOptions.project: true |
|
||||
| Monorepo | Root config + per-package overrides via files glob |
|
||||
|
||||
**기본값**: flat config + typescript-eslint recommended-type-checked + Prettier integration.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[ESLint]] · [[Code Quality]]
|
||||
- 변형: [[typescript-eslint]] · [[Biome]] (alternative) · [[oxlint]] (alternative)
|
||||
- 응용: [[Pre-commit Hooks]] · [[CI Linting]]
|
||||
- Adjacent: [[Prettier]] · [[TSConfig]] · [[Husky]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: ESLint setup, rule conflict 의 debug, flat config migration.
|
||||
**언제 X**: extreme performance — Biome / oxlint 의 consider.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **`.eslintrc.*` in v9+**: deprecated, no longer auto-loaded.
|
||||
- **Prettier as ESLint plugin (`eslint-plugin-prettier`)**: slow, conflict-prone. Use Prettier separately + eslint-config-prettier.
|
||||
- **`extends` in flat config**: doesn't exist; use spread.
|
||||
- **Global rules without `files` scope in monorepo**: lints unintended files.
|
||||
- **Disabling whole categories**: targeted overrides 의 prefer.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (eslint.org docs — flat config, typescript-eslint v8 docs).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — ESLint flat config full content |
|
||||
|
||||
Reference in New Issue
Block a user