|
| 1 | +import path from 'node:path'; |
| 2 | +import { includeIgnoreFile } from '@eslint/compat'; |
| 3 | +import js from '@eslint/js'; |
| 4 | +import { FlatCompat } from '@eslint/eslintrc'; |
| 5 | +import { defineConfig, globalIgnores } from 'eslint/config'; |
| 6 | +import importPlugin from 'eslint-plugin-import'; |
| 7 | +import jest from 'eslint-plugin-jest'; |
| 8 | +import prettierRecommended from 'eslint-plugin-prettier/recommended'; |
| 9 | +import globals from 'globals'; |
| 10 | +import typescriptEslint from 'typescript-eslint'; |
| 11 | + |
| 12 | +const compat = new FlatCompat({ |
| 13 | + baseDirectory: import.meta.dirname, |
| 14 | + recommendedConfig: js.configs.recommended, |
| 15 | + allConfig: js.configs.all, |
| 16 | +}); |
| 17 | + |
| 18 | +export default defineConfig([ |
| 19 | + includeIgnoreFile(path.resolve(import.meta.dirname, '.gitignore')), |
| 20 | + globalIgnores([ |
| 21 | + '**/node_modules', |
| 22 | + '**/coverage', |
| 23 | + 'gen-documentation/**/*', |
| 24 | + 'spec/react_on_rails/dummy-for-generators', |
| 25 | + 'spec/dummy', |
| 26 | + 'spec/execjs-compatible-dummy', |
| 27 | + 'packages/node-renderer/lib/', |
| 28 | + 'packages/node-renderer/tests/fixtures', |
| 29 | + 'packages/node-renderer/webpack.config.js', |
| 30 | + '**/node_modules/**/*', |
| 31 | + '**/assets/webpack/**/*', |
| 32 | + '**/generated/**/*', |
| 33 | + '**/app/assets/javascripts/application.js', |
| 34 | + '**/coverage/**/*', |
| 35 | + '**/cable.js', |
| 36 | + '**/public/**/*', |
| 37 | + '**/tmp/**/*', |
| 38 | + '**/vendor', |
| 39 | + '**/dist', |
| 40 | + '**/.yalc/', |
| 41 | + ]), |
| 42 | + { |
| 43 | + files: ['**/*.[jt]s', '**/*.[cm][jt]s', '**/*.[jt]sx'], |
| 44 | + }, |
| 45 | + js.configs.recommended, |
| 46 | + compat.extends('eslint-config-shakacode'), |
| 47 | + { |
| 48 | + languageOptions: { |
| 49 | + globals: globals.node, |
| 50 | + |
| 51 | + parserOptions: { |
| 52 | + // We have @babel/eslint-parser from eslint-config-shakacode, but don't use Babel in the main project |
| 53 | + requireConfigFile: false, |
| 54 | + }, |
| 55 | + }, |
| 56 | + |
| 57 | + settings: { |
| 58 | + 'import/extensions': ['.js', '.ts'], |
| 59 | + |
| 60 | + 'import/parsers': { |
| 61 | + '@typescript-eslint/parser': ['.ts'], |
| 62 | + }, |
| 63 | + |
| 64 | + 'import/resolver': { |
| 65 | + node: true, |
| 66 | + typescript: true, |
| 67 | + }, |
| 68 | + }, |
| 69 | + |
| 70 | + rules: { |
| 71 | + 'no-console': 'off', |
| 72 | + |
| 73 | + 'no-void': [ |
| 74 | + 'error', |
| 75 | + { |
| 76 | + // Allow using void to suppress errors about misused promises |
| 77 | + allowAsStatement: true, |
| 78 | + }, |
| 79 | + ], |
| 80 | + |
| 81 | + // Allow using void to suppress errors about misused promises |
| 82 | + 'no-restricted-syntax': 'off', |
| 83 | + // https://github.com/benmosher/eslint-plugin-import/issues/340 |
| 84 | + 'import/no-extraneous-dependencies': 'off', |
| 85 | + 'import/extensions': 'off', |
| 86 | + 'import/prefer-default-export': 'off', |
| 87 | + 'lines-between-class-members': [ |
| 88 | + 'error', |
| 89 | + { |
| 90 | + enforce: [ |
| 91 | + { blankLine: 'always', prev: '*', next: '*' }, |
| 92 | + { blankLine: 'never', prev: 'field', next: 'field' }, |
| 93 | + ], |
| 94 | + }, |
| 95 | + ], |
| 96 | + 'no-mixed-operators': 'off', |
| 97 | + }, |
| 98 | + }, |
| 99 | + { |
| 100 | + files: ['**/*.ts{x,}'], |
| 101 | + extends: [importPlugin.flatConfigs.typescript, typescriptEslint.configs.strictTypeChecked], |
| 102 | + |
| 103 | + languageOptions: { |
| 104 | + parserOptions: { |
| 105 | + projectService: true, |
| 106 | + }, |
| 107 | + }, |
| 108 | + |
| 109 | + rules: { |
| 110 | + '@typescript-eslint/restrict-template-expressions': 'off', |
| 111 | + |
| 112 | + '@typescript-eslint/no-unused-vars': [ |
| 113 | + 'error', |
| 114 | + { |
| 115 | + argsIgnorePattern: '^_', |
| 116 | + caughtErrorsIgnorePattern: '^_', |
| 117 | + }, |
| 118 | + ], |
| 119 | + |
| 120 | + '@typescript-eslint/no-floating-promises': [ |
| 121 | + 'error', |
| 122 | + { |
| 123 | + allowForKnownSafePromises: [ |
| 124 | + { |
| 125 | + from: 'package', |
| 126 | + package: 'fastify', |
| 127 | + name: 'FastifyReply', |
| 128 | + }, |
| 129 | + ], |
| 130 | + }, |
| 131 | + ], |
| 132 | + |
| 133 | + 'no-shadow': 'off', |
| 134 | + '@typescript-eslint/no-shadow': 'error', |
| 135 | + }, |
| 136 | + }, |
| 137 | + { |
| 138 | + files: ['packages/node-renderer/tests/**'], |
| 139 | + |
| 140 | + plugins: { |
| 141 | + jest, |
| 142 | + }, |
| 143 | + |
| 144 | + languageOptions: { |
| 145 | + globals: globals.jest, |
| 146 | + }, |
| 147 | + |
| 148 | + rules: { |
| 149 | + // Allows Jest mocks before import |
| 150 | + 'import/first': 'off', |
| 151 | + 'jest/no-disabled-tests': 'warn', |
| 152 | + 'jest/no-focused-tests': 'error', |
| 153 | + 'jest/no-identical-title': 'error', |
| 154 | + 'jest/prefer-to-have-length': 'warn', |
| 155 | + 'jest/valid-expect': 'error', |
| 156 | + // Simplifies test code |
| 157 | + '@typescript-eslint/no-non-null-assertion': 'off', |
| 158 | + }, |
| 159 | + }, |
| 160 | + { |
| 161 | + files: ['packages/node-renderer/src/integrations/**'], |
| 162 | + ignores: ['packages/node-renderer/src/integrations/api.ts'], |
| 163 | + |
| 164 | + rules: { |
| 165 | + // Integrations should only use the public integration API |
| 166 | + 'no-restricted-imports': [ |
| 167 | + 'error', |
| 168 | + { |
| 169 | + patterns: ['../*'], |
| 170 | + }, |
| 171 | + ], |
| 172 | + }, |
| 173 | + }, |
| 174 | + // must be the last config in the array |
| 175 | + // https://github.com/prettier/eslint-plugin-prettier?tab=readme-ov-file#configuration-new-eslintconfigjs |
| 176 | + prettierRecommended, |
| 177 | +]); |
0 commit comments