|
| 1 | +// @ts-check |
| 2 | +import { fixupConfigRules, fixupPluginRules } from '@eslint/compat'; |
| 3 | +import { FlatCompat } from '@eslint/eslintrc'; |
| 4 | +import eslint from '@eslint/js'; |
| 5 | +import eslintConfigPrettier from 'eslint-config-prettier'; |
| 6 | +import reactPlugin 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 | +const tsconfigRootDir = fileURLToPath(new URL('.', import.meta.url)), |
| 13 | + flatCompat = new FlatCompat(); |
| 14 | + |
| 15 | +export default tsEslint.config( |
| 16 | + // register all of the plugins up-front |
| 17 | + { |
| 18 | + plugins: { |
| 19 | + '@typescript-eslint': tsEslint.plugin, |
| 20 | + react: fixupPluginRules(reactPlugin), |
| 21 | + 'simple-import-sort': simpleImportSortPlugin, |
| 22 | + }, |
| 23 | + }, |
| 24 | + { |
| 25 | + // config with just ignores is the replacement for `.eslintignore` |
| 26 | + ignores: ['**/node_modules/**', '**/public/**', '**/.next/**'], |
| 27 | + }, |
| 28 | + |
| 29 | + // extends ... |
| 30 | + eslint.configs.recommended, |
| 31 | + ...tsEslint.configs.recommended, |
| 32 | + ...fixupConfigRules(flatCompat.extends('plugin:@next/next/core-web-vitals')), |
| 33 | + |
| 34 | + // base config |
| 35 | + { |
| 36 | + languageOptions: { |
| 37 | + globals: { ...globals.es2020, ...globals.browser, ...globals.node }, |
| 38 | + parserOptions: { |
| 39 | + projectService: true, |
| 40 | + tsconfigRootDir, |
| 41 | + warnOnUnsupportedTypeScriptVersion: false, |
| 42 | + }, |
| 43 | + }, |
| 44 | + rules: { |
| 45 | + 'no-empty-pattern': 'warn', |
| 46 | + 'simple-import-sort/exports': 'error', |
| 47 | + 'simple-import-sort/imports': 'error', |
| 48 | + '@typescript-eslint/no-unused-vars': 'warn', |
| 49 | + '@typescript-eslint/no-explicit-any': 'warn', |
| 50 | + '@typescript-eslint/no-empty-object-type': 'off', |
| 51 | + '@typescript-eslint/no-unsafe-declaration-merging': 'warn', |
| 52 | + 'react/jsx-no-target-blank': 'warn', |
| 53 | + 'react/jsx-sort-props': [ |
| 54 | + 'error', |
| 55 | + { |
| 56 | + reservedFirst: true, |
| 57 | + callbacksLast: true, |
| 58 | + noSortAlphabetically: true, |
| 59 | + }, |
| 60 | + ], |
| 61 | + '@next/next/no-sync-scripts': 'warn', |
| 62 | + }, |
| 63 | + }, |
| 64 | + { |
| 65 | + files: ['**/*.js'], |
| 66 | + extends: [tsEslint.configs.disableTypeChecked], |
| 67 | + rules: { |
| 68 | + // turn off other type-aware rules |
| 69 | + '@typescript-eslint/internal/no-poorly-typed-ts-props': 'off', |
| 70 | + |
| 71 | + // turn off rules that don't apply to JS code |
| 72 | + '@typescript-eslint/explicit-function-return-type': 'off', |
| 73 | + }, |
| 74 | + }, |
| 75 | + eslintConfigPrettier, |
| 76 | +); |
0 commit comments