|
| 1 | +import js from '@eslint/js'; |
| 2 | +import { defineConfig } from 'eslint/config'; |
| 3 | +import prettierConfig from 'eslint-config-prettier/flat'; |
| 4 | +import importPlugin from 'eslint-plugin-import'; |
| 5 | +import jestPlugin from 'eslint-plugin-jest'; |
| 6 | +import jestDomPlugin from 'eslint-plugin-jest-dom'; |
| 7 | +import reactPlugin from 'eslint-plugin-react'; |
| 8 | +import testingLibraryPlugin from 'eslint-plugin-testing-library'; |
| 9 | +import globals from 'globals'; |
| 10 | +import tseslint from 'typescript-eslint'; |
| 11 | + |
| 12 | +export default defineConfig([ |
| 13 | + js.configs.recommended, |
| 14 | + reactPlugin.configs.flat.recommended, |
| 15 | + reactPlugin.configs.flat['jsx-runtime'], |
| 16 | + importPlugin.flatConfigs.recommended, |
| 17 | + prettierConfig, |
| 18 | + { |
| 19 | + languageOptions: { |
| 20 | + globals: { |
| 21 | + ...globals.browser, |
| 22 | + ...globals.node, |
| 23 | + }, |
| 24 | + }, |
| 25 | + |
| 26 | + settings: { |
| 27 | + 'import/resolver': { |
| 28 | + typescript: true, |
| 29 | + node: true, |
| 30 | + }, |
| 31 | + |
| 32 | + react: { version: 'detect' }, |
| 33 | + }, |
| 34 | + |
| 35 | + rules: { |
| 36 | + 'import/order': [ |
| 37 | + 'error', |
| 38 | + { |
| 39 | + groups: ['builtin', 'external', 'internal'], |
| 40 | + |
| 41 | + pathGroups: [ |
| 42 | + { |
| 43 | + pattern: 'react', |
| 44 | + group: 'external', |
| 45 | + position: 'before', |
| 46 | + }, |
| 47 | + ], |
| 48 | + |
| 49 | + pathGroupsExcludedImportTypes: ['react'], |
| 50 | + 'newlines-between': 'always', |
| 51 | + |
| 52 | + alphabetize: { |
| 53 | + order: 'asc', |
| 54 | + caseInsensitive: true, |
| 55 | + }, |
| 56 | + }, |
| 57 | + ], |
| 58 | + // This rule doesn't seem important enough to be flagged. |
| 59 | + 'import/no-named-as-default-member': 'off', |
| 60 | + }, |
| 61 | + |
| 62 | + linterOptions: { |
| 63 | + // This property is specified both here in addition to the command line in |
| 64 | + // package.json. |
| 65 | + // The reason is that the property only warns but the command line option |
| 66 | + // outputs errors, but the property is useful so that we have the information |
| 67 | + // directly in editors. |
| 68 | + reportUnusedDisableDirectives: true, |
| 69 | + }, |
| 70 | + }, |
| 71 | + { |
| 72 | + // TypeScript linting |
| 73 | + files: ['**/*.{ts,tsx}'], |
| 74 | + extends: [ |
| 75 | + tseslint.configs.recommendedTypeChecked, |
| 76 | + importPlugin.flatConfigs.typescript, |
| 77 | + ], |
| 78 | + |
| 79 | + languageOptions: { |
| 80 | + parserOptions: { |
| 81 | + tsconfigRootDir: import.meta.dirname, |
| 82 | + projectService: true, |
| 83 | + }, |
| 84 | + }, |
| 85 | + }, |
| 86 | + { |
| 87 | + // Typescript test files |
| 88 | + files: ['src/__tests__/**/*.{ts,tsx}'], |
| 89 | + extends: [ |
| 90 | + jestPlugin.configs['flat/recommended'], |
| 91 | + jestPlugin.configs['flat/style'], |
| 92 | + testingLibraryPlugin.configs['flat/react'], |
| 93 | + jestDomPlugin.configs['flat/recommended'], |
| 94 | + ], |
| 95 | + |
| 96 | + languageOptions: { |
| 97 | + parserOptions: { |
| 98 | + ecmaFeatures: { jsx: true }, |
| 99 | + }, |
| 100 | + }, |
| 101 | + |
| 102 | + rules: { |
| 103 | + // TODO: update tests to not use store directly and remove these overrides |
| 104 | + // https://github.com/mozilla/perfcompare/issues/115 |
| 105 | + '@typescript-eslint/no-unsafe-member-access': 'off', |
| 106 | + // We can be less strict in tests about non-null assertions, to make it easier. |
| 107 | + '@typescript-eslint/no-non-null-assertion': 'off', |
| 108 | + // In tests we can accept that async functions do not have await directives. |
| 109 | + '@typescript-eslint/require-await': 'off', |
| 110 | + |
| 111 | + // This disallows using direct Node properties (eg: firstChild), but we have |
| 112 | + // legitimate uses: |
| 113 | + 'testing-library/no-node-access': 'off', |
| 114 | + |
| 115 | + // Other useful rules in testing-library |
| 116 | + 'testing-library/prefer-explicit-assert': [ |
| 117 | + 'error', |
| 118 | + { includeFindQueries: false }, |
| 119 | + ], |
| 120 | + |
| 121 | + // Individual jest-formatting rules so that we format only test and describe blocks |
| 122 | + 'jest/padding-around-describe-blocks': 2, |
| 123 | + 'jest/padding-around-test-blocks': 2, |
| 124 | + }, |
| 125 | + }, |
| 126 | + { |
| 127 | + // JavaScript linting |
| 128 | + files: ['**/*.js', '**/*.mjs'], |
| 129 | + languageOptions: { |
| 130 | + ecmaVersion: 'latest', |
| 131 | + sourceType: 'module', |
| 132 | + }, |
| 133 | + }, |
| 134 | +]); |
0 commit comments