|
| 1 | +import cspellPlugin from '@cspell/eslint-plugin'; |
| 2 | +import eslint from '@eslint/js'; |
| 3 | +import html from '@html-eslint/eslint-plugin'; |
| 4 | +import stylistic from '@stylistic/eslint-plugin'; |
| 5 | +import eslintConfigPrettier from 'eslint-config-prettier'; |
| 6 | +import react from 'eslint-plugin-react'; |
| 7 | +import simpleImportSortPlugin from 'eslint-plugin-simple-import-sort'; |
| 8 | +import globals from 'globals'; |
| 9 | +import tsEslint from 'typescript-eslint'; |
| 10 | +import { fileURLToPath } from 'url'; |
| 11 | + |
| 12 | +/** |
| 13 | + * @see{@link https://github.com/typescript-eslint/typescript-eslint/blob/main/eslint.config.mjs} |
| 14 | + * @see{@link https://github.com/vercel/next.js/issues/71763#issuecomment-2476838298} |
| 15 | + */ |
| 16 | + |
| 17 | +const tsconfigRootDir = fileURLToPath(new URL('.', import.meta.url)); |
| 18 | + |
| 19 | +export default tsEslint.config( |
| 20 | + // register all of the plugins up-front |
| 21 | + { |
| 22 | + plugins: { |
| 23 | + '@typescript-eslint': tsEslint.plugin, |
| 24 | + react, |
| 25 | + '@stylistic': stylistic, |
| 26 | + 'simple-import-sort': simpleImportSortPlugin, |
| 27 | + '@cspell': cspellPlugin |
| 28 | + } |
| 29 | + }, |
| 30 | + { |
| 31 | + // config with just ignores is the replacement for `.eslintignore` |
| 32 | + ignores: ['**/node_modules/**', 'dist/**', '.parcel-cache/**'] |
| 33 | + }, |
| 34 | + |
| 35 | + // extends ... |
| 36 | + eslint.configs.recommended, |
| 37 | + ...tsEslint.configs.recommended, |
| 38 | + |
| 39 | + // base config |
| 40 | + { |
| 41 | + languageOptions: { |
| 42 | + globals: { ...globals.es2020, ...globals.browser, ...globals.node }, |
| 43 | + parserOptions: { |
| 44 | + projectService: true, |
| 45 | + tsconfigRootDir, |
| 46 | + warnOnUnsupportedTypeScriptVersion: false |
| 47 | + } |
| 48 | + }, |
| 49 | + rules: { |
| 50 | + 'arrow-body-style': ['error', 'as-needed'], |
| 51 | + 'no-empty-pattern': 'warn', |
| 52 | + 'no-console': ['error', { allow: ['warn', 'error', 'info'] }], |
| 53 | + 'consistent-return': 'warn', |
| 54 | + 'prefer-destructuring': ['error', { object: true, array: true }], |
| 55 | + // react |
| 56 | + 'react/no-unescaped-entities': 'off', |
| 57 | + 'react/self-closing-comp': [ |
| 58 | + 'error', |
| 59 | + { component: true, html: true } |
| 60 | + ], |
| 61 | + 'react/jsx-curly-brace-presence': [ |
| 62 | + 'error', |
| 63 | + { props: 'never', children: 'never' } |
| 64 | + ], |
| 65 | + 'react/jsx-no-target-blank': 'warn', |
| 66 | + 'react/jsx-sort-props': [ |
| 67 | + 'error', |
| 68 | + { |
| 69 | + reservedFirst: true, |
| 70 | + callbacksLast: true, |
| 71 | + noSortAlphabetically: true |
| 72 | + } |
| 73 | + ], |
| 74 | + // typescript |
| 75 | + '@typescript-eslint/no-unused-vars': 'warn', |
| 76 | + '@typescript-eslint/no-explicit-any': 'warn', |
| 77 | + '@typescript-eslint/no-empty-object-type': 'off', |
| 78 | + '@typescript-eslint/no-unsafe-declaration-merging': 'warn', |
| 79 | + |
| 80 | + // @typescript-eslint + eslint, works together |
| 81 | + '@typescript-eslint/consistent-type-definitions': [ |
| 82 | + 'error', |
| 83 | + 'interface' |
| 84 | + ], |
| 85 | + 'no-restricted-syntax': [ |
| 86 | + 'error', |
| 87 | + { |
| 88 | + selector: "TSPropertySignature[key.name='children']", |
| 89 | + message: |
| 90 | + 'Please use PropsWithChildren<T> instead of defining children manually' |
| 91 | + } |
| 92 | + ], |
| 93 | + // stylistic |
| 94 | + '@stylistic/padding-line-between-statements': [ |
| 95 | + 'error', |
| 96 | + { blankLine: 'always', prev: '*', next: 'return' }, |
| 97 | + { blankLine: 'always', prev: 'directive', next: '*' }, |
| 98 | + { blankLine: 'any', prev: 'directive', next: 'directive' }, |
| 99 | + { |
| 100 | + blankLine: 'always', |
| 101 | + prev: '*', |
| 102 | + next: ['enum', 'interface', 'type'] |
| 103 | + } |
| 104 | + ], |
| 105 | + |
| 106 | + // simple-import-sort |
| 107 | + 'simple-import-sort/exports': 'error', |
| 108 | + 'simple-import-sort/imports': 'error', |
| 109 | + // spellchecker |
| 110 | + '@cspell/spellchecker': [ |
| 111 | + 'warn', |
| 112 | + { |
| 113 | + cspell: { |
| 114 | + language: 'en', |
| 115 | + dictionaries: [ |
| 116 | + 'typescript', |
| 117 | + 'node', |
| 118 | + 'html', |
| 119 | + 'css', |
| 120 | + 'bash', |
| 121 | + 'npm' |
| 122 | + ] |
| 123 | + } |
| 124 | + } |
| 125 | + ] |
| 126 | + } |
| 127 | + }, |
| 128 | + { |
| 129 | + ...html.configs['flat/recommended'], |
| 130 | + files: ['**/*.html'], |
| 131 | + rules: { |
| 132 | + '@html-eslint/sort-attrs': [ |
| 133 | + 'error', |
| 134 | + { priority: ['rel', 'name', 'id', 'type', 'class', 'style'] } |
| 135 | + ] |
| 136 | + } |
| 137 | + }, |
| 138 | + eslintConfigPrettier |
| 139 | +); |
0 commit comments