|
| 1 | +const {fixupConfigRules, fixupPluginRules} = require('@eslint/compat'); |
| 2 | +const globals = require('globals'); |
| 3 | +const googleConfig = require('eslint-config-google'); |
| 4 | +const jsdocPlugin = require('eslint-plugin-jsdoc'); |
| 5 | +const reactPlugin = require('eslint-plugin-react'); |
| 6 | + |
| 7 | +const jsdocRecommended = jsdocPlugin.configs['flat/recommended'] || jsdocPlugin.configs.recommended; |
| 8 | + |
| 9 | +const [reactRecommended] = fixupConfigRules(reactPlugin.configs.recommended); |
| 10 | +const googleRules = { |
| 11 | + ...googleConfig.rules, |
| 12 | +}; |
| 13 | +delete googleRules['valid-jsdoc']; |
| 14 | +delete googleRules['require-jsdoc']; |
| 15 | + |
| 16 | +module.exports = [ |
| 17 | + { |
| 18 | + ignores: [ |
| 19 | + '**/*.min.js', |
| 20 | + '**/dist/', |
| 21 | + '**/build/', |
| 22 | + '**/vendor/', |
| 23 | + 'eslint.config.js', |
| 24 | + ], |
| 25 | + }, |
| 26 | + { |
| 27 | + name: 'quicklink/base', |
| 28 | + languageOptions: { |
| 29 | + ecmaVersion: 2017, |
| 30 | + sourceType: 'script', |
| 31 | + parserOptions: { |
| 32 | + ecmaFeatures: { |
| 33 | + jsx: true, |
| 34 | + }, |
| 35 | + }, |
| 36 | + globals: { |
| 37 | + ...globals.browser, |
| 38 | + ...globals.node, |
| 39 | + }, |
| 40 | + }, |
| 41 | + plugins: { |
| 42 | + react: fixupPluginRules(reactPlugin), |
| 43 | + }, |
| 44 | + settings: { |
| 45 | + react: { |
| 46 | + version: 'detect', |
| 47 | + }, |
| 48 | + }, |
| 49 | + rules: { |
| 50 | + ...(reactRecommended?.rules ?? reactPlugin.configs.recommended.rules), |
| 51 | + ...googleRules, |
| 52 | + 'max-len': [ |
| 53 | + 'warn', |
| 54 | + { |
| 55 | + code: 130, |
| 56 | + }, |
| 57 | + ], |
| 58 | + 'arrow-parens': [ |
| 59 | + 'error', |
| 60 | + 'as-needed', |
| 61 | + ], |
| 62 | + 'space-before-function-paren': [ |
| 63 | + 'error', |
| 64 | + { |
| 65 | + anonymous: 'always', |
| 66 | + named: 'never', |
| 67 | + }, |
| 68 | + ], |
| 69 | + 'no-negated-condition': 'warn', |
| 70 | + 'no-const-assign': 'error', |
| 71 | + 'no-unused-vars': [ |
| 72 | + 'error', |
| 73 | + { |
| 74 | + args: 'none', |
| 75 | + varsIgnorePattern: '^_', |
| 76 | + caughtErrorsIgnorePattern: '^_', |
| 77 | + }, |
| 78 | + ], |
| 79 | + 'prefer-destructuring': [ |
| 80 | + 'off', |
| 81 | + { |
| 82 | + object: true, |
| 83 | + array: false, |
| 84 | + }, |
| 85 | + ], |
| 86 | + 'prefer-template': 'error', |
| 87 | + strict: [ |
| 88 | + 'error', |
| 89 | + 'global', |
| 90 | + ], |
| 91 | + 'spaced-comment': [ |
| 92 | + 'error', |
| 93 | + 'always', |
| 94 | + { |
| 95 | + exceptions: [ |
| 96 | + '/', |
| 97 | + ], |
| 98 | + }, |
| 99 | + ], |
| 100 | + }, |
| 101 | + }, |
| 102 | + { |
| 103 | + files: [ |
| 104 | + 'src/**', |
| 105 | + ], |
| 106 | + languageOptions: { |
| 107 | + sourceType: 'module', |
| 108 | + }, |
| 109 | + rules: { |
| 110 | + strict: [ |
| 111 | + 'error', |
| 112 | + 'never', |
| 113 | + ], |
| 114 | + }, |
| 115 | + }, |
| 116 | + ...(Array.isArray(jsdocRecommended) ? jsdocRecommended : [jsdocRecommended]), |
| 117 | + { |
| 118 | + files: [ |
| 119 | + 'site/src/assets/js/**', |
| 120 | + ], |
| 121 | + languageOptions: { |
| 122 | + sourceType: 'script', |
| 123 | + globals: { |
| 124 | + ...globals.browser, |
| 125 | + }, |
| 126 | + }, |
| 127 | + rules: { |
| 128 | + 'jsdoc/require-jsdoc': 'off', |
| 129 | + strict: [ |
| 130 | + 'error', |
| 131 | + 'function', |
| 132 | + ], |
| 133 | + }, |
| 134 | + }, |
| 135 | + { |
| 136 | + files: [ |
| 137 | + 'site/src/demos/**', |
| 138 | + ], |
| 139 | + languageOptions: { |
| 140 | + sourceType: 'module', |
| 141 | + ecmaVersion: 2020, |
| 142 | + globals: { |
| 143 | + ...globals.browser, |
| 144 | + }, |
| 145 | + }, |
| 146 | + rules: { |
| 147 | + 'jsdoc/require-jsdoc': 'off', |
| 148 | + 'strict': ['error', 'never'], |
| 149 | + 'max-len': 'off', |
| 150 | + }, |
| 151 | + }, |
| 152 | +]; |
0 commit comments