|
| 1 | +import js from '@eslint/js'; |
| 2 | +import globals from 'globals'; |
| 3 | +import tseslint from 'typescript-eslint'; |
| 4 | +import reactPlugin from 'eslint-plugin-react'; |
| 5 | +import reactHooksPlugin from 'eslint-plugin-react-hooks'; |
| 6 | +import reactRefreshPlugin from 'eslint-plugin-react-refresh'; |
| 7 | +import importPlugin from 'eslint-plugin-import-x'; |
| 8 | +import tanstackQueryPlugin from '@tanstack/eslint-plugin-query'; |
| 9 | +import prettierRecommended from 'eslint-plugin-prettier/recommended'; |
| 10 | +import { fixupConfigRules } from '@eslint/compat'; |
| 11 | + |
| 12 | +export default tseslint.config( |
| 13 | + // 1. ignores |
| 14 | + { ignores: ['dist/', 'build/', 'dev-dist/', 'eslint.config.js'] }, |
| 15 | + // 2. 기본 + TS 추천 설정 |
| 16 | + js.configs.recommended, |
| 17 | + tseslint.configs.recommended, |
| 18 | + // 3. 플러그인 flat config |
| 19 | + tanstackQueryPlugin.configs['flat/recommended'], |
| 20 | + // ✅ 구형 API를 호출하는 React 플러그인 설정들을 최신 버전에 맞게 자동으로 패치(호환) |
| 21 | + ...fixupConfigRules([ |
| 22 | + reactPlugin.configs.flat.recommended, |
| 23 | + reactPlugin.configs.flat['jsx-runtime'], |
| 24 | + ]), |
| 25 | + // 4. import flat config |
| 26 | + importPlugin.flatConfigs.recommended, |
| 27 | + importPlugin.flatConfigs.typescript, |
| 28 | + // 5. 메인 커스텀 설정 블록 |
| 29 | + { |
| 30 | + files: ['**/*.{js,jsx,ts,tsx}'], |
| 31 | + languageOptions: { |
| 32 | + ecmaVersion: 'latest', |
| 33 | + sourceType: 'module', |
| 34 | + globals: { ...globals.browser }, |
| 35 | + parser: tseslint.parser, |
| 36 | + }, |
| 37 | + settings: { |
| 38 | + react: { version: 'detect' }, |
| 39 | + 'import-x/resolver': { typescript: true, node: true }, |
| 40 | + }, |
| 41 | + plugins: { |
| 42 | + 'react-hooks': reactHooksPlugin, |
| 43 | + 'react-refresh': reactRefreshPlugin, |
| 44 | + }, |
| 45 | + rules: { |
| 46 | + // 플러그인 기본 설정 주입 |
| 47 | + ...reactHooksPlugin.configs['recommended'].rules, |
| 48 | + |
| 49 | + // --- 커스텀 Rules 시작 --- |
| 50 | + 'react-refresh/only-export-components': [ |
| 51 | + 'warn', |
| 52 | + { allowConstantExport: true }, // 상수 내보내기 허용 |
| 53 | + ], |
| 54 | + 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', |
| 55 | + 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off', |
| 56 | + 'no-param-reassign': ['error', { props: false }], |
| 57 | + 'prefer-const': 'warn', |
| 58 | + 'no-plusplus': 'off', |
| 59 | + 'vars-on-top': 'off', |
| 60 | + 'no-underscore-dangle': 'off', // var _foo; |
| 61 | + 'comma-dangle': 'off', |
| 62 | + 'func-names': 'off', // setTimeout(function () {}, 0); |
| 63 | + 'prefer-arrow-callback': 'off', // setTimeout(function () {}, 0); |
| 64 | + 'prefer-template': 'off', |
| 65 | + 'no-nested-ternary': 'off', |
| 66 | + 'max-classes-per-file': 'off', |
| 67 | + 'no-restricted-syntax': ['off', 'ForOfStatement'], |
| 68 | + 'consistent-return': 'warn', |
| 69 | + 'react/prop-types': 'off', |
| 70 | + 'no-unused-expressions': 'warn', |
| 71 | + 'no-unused-vars': 'off', |
| 72 | + '@typescript-eslint/no-unused-vars': [ |
| 73 | + 'warn', |
| 74 | + { |
| 75 | + argsIgnorePattern: '^_', // _로 시작하는 인자 무시 |
| 76 | + varsIgnorePattern: '^_', // _로 시작하는 변수 무시 |
| 77 | + }, |
| 78 | + ], |
| 79 | + |
| 80 | + /** import 정렬 관련 설정 */ |
| 81 | + 'import-x/no-unresolved': 'error', |
| 82 | + 'import-x/order': [ |
| 83 | + 'warn', |
| 84 | + { |
| 85 | + // 그룹 순서 지정 |
| 86 | + groups: [ |
| 87 | + 'builtin', // Built-in imports go first |
| 88 | + 'external', // External imports |
| 89 | + 'internal', // Absolute imports |
| 90 | + ['parent', 'sibling'], // Relative imports from siblings and parents can mix |
| 91 | + 'index', // index imports |
| 92 | + 'object', |
| 93 | + 'type', |
| 94 | + ], |
| 95 | + 'newlines-between': 'always', |
| 96 | + // 패턴으로 세부적인 순서 지정 |
| 97 | + pathGroups: [ |
| 98 | + { |
| 99 | + pattern: '{react,react-dom,react-dom/*}', |
| 100 | + group: 'external', |
| 101 | + position: 'before', |
| 102 | + }, |
| 103 | + ], |
| 104 | + // 리액트 패키지는 external 그룹에서 알파벳 순이 아닌 상단에 위치시키기 위해 예외 처리 |
| 105 | + pathGroupsExcludedImportTypes: ['react'], |
| 106 | + alphabetize: { order: 'asc', caseInsensitive: true }, |
| 107 | + }, |
| 108 | + ], |
| 109 | + }, |
| 110 | + }, |
| 111 | + |
| 112 | + // 6. Node.js 전역변수 — 서버/설정 파일 전용 ✅ |
| 113 | + { |
| 114 | + files: ['vite.config.*', 'vitest.config.*', 'scripts/**/*.{js,ts}'], |
| 115 | + languageOptions: { |
| 116 | + globals: { ...globals.node }, |
| 117 | + }, |
| 118 | + }, |
| 119 | + |
| 120 | + // 7. Prettier — 반드시 마지막 (다른 포맷 규칙 override) |
| 121 | + prettierRecommended, |
| 122 | + { |
| 123 | + rules: { |
| 124 | + // Prettier 포맷 관련 내용은 'warn' 으로 취급(ESLint/Prettier 충돌 방지) ▼ |
| 125 | + // { endOfLine: 'auto' } 엔드라인 시퀀스 자동 변경 ▼ |
| 126 | + 'prettier/prettier': ['warn', { endOfLine: 'auto' }], |
| 127 | + }, |
| 128 | + }, |
| 129 | +); |
0 commit comments