|
| 1 | +const globals = require('globals'); |
| 2 | + |
| 3 | +const eslint = require('@eslint/js'); |
| 4 | +const tsEslint = require('typescript-eslint'); |
| 5 | + |
| 6 | +const importPlugin = require('eslint-plugin-import'); |
| 7 | +const jsxA11yPlugin = require('eslint-plugin-jsx-a11y'); |
| 8 | +const reactPlugin = require('eslint-plugin-react'); |
| 9 | +const reactHooksPlugin = require('eslint-plugin-react-hooks'); |
| 10 | +const storybookPlugin = require('eslint-plugin-storybook'); |
| 11 | +const tailwindPlugin = require('eslint-plugin-tailwindcss'); |
| 12 | +const testingLibraryPlugin = require('eslint-plugin-testing-library'); |
| 13 | + |
| 14 | +const tsConfig = require('./tsconfig.json'); |
| 15 | + |
| 16 | +const config = tsEslint.config( |
| 17 | + // Default rules |
| 18 | + eslint.configs.recommended, |
| 19 | + importPlugin.flatConfigs.recommended, |
| 20 | + importPlugin.flatConfigs.typescript, |
| 21 | + jsxA11yPlugin.flatConfigs.recommended, |
| 22 | + reactPlugin.configs.flat.recommended, |
| 23 | + reactPlugin.configs.flat['jsx-runtime'], |
| 24 | + ...storybookPlugin.configs['flat/recommended'], |
| 25 | + ...tailwindPlugin.configs['flat/recommended'], |
| 26 | + ...tsEslint.configs.recommendedTypeChecked, |
| 27 | + ...tsEslint.configs.strictTypeChecked, |
| 28 | + ...tsEslint.configs.stylisticTypeChecked, |
| 29 | + { |
| 30 | + languageOptions: { |
| 31 | + globals: { |
| 32 | + ...globals.node, |
| 33 | + }, |
| 34 | + parserOptions: { |
| 35 | + projectService: true, |
| 36 | + tsconfigRootDir: __dirname, |
| 37 | + ecmaFeatures: { |
| 38 | + jsx: true, |
| 39 | + }, |
| 40 | + }, |
| 41 | + }, |
| 42 | + settings: { |
| 43 | + react: { |
| 44 | + version: 'detect', |
| 45 | + }, |
| 46 | + 'import/resolver': { |
| 47 | + typescript: true, |
| 48 | + node: true, |
| 49 | + }, |
| 50 | + tailwindcss: { |
| 51 | + callees: ['classnames', 'classNames'], |
| 52 | + }, |
| 53 | + }, |
| 54 | + plugins: { |
| 55 | + 'react-hooks': reactHooksPlugin, |
| 56 | + }, |
| 57 | + }, |
| 58 | + { |
| 59 | + ignores: tsConfig.exclude, |
| 60 | + }, |
| 61 | + { |
| 62 | + rules: { |
| 63 | + 'no-console': 'warn', |
| 64 | + curly: 'warn', |
| 65 | + 'prefer-template': 'warn', |
| 66 | + 'no-useless-concat': 'warn', |
| 67 | + '@typescript-eslint/no-empty-object-type': ['error', { allowInterfaces: 'always' }], |
| 68 | + '@typescript-eslint/no-unused-vars': ['error', { ignoreRestSiblings: true }], |
| 69 | + '@typescript-eslint/no-misused-promises': ['error', { checksVoidReturn: false }], |
| 70 | + '@typescript-eslint/no-confusing-void-expression': ['error', { ignoreArrowShorthand: true }], |
| 71 | + '@typescript-eslint/array-type': ['error', { default: 'array-simple' }], |
| 72 | + '@typescript-eslint/no-non-null-assertion': 'off', |
| 73 | + 'import/no-cycle': 'warn', |
| 74 | + 'react/prop-types': 'off', |
| 75 | + 'react/jsx-boolean-value': ['warn', 'always'], |
| 76 | + 'react/self-closing-comp': 'warn', |
| 77 | + 'react/jsx-curly-brace-presence': ['warn', { props: 'never', children: 'never' }], |
| 78 | + ...reactHooksPlugin.configs.recommended.rules, |
| 79 | + }, |
| 80 | + }, |
| 81 | + // Rules for JavaScript files |
| 82 | + { |
| 83 | + files: ['**/*.js'], |
| 84 | + ...tsEslint.configs.disableTypeChecked, |
| 85 | + rules: { |
| 86 | + ...tsEslint.configs.disableTypeChecked.rules, |
| 87 | + '@typescript-eslint/no-require-imports': 'off', |
| 88 | + }, |
| 89 | + }, |
| 90 | + // Rules for test files |
| 91 | + { |
| 92 | + files: ['**/*.test.ts', '**/*.test.tsx'], |
| 93 | + ...testingLibraryPlugin.configs['flat/react'], |
| 94 | + rules: { |
| 95 | + ...testingLibraryPlugin.configs['flat/react'].rules, |
| 96 | + '@typescript-eslint/unbound-method': 'off', |
| 97 | + }, |
| 98 | + }, |
| 99 | + // Rules for Storybook files |
| 100 | + { |
| 101 | + files: ['**/*.stories.tsx'], |
| 102 | + rules: { |
| 103 | + 'react-hooks/rules-of-hooks': 'off', |
| 104 | + }, |
| 105 | + }, |
| 106 | +); |
| 107 | + |
| 108 | +module.exports = config; |
0 commit comments