|
| 1 | +import jest from 'eslint-plugin-jest'; |
| 2 | +import jsxA11y from 'eslint-plugin-jsx-a11y'; |
| 3 | +import prettierRecommended from 'eslint-plugin-prettier/recommended'; |
| 4 | +import { importX } from 'eslint-plugin-import-x'; |
| 5 | +import * as eslintImportResolverTypescript from 'eslint-import-resolver-typescript'; |
| 6 | +import noRelativeImportPaths from 'eslint-plugin-no-relative-import-paths'; |
| 7 | +import react from 'eslint-plugin-react'; |
| 8 | +import security from 'eslint-plugin-security'; |
| 9 | +import sonarjs from 'eslint-plugin-sonarjs'; |
| 10 | +import json from 'eslint-plugin-json'; |
| 11 | +import unicorn from 'eslint-plugin-unicorn'; |
| 12 | +import { defineConfig, globalIgnores } from 'eslint/config'; |
| 13 | +import js from '@eslint/js'; |
| 14 | +import html from 'eslint-plugin-html'; |
| 15 | +import tseslint from 'typescript-eslint'; |
| 16 | +import sortDestructureKeys from 'eslint-plugin-sort-destructure-keys'; |
| 17 | +import { |
| 18 | + configs as airbnbConfigs, |
| 19 | + plugins as airbnbPlugins, |
| 20 | +} from 'eslint-config-airbnb-extended'; |
| 21 | +import { rules as prettierConfigRules } from 'eslint-config-prettier'; |
| 22 | + |
| 23 | +import { dirname } from 'node:path'; |
| 24 | +import { fileURLToPath } from 'node:url'; |
| 25 | +import { FlatCompat } from '@eslint/eslintrc'; |
| 26 | + |
| 27 | +const __filename = fileURLToPath(import.meta.url); |
| 28 | +const __dirname = dirname(__filename); |
| 29 | + |
| 30 | +const compat = new FlatCompat({ |
| 31 | + baseDirectory: __dirname, |
| 32 | +}); |
| 33 | + |
| 34 | +export default defineConfig([ |
| 35 | + globalIgnores([ |
| 36 | + '**/*/coverage/*', |
| 37 | + '**/.build', |
| 38 | + '**/node_modules', |
| 39 | + '**/dist', |
| 40 | + '**/test-results', |
| 41 | + '**/playwright-report*', |
| 42 | + 'eslint.config.mjs', |
| 43 | + ]), |
| 44 | + |
| 45 | + //imports |
| 46 | + importX.flatConfigs.recommended, |
| 47 | + { rules: { ...airbnbPlugins.importX.rules } }, |
| 48 | + |
| 49 | + // js |
| 50 | + js.configs.recommended, |
| 51 | + airbnbPlugins.stylistic, |
| 52 | + airbnbConfigs.base.recommended, |
| 53 | + |
| 54 | + // ts |
| 55 | + tseslint.configs.strictTypeChecked, |
| 56 | + tseslint.configs.stylisticTypeChecked, |
| 57 | + airbnbConfigs.base.typescript, |
| 58 | + airbnbPlugins.typescriptEslint, |
| 59 | + |
| 60 | + { |
| 61 | + ignores: ['**/*.json'], |
| 62 | + languageOptions: { |
| 63 | + parserOptions: { |
| 64 | + projectService: true, |
| 65 | + tsconfigRootDir: import.meta.dirname, |
| 66 | + }, |
| 67 | + }, |
| 68 | + }, |
| 69 | + |
| 70 | + { |
| 71 | + files: ['**/*.json'], |
| 72 | + extends: [tseslint.configs.disableTypeChecked], |
| 73 | + }, |
| 74 | + |
| 75 | + { |
| 76 | + settings: { |
| 77 | + 'import-x/resolver-next': [ |
| 78 | + eslintImportResolverTypescript.createTypeScriptImportResolver({ |
| 79 | + project: [ |
| 80 | + 'frontend/tsconfig.json', |
| 81 | + 'lambdas/*/tsconfig.json', |
| 82 | + 'tests/test-team/tsconfig.json', |
| 83 | + 'utils/*/tsconfig.json', |
| 84 | + ], |
| 85 | + }), |
| 86 | + ], |
| 87 | + }, |
| 88 | + }, |
| 89 | + |
| 90 | + { |
| 91 | + rules: { |
| 92 | + '@typescript-eslint/no-unused-vars': [ |
| 93 | + 2, |
| 94 | + { |
| 95 | + argsIgnorePattern: '^_', |
| 96 | + varsIgnorePattern: '^_', |
| 97 | + }, |
| 98 | + ], |
| 99 | + '@typescript-eslint/consistent-type-definitions': 0, |
| 100 | + }, |
| 101 | + }, |
| 102 | + |
| 103 | + // unicorn |
| 104 | + unicorn.configs['recommended'], |
| 105 | + { |
| 106 | + rules: { |
| 107 | + 'unicorn/prevent-abbreviations': 0, |
| 108 | + 'unicorn/filename-case': [ |
| 109 | + 2, |
| 110 | + { |
| 111 | + case: 'kebabCase', |
| 112 | + ignore: ['.tsx'], |
| 113 | + }, |
| 114 | + ], |
| 115 | + 'unicorn/no-null': 0, |
| 116 | + 'unicorn/prefer-module': 0, |
| 117 | + 'unicorn/import-style': [ |
| 118 | + 2, |
| 119 | + { |
| 120 | + styles: { |
| 121 | + path: { |
| 122 | + named: true, |
| 123 | + }, |
| 124 | + }, |
| 125 | + }, |
| 126 | + ], |
| 127 | + }, |
| 128 | + }, |
| 129 | + |
| 130 | + // react |
| 131 | + react.configs.flat.recommended, |
| 132 | + airbnbConfigs.react.recommended, |
| 133 | + airbnbConfigs.react.typescript, |
| 134 | + airbnbPlugins.react, |
| 135 | + airbnbPlugins.reactHooks, |
| 136 | + airbnbPlugins.reactA11y, |
| 137 | + |
| 138 | + // jest |
| 139 | + jest.configs['flat/recommended'], |
| 140 | + |
| 141 | + // prettier |
| 142 | + prettierRecommended, |
| 143 | + { rules: { ...prettierConfigRules, 'prettier/prettier': 2 } }, |
| 144 | + |
| 145 | + // jsxA11y |
| 146 | + { |
| 147 | + files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'], |
| 148 | + plugins: { |
| 149 | + 'jsx-a11y': jsxA11y, |
| 150 | + }, |
| 151 | + languageOptions: { |
| 152 | + parserOptions: { |
| 153 | + ecmaFeatures: { |
| 154 | + jsx: true, |
| 155 | + }, |
| 156 | + }, |
| 157 | + }, |
| 158 | + }, |
| 159 | + |
| 160 | + // security |
| 161 | + security.configs.recommended, |
| 162 | + |
| 163 | + // sonar |
| 164 | + sonarjs.configs.recommended, |
| 165 | + |
| 166 | + // html |
| 167 | + { |
| 168 | + files: ['**/*.html'], |
| 169 | + plugins: { html }, |
| 170 | + }, |
| 171 | + |
| 172 | + // Next.js |
| 173 | + ...compat.config({ |
| 174 | + extends: ['next', 'next/core-web-vitals', 'next/typescript'], |
| 175 | + settings: { |
| 176 | + next: { |
| 177 | + rootDir: 'frontend', |
| 178 | + }, |
| 179 | + }, |
| 180 | + rules: { |
| 181 | + // needed because next lint rules look for a pages directory |
| 182 | + '@next/next/no-html-link-for-pages': 0, |
| 183 | + }, |
| 184 | + }), |
| 185 | + |
| 186 | + // json |
| 187 | + { |
| 188 | + files: ['**/*.json'], |
| 189 | + ...json.configs['recommended'], |
| 190 | + }, |
| 191 | + |
| 192 | + // destructure sorting |
| 193 | + { |
| 194 | + name: 'eslint-plugin-sort-destructure-keys', |
| 195 | + plugins: { |
| 196 | + 'sort-destructure-keys': sortDestructureKeys, |
| 197 | + }, |
| 198 | + rules: { |
| 199 | + 'sort-destructure-keys/sort-destructure-keys': 2, |
| 200 | + }, |
| 201 | + }, |
| 202 | + |
| 203 | + // imports |
| 204 | + { |
| 205 | + rules: { |
| 206 | + 'sort-imports': [ |
| 207 | + 2, |
| 208 | + { |
| 209 | + ignoreDeclarationSort: true, |
| 210 | + }, |
| 211 | + ], |
| 212 | + 'import-x/extensions': 0, |
| 213 | + }, |
| 214 | + }, |
| 215 | + { |
| 216 | + files: ['**/*.ts', '**/*.tsx'], |
| 217 | + rules: { |
| 218 | + 'import-x/no-unresolved': 0, // trust the typescript compiler to catch unresolved imports |
| 219 | + }, |
| 220 | + }, |
| 221 | + { |
| 222 | + files: ['tests/test-team/**'], |
| 223 | + rules: { |
| 224 | + 'import-x/no-extraneous-dependencies': [ |
| 225 | + 2, |
| 226 | + { |
| 227 | + devDependencies: true, |
| 228 | + }, |
| 229 | + ], |
| 230 | + }, |
| 231 | + }, |
| 232 | + { |
| 233 | + files: ['**/utils/**', 'tests/test-team/**'], |
| 234 | + rules: { |
| 235 | + 'import-x/prefer-default-export': 0, |
| 236 | + }, |
| 237 | + }, |
| 238 | + { |
| 239 | + plugins: { |
| 240 | + 'no-relative-import-paths': noRelativeImportPaths, |
| 241 | + }, |
| 242 | + rules: { |
| 243 | + 'no-relative-import-paths/no-relative-import-paths': 2, |
| 244 | + }, |
| 245 | + }, |
| 246 | + { |
| 247 | + files: ['scripts/**'], |
| 248 | + rules: { |
| 249 | + 'import-x/no-extraneous-dependencies': [ |
| 250 | + 'error', |
| 251 | + { devDependencies: true }, |
| 252 | + ], |
| 253 | + }, |
| 254 | + }, |
| 255 | + |
| 256 | + // misc rule overrides |
| 257 | + { |
| 258 | + rules: { |
| 259 | + 'no-restricted-syntax': 0, |
| 260 | + 'no-underscore-dangle': 0, |
| 261 | + 'no-await-in-loop': 0, |
| 262 | + 'no-plusplus': [2, { allowForLoopAfterthoughts: true }], |
| 263 | + 'unicorn/prefer-top-level-await': 0, // top level await is not available in commonjs |
| 264 | + }, |
| 265 | + }, |
| 266 | +]); |
0 commit comments