|
| 1 | +import { fixupConfigRules, fixupPluginRules } from "@eslint/compat"; |
| 2 | +import typescriptEslint from "@typescript-eslint/eslint-plugin"; |
| 3 | +import formatjs from "eslint-plugin-formatjs"; |
| 4 | +import patternflyReact from "eslint-plugin-patternfly-react"; |
| 5 | +import react from "eslint-plugin-react"; |
| 6 | +import simpleImportSort from "eslint-plugin-simple-import-sort"; |
| 7 | +import sortKeysFix from "eslint-plugin-sort-keys-fix"; |
| 8 | +import testingLibrary from "eslint-plugin-testing-library"; |
| 9 | +import globals from "globals"; |
| 10 | +import path from "node:path"; |
| 11 | +import { fileURLToPath } from "node:url"; |
| 12 | +import js from "@eslint/js"; |
| 13 | +import { FlatCompat } from "@eslint/eslintrc"; |
| 14 | +// import prettier from "eslint-plugin-prettier"; |
| 15 | + |
| 16 | +const __filename = fileURLToPath(import.meta.url); |
| 17 | +const __dirname = path.dirname(__filename); |
| 18 | +const compat = new FlatCompat({ |
| 19 | + baseDirectory: __dirname, |
| 20 | + recommendedConfig: js.configs.recommended, |
| 21 | + allConfig: js.configs.all |
| 22 | +}); |
| 23 | + |
| 24 | +export default [{ |
| 25 | + ignores: [ |
| 26 | + '**/node_modules', |
| 27 | + '**/public', |
| 28 | + '**/dist', |
| 29 | + '**/.DS_Store', |
| 30 | + '**/coverage', |
| 31 | + '**/npm-debug.log', |
| 32 | + '**/yarn-debug.log', |
| 33 | + '**/yarn-error.log', |
| 34 | + '**/.idea', |
| 35 | + '**/.project', |
| 36 | + '**/.classpath', |
| 37 | + '**/.c9', |
| 38 | + '**/*.launch', |
| 39 | + '**/.settings', |
| 40 | + '**/*.sublime-workspace', |
| 41 | + '**/.history', |
| 42 | + '**/.vscode', |
| 43 | + '**/.vscode', |
| 44 | + '**/*.swp', |
| 45 | + '**/*.test.ts', |
| 46 | + '**/*.test.tsx', |
| 47 | + ], |
| 48 | +}, ...fixupConfigRules(compat.extends( |
| 49 | + '@redhat-cloud-services/eslint-config-redhat-cloud-services', |
| 50 | + 'eslint:recommended', // Extended by eslint-config-redhat-cloud-services |
| 51 | + 'plugin:@typescript-eslint/recommended', |
| 52 | + 'plugin:react/recommended', // Extended by eslint-config-redhat-cloud-services |
| 53 | + 'plugin:react-hooks/recommended', |
| 54 | +)), { |
| 55 | + plugins: { |
| 56 | + '@typescript-eslint': fixupPluginRules(typescriptEslint), |
| 57 | + formatjs, |
| 58 | + 'patternfly-react': patternflyReact, |
| 59 | + // prettier, // Plugin defined by eslint-config-redhat-cloud-services |
| 60 | + react: fixupPluginRules(react), |
| 61 | + 'simple-import-sort': simpleImportSort, |
| 62 | + 'sort-keys-fix': sortKeysFix, |
| 63 | + 'testing-library': testingLibrary, |
| 64 | + }, |
| 65 | + |
| 66 | + languageOptions: { |
| 67 | + globals: { |
| 68 | + ...globals.browser, |
| 69 | + ...globals.node, |
| 70 | + afterEach: 'readonly', |
| 71 | + beforeEach: 'readonly', |
| 72 | + describe: 'readonly', |
| 73 | + expect: 'readonly', |
| 74 | + global: 'writable', |
| 75 | + insights: 'readonly', |
| 76 | + it: 'readonly', |
| 77 | + jest: 'readonly', |
| 78 | + mount: 'readonly', |
| 79 | + render: 'readonly', |
| 80 | + require: 'readonly', |
| 81 | + test: 'readonly', |
| 82 | + shallow: 'readonly', |
| 83 | + }, |
| 84 | + |
| 85 | + ecmaVersion: 5, |
| 86 | + sourceType: 'module', |
| 87 | + |
| 88 | + parserOptions: { |
| 89 | + ecmaFeatures: { |
| 90 | + jsx: true, |
| 91 | + }, |
| 92 | + }, |
| 93 | + }, |
| 94 | + |
| 95 | + settings: { |
| 96 | + react: { |
| 97 | + version: 'detect', |
| 98 | + }, |
| 99 | + }, |
| 100 | + |
| 101 | + rules: { |
| 102 | + '@typescript-eslint/adjacent-overload-signatures': 'error', |
| 103 | + '@typescript-eslint/array-type': 'error', |
| 104 | + '@typescript-eslint/ban-types': 'error', |
| 105 | + '@typescript-eslint/camelcase': 'off', |
| 106 | + '@typescript-eslint/consistent-type-assertions': 'error', |
| 107 | + '@typescript-eslint/consistent-type-definitions': 'error', |
| 108 | + '@typescript-eslint/consistent-type-imports': 'error', |
| 109 | + '@typescript-eslint/explicit-function-return-type': 'off', |
| 110 | + '@typescript-eslint/explicit-module-boundary-types': 'off', |
| 111 | + '@typescript-eslint/explicit-member-accessibility': 'off', |
| 112 | + '@typescript-eslint/indent': 'off', |
| 113 | + '@typescript-eslint/no-empty-function': 'off', |
| 114 | + '@typescript-eslint/no-empty-interface': 'off', |
| 115 | + '@typescript-eslint/no-misused-new': 'error', |
| 116 | + '@typescript-eslint/no-namespace': 'error', |
| 117 | + '@typescript-eslint/no-var-requires': 'off', |
| 118 | + '@typescript-eslint/prefer-for-of': 'error', |
| 119 | + '@typescript-eslint/prefer-function-type': 'error', |
| 120 | + '@typescript-eslint/prefer-namespace-keyword': 'error', |
| 121 | + '@typescript-eslint/no-explicit-any': 'off', |
| 122 | + '@typescript-eslint/no-use-before-define': 'off', |
| 123 | + '@typescript-eslint/no-inferrable-types': 'off', |
| 124 | + '@typescript-eslint/triple-slash-reference': 'error', |
| 125 | + '@typescript-eslint/unified-signatures': 'error', |
| 126 | + |
| 127 | + 'arrow-parens': [2, 'as-needed', { |
| 128 | + requireForBlockBody: false, |
| 129 | + }], |
| 130 | + |
| 131 | + 'constructor-super': 'error', |
| 132 | + curly: 'error', |
| 133 | + 'dot-notation': 'error', |
| 134 | + eqeqeq: ['error', 'smart'], |
| 135 | + // 'formatjs/enforce-default-message': 'error', // Not working -- see https://github.com/formatjs/formatjs/issues/4388 |
| 136 | + // 'formatjs/enforce-description': 'error', |
| 137 | + // 'formatjs/enforce-id': 'error', |
| 138 | + 'guard-for-in': 'error', |
| 139 | + 'max-classes-per-file': ['error', 1], |
| 140 | + 'max-len': 'off', |
| 141 | + 'no-bitwise': 'error', |
| 142 | + 'no-caller': 'error', |
| 143 | + 'no-cond-assign': 'error', |
| 144 | + 'no-console': 'error', |
| 145 | + 'no-debugger': 'error', |
| 146 | + 'no-empty': 'error', |
| 147 | + 'no-eval': 'error', |
| 148 | + 'no-new-wrappers': 'error', |
| 149 | + 'no-prototype-builtins': 'off', |
| 150 | + |
| 151 | + 'no-restricted-imports': ['error', { |
| 152 | + patterns: ['../*/**'], |
| 153 | + }], |
| 154 | + |
| 155 | + 'no-shadow': 'error', |
| 156 | + 'no-throw-literal': 'error', |
| 157 | + 'no-trailing-spaces': 'off', |
| 158 | + 'no-undef': 'off', |
| 159 | + 'no-undef-init': 'error', |
| 160 | + 'no-unsafe-finally': 'error', |
| 161 | + |
| 162 | + 'no-unused-expressions': ['error', { |
| 163 | + allowTernary: true, |
| 164 | + allowShortCircuit: true, |
| 165 | + }], |
| 166 | + |
| 167 | + 'no-unused-labels': 'error', |
| 168 | + 'no-var': 'error', |
| 169 | + 'object-shorthand': 'error', |
| 170 | + 'one-var': ['error', 'never'], |
| 171 | + 'patternfly-react/no-anonymous-functions': 0, |
| 172 | + 'prefer-const': 'error', |
| 173 | + 'prettier/prettier': 'error', |
| 174 | + radix: ['error', 'as-needed'], |
| 175 | + 'react-hooks/exhaustive-deps': 0, |
| 176 | + 'react/display-name': 0, |
| 177 | + |
| 178 | + 'react/no-unescaped-entities': ['error', { |
| 179 | + forbid: ['>', '}'], |
| 180 | + }], |
| 181 | + |
| 182 | + 'react/no-unknown-property': ['error', { |
| 183 | + ignore: ['key'], |
| 184 | + }], |
| 185 | + |
| 186 | + 'react/prop-types': 0, |
| 187 | + 'simple-import-sort/imports': 'error', |
| 188 | + 'spaced-comment': 'error', |
| 189 | + 'rulesdir/disallow-pf-migrated-components': 'off', |
| 190 | + 'rulesdir/forbid-pf-relative-imports': 'off', |
| 191 | + 'testing-library/await-async-queries': 'error', |
| 192 | + 'testing-library/no-await-sync-queries': 'error', |
| 193 | + // 'testing-library/no-debugging-utils': 'warn', // Not working -- see https://eslint.org/docs/latest/use/troubleshooting/v9-rule-api-changes |
| 194 | + 'testing-library/no-dom-import': 'off', |
| 195 | + 'use-isnan': 'error', |
| 196 | + }, |
| 197 | +}, { |
| 198 | + files: ['src/locales/messages.ts'], |
| 199 | + |
| 200 | + rules: { |
| 201 | + 'sort-keys-fix/sort-keys-fix': 'error', |
| 202 | + }, |
| 203 | +}, ...compat.extends('plugin:testing-library/react').map(config => ({ |
| 204 | + ...config, |
| 205 | + files: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'], |
| 206 | +}))]; |
0 commit comments