|
| 1 | +import { version } from 'react'; |
| 2 | +import reactPlugin from 'eslint-plugin-react'; |
| 3 | +import tsPlugin from '@typescript-eslint/eslint-plugin'; |
| 4 | +import tsParser from '@typescript-eslint/parser'; |
| 5 | +import vitestPlugin from '@vitest/eslint-plugin'; |
| 6 | +import prettierPlugin from 'eslint-plugin-prettier'; |
| 7 | + |
| 8 | +const baseConfig = { |
| 9 | + languageOptions: { |
| 10 | + parser: tsParser, |
| 11 | + sourceType: 'module', |
| 12 | + }, |
| 13 | + plugins: { |
| 14 | + '@typescript-eslint': tsPlugin, |
| 15 | + }, |
| 16 | +}; |
| 17 | + |
| 18 | +const ignoreConfig = { |
| 19 | + ignores: [ |
| 20 | + '**/dist', |
| 21 | + '**/lib', |
| 22 | + '**/node_modules', |
| 23 | + '**/packages/pdfkit/**', |
| 24 | + '**/packages/png-js/**', |
| 25 | + '**/packages/svgkit/**', |
| 26 | + '**/packages/yoga/**', |
| 27 | + '**/packages/examples/**', |
| 28 | + ], |
| 29 | +}; |
| 30 | + |
| 31 | +const globalsConfig = { |
| 32 | + languageOptions: { |
| 33 | + globals: { |
| 34 | + atob: false, |
| 35 | + Blob: false, |
| 36 | + BROWSER: false, |
| 37 | + Buffer: false, |
| 38 | + console: false, |
| 39 | + fetch: false, |
| 40 | + global: false, |
| 41 | + module: false, |
| 42 | + process: false, |
| 43 | + TextDecoder: false, |
| 44 | + TextEncoder: false, |
| 45 | + URL: false, |
| 46 | + window: false, |
| 47 | + }, |
| 48 | + }, |
| 49 | +}; |
| 50 | + |
| 51 | +const jsConfig = { |
| 52 | + rules: { |
| 53 | + 'array-callback-return': ['error', { allowImplicit: true }], |
| 54 | + 'block-scoped-var': 'error', |
| 55 | + complexity: ['off', 20], |
| 56 | + 'constructor-super': 'error', |
| 57 | + 'default-case': ['error', { commentPattern: '^no default$' }], |
| 58 | + 'default-case-last': 'error', |
| 59 | + 'dot-notation': ['error', { allowKeywords: true }], |
| 60 | + eqeqeq: ['error', 'always', { null: 'ignore' }], |
| 61 | + 'for-direction': 'error', |
| 62 | + 'grouped-accessor-pairs': 'error', |
| 63 | + 'guard-for-in': 'error', |
| 64 | + 'getter-return': 'error', |
| 65 | + 'max-classes-per-file': ['error', 1], |
| 66 | + 'no-alert': 'error', |
| 67 | + 'no-caller': 'error', |
| 68 | + 'no-async-promise-executor': 'error', |
| 69 | + 'no-case-declarations': 'error', |
| 70 | + 'no-class-assign': 'error', |
| 71 | + 'no-compare-neg-zero': 'error', |
| 72 | + 'no-constructor-return': 'error', |
| 73 | + 'no-await-in-loop': 'error', |
| 74 | + 'no-console': 'warn', |
| 75 | + 'no-cond-assign': 'error', |
| 76 | + 'no-const-assign': 'error', |
| 77 | + 'no-constant-condition': 'warn', |
| 78 | + 'no-else-return': ['error', { allowElseIf: false }], |
| 79 | + 'no-control-regex': 'error', |
| 80 | + 'no-debugger': 'error', |
| 81 | + 'no-delete-var': 'error', |
| 82 | + 'no-dupe-args': 'error', |
| 83 | + 'no-dupe-class-members': 'error', |
| 84 | + 'no-dupe-else-if': 'error', |
| 85 | + 'no-dupe-keys': 'error', |
| 86 | + 'no-duplicate-case': 'error', |
| 87 | + 'no-empty': 'error', |
| 88 | + 'no-eval': 'error', |
| 89 | + 'no-empty-character-class': 'error', |
| 90 | + 'no-empty-pattern': 'error', |
| 91 | + 'no-empty-static-block': 'error', |
| 92 | + 'no-extend-native': 'error', |
| 93 | + 'no-extra-bind': 'error', |
| 94 | + 'no-ex-assign': 'error', |
| 95 | + 'no-extra-boolean-cast': 'error', |
| 96 | + 'no-fallthrough': 'error', |
| 97 | + 'no-func-assign': 'error', |
| 98 | + 'no-global-assign': 'error', |
| 99 | + 'no-import-assign': 'error', |
| 100 | + 'no-invalid-regexp': 'error', |
| 101 | + 'no-implied-eval': 'error', |
| 102 | + 'no-iterator': 'error', |
| 103 | + 'no-irregular-whitespace': 'error', |
| 104 | + 'no-loss-of-precision': 'error', |
| 105 | + 'no-lone-blocks': 'error', |
| 106 | + 'no-loop-func': 'error', |
| 107 | + 'no-labels': ['error', { allowLoop: false, allowSwitch: false }], |
| 108 | + 'no-misleading-character-class': 'error', |
| 109 | + 'no-new-native-nonconstructor': 'error', |
| 110 | + 'no-nonoctal-decimal-escape': 'error', |
| 111 | + 'no-obj-calls': 'error', |
| 112 | + 'no-new-func': 'error', |
| 113 | + 'no-octal': 'error', |
| 114 | + 'no-octal-escape': 'error', |
| 115 | + 'no-proto': 'error', |
| 116 | + 'no-prototype-builtins': 'error', |
| 117 | + 'no-script-url': 'error', |
| 118 | + 'no-return-await': 'error', |
| 119 | + 'no-redeclare': 'error', |
| 120 | + 'no-return-assign': ['error', 'always'], |
| 121 | + 'no-regex-spaces': 'error', |
| 122 | + 'no-new-wrappers': 'error', |
| 123 | + 'no-self-assign': 'error', |
| 124 | + 'no-setter-return': 'error', |
| 125 | + 'no-extra-label': 'error', |
| 126 | + 'no-sequences': 'error', |
| 127 | + 'no-throw-literal': 'error', |
| 128 | + 'no-template-curly-in-string': 'error', |
| 129 | + 'no-shadow-restricted-names': 'error', |
| 130 | + 'no-sparse-arrays': 'error', |
| 131 | + 'no-this-before-super': 'error', |
| 132 | + 'no-undef': 'error', |
| 133 | + 'no-unreachable': 'error', |
| 134 | + 'no-unsafe-finally': 'error', |
| 135 | + 'no-unsafe-negation': 'error', |
| 136 | + 'no-unsafe-optional-chaining': 'error', |
| 137 | + 'no-unused-labels': 'error', |
| 138 | + 'no-negated-in-lhs': 'off', |
| 139 | + 'no-unused-vars': ['error', { ignoreRestSiblings: true }], |
| 140 | + 'no-useless-backreference': 'error', |
| 141 | + 'no-useless-concat': 'error', |
| 142 | + 'no-useless-catch': 'error', |
| 143 | + 'no-useless-escape': 'error', |
| 144 | + 'no-useless-return': 'error', |
| 145 | + 'no-void': 'error', |
| 146 | + 'no-with': 'error', |
| 147 | + 'prefer-promise-reject-errors': ['error', { allowEmptyReject: true }], |
| 148 | + 'prefer-regex-literals': ['error', { disallowRedundantWrapping: true }], |
| 149 | + 'prefer-const': 'error', |
| 150 | + 'prefer-rest-params': 'error', |
| 151 | + 'prefer-spread': 'error', |
| 152 | + radix: 'error', |
| 153 | + 'require-yield': 'error', |
| 154 | + 'use-isnan': 'error', |
| 155 | + 'valid-typeof': 'error', |
| 156 | + yoda: 'error', |
| 157 | + }, |
| 158 | +}; |
| 159 | + |
| 160 | +const reactConfig = { |
| 161 | + settings: { |
| 162 | + react: { version }, |
| 163 | + }, |
| 164 | + plugins: { |
| 165 | + react: reactPlugin, |
| 166 | + }, |
| 167 | + rules: { |
| 168 | + 'react/display-name': 'error', |
| 169 | + 'react/jsx-key': 'error', |
| 170 | + 'react/jsx-no-comment-textnodes': 'error', |
| 171 | + 'react/jsx-no-duplicate-props': 'error', |
| 172 | + 'react/jsx-no-target-blank': 'error', |
| 173 | + 'react/jsx-no-undef': 'error', |
| 174 | + 'react/jsx-uses-vars': 'error', |
| 175 | + 'react/no-children-prop': 'error', |
| 176 | + 'react/no-danger-with-children': 'error', |
| 177 | + 'react/no-deprecated': 'error', |
| 178 | + 'react/no-direct-mutation-state': 'error', |
| 179 | + 'react/no-find-dom-node': 'error', |
| 180 | + 'react/no-is-mounted': 'error', |
| 181 | + 'react/no-render-return-value': 'error', |
| 182 | + 'react/no-string-refs': 'error', |
| 183 | + 'react/no-unescaped-entities': 'error', |
| 184 | + 'react/no-unknown-property': 'error', |
| 185 | + 'react/require-render-return': 'error', |
| 186 | + }, |
| 187 | + languageOptions: { |
| 188 | + parserOptions: { |
| 189 | + jsxPragma: null, |
| 190 | + ecmaFeatures: { |
| 191 | + jsx: true, |
| 192 | + }, |
| 193 | + }, |
| 194 | + }, |
| 195 | +}; |
| 196 | + |
| 197 | +const vitestConfig = { |
| 198 | + files: ['**/*.test.js', '**/*.test.ts'], |
| 199 | + plugins: { |
| 200 | + vitest: vitestPlugin, |
| 201 | + }, |
| 202 | + rules: { |
| 203 | + 'vitest/expect-expect': 'error', |
| 204 | + 'vitest/no-identical-title': 'error', |
| 205 | + 'vitest/no-commented-out-tests': 'error', |
| 206 | + 'vitest/valid-title': 'error', |
| 207 | + 'vitest/valid-expect': 'error', |
| 208 | + 'vitest/valid-describe-callback': 'error', |
| 209 | + 'vitest/require-local-test-context-for-concurrent-snapshots': 'error', |
| 210 | + 'vitest/no-import-node-test': 'error', |
| 211 | + 'vitest/max-nested-describe': ['error', { max: 3 }], |
| 212 | + }, |
| 213 | +}; |
| 214 | + |
| 215 | +const tsConfig = { |
| 216 | + files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts'], |
| 217 | + rules: { |
| 218 | + 'constructor-super': 'off', |
| 219 | + 'getter-return': 'off', |
| 220 | + 'no-class-assign': 'off', |
| 221 | + 'no-const-assign': 'off', |
| 222 | + 'no-dupe-args': 'off', |
| 223 | + 'no-dupe-class-members': 'off', |
| 224 | + 'no-dupe-keys': 'off', |
| 225 | + 'no-func-assign': 'off', |
| 226 | + 'no-import-assign': 'off', |
| 227 | + 'no-new-native-nonconstructor': 'off', |
| 228 | + 'no-promise-executor-return': 'error', |
| 229 | + 'no-obj-calls': 'off', |
| 230 | + 'no-redeclare': 'off', |
| 231 | + 'no-setter-return': 'off', |
| 232 | + 'no-this-before-super': 'off', |
| 233 | + 'no-undef': 'off', |
| 234 | + 'no-unreachable': 'off', |
| 235 | + 'no-unsafe-negation': 'off', |
| 236 | + 'no-unused-vars': 'off', |
| 237 | + '@typescript-eslint/ban-ts-comment': 'error', |
| 238 | + '@typescript-eslint/no-array-constructor': 'error', |
| 239 | + '@typescript-eslint/no-duplicate-enum-values': 'error', |
| 240 | + '@typescript-eslint/no-empty-object-type': 'error', |
| 241 | + '@typescript-eslint/no-explicit-any': 'off', |
| 242 | + '@typescript-eslint/no-extra-non-null-assertion': 'error', |
| 243 | + '@typescript-eslint/no-misused-new': 'error', |
| 244 | + '@typescript-eslint/no-namespace': 'error', |
| 245 | + '@typescript-eslint/no-non-null-asserted-optional-chain': 'error', |
| 246 | + '@typescript-eslint/no-require-imports': 'error', |
| 247 | + '@typescript-eslint/no-this-alias': 'error', |
| 248 | + '@typescript-eslint/no-unnecessary-type-constraint': 'error', |
| 249 | + '@typescript-eslint/no-unsafe-declaration-merging': 'error', |
| 250 | + '@typescript-eslint/no-unsafe-function-type': 'error', |
| 251 | + '@typescript-eslint/no-unused-expressions': 'error', |
| 252 | + '@typescript-eslint/no-unused-vars': 'error', |
| 253 | + '@typescript-eslint/no-wrapper-object-types': 'error', |
| 254 | + '@typescript-eslint/prefer-as-const': 'error', |
| 255 | + '@typescript-eslint/prefer-namespace-keyword': 'error', |
| 256 | + '@typescript-eslint/triple-slash-reference': 'error', |
| 257 | + }, |
| 258 | +}; |
| 259 | + |
| 260 | +const prettierConfig = { |
| 261 | + plugins: { |
| 262 | + prettier: prettierPlugin, |
| 263 | + }, |
| 264 | + rules: { |
| 265 | + 'prettier/prettier': 'error', |
| 266 | + }, |
| 267 | +}; |
| 268 | + |
| 269 | +const config = [ |
| 270 | + baseConfig, |
| 271 | + ignoreConfig, |
| 272 | + globalsConfig, |
| 273 | + jsConfig, |
| 274 | + reactConfig, |
| 275 | + vitestConfig, |
| 276 | + tsConfig, |
| 277 | + prettierConfig, |
| 278 | +]; |
| 279 | + |
| 280 | +export default config; |
0 commit comments