|
| 1 | +import eslint from '@eslint/js'; |
| 2 | +import * as typescriptEslint from 'typescript-eslint'; |
| 3 | +import eslintPluginPrettier from 'eslint-plugin-prettier'; |
| 4 | +import { FlatCompat } from '@eslint/eslintrc'; |
| 5 | +import path from 'path'; |
| 6 | +import { fileURLToPath } from 'url'; |
| 7 | + |
| 8 | +// 기존 ESLint 설정을 새로운 flat config 형식으로 변환하기 위한 도구 초기화 (.eslintrc => eslint.config.js) |
| 9 | +const __filename = fileURLToPath(import.meta.url); |
| 10 | +const __dirname = path.dirname(__filename); |
| 11 | + |
| 12 | +const compat = new FlatCompat({ |
| 13 | + baseDirectory: __dirname, |
| 14 | +}); |
| 15 | + |
| 16 | +export default typescriptEslint.config( |
| 17 | + { |
| 18 | + files: ['**/*.{ts,tsx}'], |
| 19 | + }, |
| 20 | + // 린트에서 무시할 파일/디렉토리 설정 |
| 21 | + { |
| 22 | + ignores: ['**/node_modules/**', 'dist/**', 'build/**', 'coverage/**'], |
| 23 | + }, |
| 24 | + // 기본 설정 확장 |
| 25 | + eslint.configs.recommended, |
| 26 | + ...typescriptEslint.configs.recommended, |
| 27 | + ...typescriptEslint.configs.stylistic, |
| 28 | + ...compat.extends('eslint-config-airbnb-base'), |
| 29 | + { |
| 30 | + // 파서 설정 |
| 31 | + files: ['**/*.{ts,tsx}'], |
| 32 | + languageOptions: { |
| 33 | + parserOptions: { |
| 34 | + project: './tsconfig.json', |
| 35 | + warnOnUnsupportedTypeScriptVersion: false, |
| 36 | + }, |
| 37 | + }, |
| 38 | + // Prettier 플러그인 설정 |
| 39 | + plugins: { |
| 40 | + prettier: eslintPluginPrettier, // ESLint와 Prettier 규칙 충돌 방지 |
| 41 | + }, |
| 42 | + }, |
| 43 | + { |
| 44 | + rules: { |
| 45 | + 'no-console': 'off', |
| 46 | + 'import/extensions': 'off', // 파일 확장자 규칙 비활성화 |
| 47 | + 'import/no-unresolved': 'off', // 모듈 경로 해석 규칙 비활성화 |
| 48 | + 'import/extensions': [ |
| 49 | + 'off', |
| 50 | + 'ignorePackages', |
| 51 | + { |
| 52 | + js: 'never', |
| 53 | + jsx: 'never', |
| 54 | + ts: 'never', |
| 55 | + tsx: 'never', |
| 56 | + }, |
| 57 | + ], |
| 58 | + // TypeScript 관련 규칙 |
| 59 | + '@typescript-eslint/no-explicit-any': 'error', // any타입 사용 금지 |
| 60 | + '@typescript-eslint/no-unused-vars': [ |
| 61 | + // 미사용 변수 에러 = 언더스코어(명시적으로 사용) 예외 |
| 62 | + 'error', |
| 63 | + { |
| 64 | + argsIgnorePattern: '^_', |
| 65 | + varsIgnorePattern: '^_', |
| 66 | + caughtErrorsIgnorePattern: '^_', |
| 67 | + }, |
| 68 | + ], |
| 69 | + '@typescript-eslint/promise-function-async': 'error', // Promise 반환 함수에 async 강제 |
| 70 | + '@typescript-eslint/explicit-function-return-type': 'off', // 함수 반환 타입 명시 |
| 71 | + '@typescript-eslint/consistent-type-assertions': [ |
| 72 | + // 타입 단언보다 타입 선언 사용 권장 |
| 73 | + 'error', |
| 74 | + { |
| 75 | + assertionStyle: 'as', |
| 76 | + objectLiteralTypeAssertions: 'allow-as-parameter', |
| 77 | + }, |
| 78 | + ], |
| 79 | + // 네이밍 컨벤션 |
| 80 | + '@typescript-eslint/naming-convention': [ |
| 81 | + 'error', |
| 82 | + { |
| 83 | + selector: 'typeLike', |
| 84 | + format: ['PascalCase'], |
| 85 | + }, |
| 86 | + { |
| 87 | + selector: 'variable', |
| 88 | + format: ['camelCase'], |
| 89 | + leadingUnderscore: 'allow', |
| 90 | + }, |
| 91 | + { |
| 92 | + selector: 'function', |
| 93 | + format: ['camelCase'], |
| 94 | + }, |
| 95 | + ], |
| 96 | + }, |
| 97 | + }, |
| 98 | +); |
0 commit comments