|
| 1 | +const fs = require('fs'); |
| 2 | +const path = require('path'); |
| 3 | +const json5 = require('json5'); |
| 4 | +const js = require('@eslint/js'); |
| 5 | +const { FlatCompat } = require('@eslint/eslintrc'); |
| 6 | + |
| 7 | +const hammerheadPlugin = require('eslint-plugin-hammerhead'); |
| 8 | + |
| 9 | +function wrapLegacyRule (rule) { |
| 10 | + if (typeof rule !== 'function') |
| 11 | + return rule; |
| 12 | + |
| 13 | + return { |
| 14 | + meta: {}, |
| 15 | + create: rule, |
| 16 | + }; |
| 17 | +} |
| 18 | + |
| 19 | +hammerheadPlugin.rules = Object.fromEntries( |
| 20 | + Object.entries(hammerheadPlugin.rules).map(([name, rule]) => [name, wrapLegacyRule(rule)]) |
| 21 | +); |
| 22 | + |
| 23 | +const compat = new FlatCompat({ |
| 24 | + baseDirectory: __dirname, |
| 25 | + recommendedConfig: js.configs.recommended, |
| 26 | + allConfig: js.configs.all, |
| 27 | +}); |
| 28 | + |
| 29 | +function readConfig (relativePath) { |
| 30 | + return json5.parse(fs.readFileSync(path.join(__dirname, relativePath), 'utf8')); |
| 31 | +} |
| 32 | + |
| 33 | +function scopeConfigs (files, configs) { |
| 34 | + return configs.map(config => ({ |
| 35 | + ...config, |
| 36 | + files, |
| 37 | + })); |
| 38 | +} |
| 39 | + |
| 40 | +module.exports = [ |
| 41 | + { |
| 42 | + ignores: ['test/server/data/**/*.js'], |
| 43 | + }, |
| 44 | + ...compat.config(readConfig('.eslintrc')), |
| 45 | + ...scopeConfigs(['examples/**/*.js'], compat.config(readConfig('examples/.eslintrc'))), |
| 46 | + ...scopeConfigs(['src/**/*.{js,ts}'], compat.config(readConfig('src/.eslintrc'))), |
| 47 | + ...scopeConfigs(['src/cli/**/*.{js,ts}'], compat.config(readConfig('src/cli/.eslintrc'))), |
| 48 | + ...scopeConfigs(['src/client/**/*.{js,ts}'], compat.config(readConfig('src/client/.eslintrc'))), |
| 49 | + ...scopeConfigs(['src/client/browser/**/*.{js,ts}'], compat.config(readConfig('src/client/browser/.eslintrc'))), |
| 50 | + ...scopeConfigs(['test/docker/**/*.js'], compat.config(readConfig('test/docker/.eslintrc'))), |
| 51 | + ...scopeConfigs(['test/client/**/*.js'], compat.config(readConfig('test/client/.eslintrc'))), |
| 52 | + ...scopeConfigs(['test/client/fixtures/**/*.js'], compat.config(readConfig('test/client/fixtures/.eslintrc'))), |
| 53 | + ...scopeConfigs(['test/functional/**/*.js'], compat.config(readConfig('test/functional/.eslintrc'))), |
| 54 | + ...scopeConfigs(['test/functional/fixtures/**/*.js'], compat.config(readConfig('test/functional/fixtures/.eslintrc'))), |
| 55 | + ...scopeConfigs(['test/functional/legacy-fixtures/**/*.js'], compat.config(readConfig('test/functional/legacy-fixtures/.eslintrc'))), |
| 56 | + ...scopeConfigs(['test/server/**/*.js'], compat.config(readConfig('test/server/.eslintrc'))), |
| 57 | + { |
| 58 | + files: ['src/client/rollup.config.js'], |
| 59 | + languageOptions: { |
| 60 | + globals: { |
| 61 | + __dirname: 'readonly', |
| 62 | + __filename: 'readonly', |
| 63 | + Buffer: 'readonly', |
| 64 | + clearInterval: 'readonly', |
| 65 | + clearTimeout: 'readonly', |
| 66 | + global: 'readonly', |
| 67 | + process: 'readonly', |
| 68 | + setInterval: 'readonly', |
| 69 | + setTimeout: 'readonly', |
| 70 | + }, |
| 71 | + }, |
| 72 | + }, |
| 73 | +]; |
0 commit comments