|
| 1 | +import path from 'path'; |
| 2 | +import { fileURLToPath } from 'url'; |
| 3 | +import stylistic from '@stylistic/eslint-plugin'; |
| 4 | +import reactRefresh from 'eslint-plugin-react-refresh'; |
| 5 | +import globals from 'globals'; |
| 6 | +import js from '@eslint/js'; |
| 7 | +// import tsParser from '@typescript-eslint/parser'; |
| 8 | +import reactRecommended from 'eslint-plugin-react/configs/recommended.js'; |
| 9 | +import customRules from 'eslint-plugin-custom-rules'; |
| 10 | + |
| 11 | +// import eslint-plugin-react-hooks & @typescript-eslint/eslint-plugin & customRules to not let tools report them as unused |
| 12 | +// eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 13 | +import eslintPluginReactHooks from 'eslint-plugin-react-hooks'; |
| 14 | +// eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 15 | +import tsEslintEslintPlugin from '@typescript-eslint/eslint-plugin'; |
| 16 | + |
| 17 | +import { FlatCompat } from '@eslint/eslintrc'; |
| 18 | + |
| 19 | +// mimic CommonJS variables -- not needed if using CommonJS |
| 20 | +const __filename = fileURLToPath(import.meta.url); |
| 21 | +const __dirname = path.dirname(__filename); |
| 22 | + |
| 23 | +const compat = new FlatCompat({ |
| 24 | + baseDirectory: __dirname, |
| 25 | +}); |
| 26 | + |
| 27 | +// TODO add eslint-plugin-import when https://github.com/import-js/eslint-plugin-import/issues/2556 is done |
| 28 | + |
| 29 | +export default [ |
| 30 | + // rules recommended by @eslint/js |
| 31 | + js.configs.recommended, |
| 32 | + |
| 33 | + // rules recommended by eslint-plugin-react |
| 34 | + { |
| 35 | + ...reactRecommended, |
| 36 | + settings: { |
| 37 | + react: { |
| 38 | + version: 'detect', |
| 39 | + }, |
| 40 | + }, |
| 41 | + }, |
| 42 | + |
| 43 | + // rules recommended by @stylistic/eslint-plugin |
| 44 | + stylistic.configs.customize({ |
| 45 | + semi: true, |
| 46 | + }), |
| 47 | + |
| 48 | + // rules recommended by @typescript-eslint/eslint-plugin |
| 49 | + ...compat.extends('plugin:@typescript-eslint/recommended'), |
| 50 | + |
| 51 | + // rules recommended by eslint-plugin-react-hooks |
| 52 | + ...compat.extends('plugin:react-hooks/recommended'), |
| 53 | + |
| 54 | + // eslint-plugin-custom-rules config |
| 55 | + { |
| 56 | + plugins: { |
| 57 | + 'custom-rules': customRules, |
| 58 | + }, |
| 59 | + rules: { |
| 60 | + 'custom-rules/classes-rule': 1, |
| 61 | + }, |
| 62 | + }, |
| 63 | + |
| 64 | + // other config |
| 65 | + { |
| 66 | + languageOptions: { |
| 67 | + globals: { |
| 68 | + ...globals.browser, |
| 69 | + ...globals.commonjs, |
| 70 | + ...globals.es2020, |
| 71 | + process: true, |
| 72 | + }, |
| 73 | + }, |
| 74 | + plugins: { |
| 75 | + 'react-refresh': reactRefresh, |
| 76 | + }, |
| 77 | + rules: { |
| 78 | + // react-refresh rules |
| 79 | + 'react-refresh/only-export-components': [ |
| 80 | + 'warn', |
| 81 | + { allowConstantExport: true }, |
| 82 | + ], |
| 83 | + |
| 84 | + // react rules |
| 85 | + 'react/no-unused-prop-types': 0, |
| 86 | + 'react/prop-types': 0, |
| 87 | + |
| 88 | + // @typescript-eslint rules |
| 89 | + '@typescript-eslint/naming-convention': ['error', { |
| 90 | + selector: 'variable', |
| 91 | + format: ['camelCase', 'UPPER_CASE'], |
| 92 | + leadingUnderscore: 'allow', |
| 93 | + trailingUnderscore: 'allow', |
| 94 | + filter: { |
| 95 | + regex: '/([^_]*)/', |
| 96 | + match: true, |
| 97 | + }, |
| 98 | + }], |
| 99 | + '@typescript-eslint/no-unused-vars': [ |
| 100 | + 'error', |
| 101 | + { |
| 102 | + argsIgnorePattern: '^_', |
| 103 | + varsIgnorePattern: '^_', |
| 104 | + caughtErrorsIgnorePattern: '^_', |
| 105 | + }, |
| 106 | + ], |
| 107 | + |
| 108 | + // @stylistic rules |
| 109 | + '@stylistic/arrow-parens': 'off', |
| 110 | + '@stylistic/quote-props': ['error', 'as-needed'], |
| 111 | + '@stylistic/brace-style': ['error', '1tbs'], |
| 112 | + }, |
| 113 | + }, |
| 114 | + |
| 115 | + // ignores patterns |
| 116 | + { |
| 117 | + ignores: ['src/static/ext', 'packages', 'builder/prod/build', 'builder/dev/build'], |
| 118 | + }, |
| 119 | +]; |
0 commit comments