|
| 1 | +import babelEslintParser from '@babel/eslint-parser'; |
| 2 | +import eslint from '@eslint/js'; |
| 3 | +import eslintPluginVitest from '@vitest/eslint-plugin'; |
| 4 | +import eslintConfigPrettier from 'eslint-config-prettier'; |
| 5 | +import eslintPluginJsdoc from 'eslint-plugin-jsdoc'; |
| 6 | +import eslintPluginN from 'eslint-plugin-n'; |
| 7 | +import eslintPluginSimpleImportSort from 'eslint-plugin-simple-import-sort'; |
| 8 | +import eslintPluginUnicorn from 'eslint-plugin-unicorn'; |
| 9 | +import globals from 'globals'; |
| 10 | +import tseslint from 'typescript-eslint'; |
| 11 | + |
| 12 | +const parserOptionsJs = { |
| 13 | + ecmaFeatures: { |
| 14 | + modules: true, |
| 15 | + }, |
| 16 | + ecmaVersion: 'latest', |
| 17 | + requireConfigFile: false, |
| 18 | +}; |
| 19 | + |
| 20 | +const parserOptionsTs = { |
| 21 | + projectService: true, |
| 22 | + // eslint-disable-next-line n/no-unsupported-features/node-builtins |
| 23 | + tsconfigRootDir: import.meta.dirname, |
| 24 | +}; |
| 25 | + |
| 26 | +const customRules = { |
| 27 | + rules: { |
| 28 | + 'jsdoc/check-param-names': 'off', |
| 29 | + 'jsdoc/newline-after-description': 'off', |
| 30 | + 'jsdoc/require-jsdoc': ['error', { publicOnly: true }], |
| 31 | + 'jsdoc/require-param': 'off', |
| 32 | + 'jsdoc/require-param-type': 'off', |
| 33 | + 'jsdoc/require-returns': 'off', |
| 34 | + 'jsdoc/require-returns-type': 'off', |
| 35 | + 'jsdoc/tag-lines': 'off', |
| 36 | + 'unicorn/consistent-destructuring': 'off', |
| 37 | + 'unicorn/consistent-function-scoping': [ |
| 38 | + 'error', |
| 39 | + { checkArrowFunctions: false }, |
| 40 | + ], |
| 41 | + 'unicorn/custom-error-definition': 'error', |
| 42 | + 'unicorn/no-array-callback-reference': 'off', |
| 43 | + 'unicorn/no-empty-file': 'off', |
| 44 | + 'unicorn/no-null': 'off', |
| 45 | + 'unicorn/prefer-module': 'off', |
| 46 | + 'unicorn/prefer-ternary': ['error', 'only-single-line'], |
| 47 | + 'unicorn/prevent-abbreviations': [ |
| 48 | + 'error', |
| 49 | + { allowList: { args: true, doc: true, Doc: true, env: true } }, |
| 50 | + ], |
| 51 | + }, |
| 52 | +}; |
| 53 | + |
| 54 | +export default tseslint.config( |
| 55 | + { |
| 56 | + ignores: [ |
| 57 | + 'dist/', |
| 58 | + 'node_modules/', |
| 59 | + '.*/', |
| 60 | + 'tests/__snapshots__/', |
| 61 | + 'tests/cases/', |
| 62 | + 'vite.config.ts', |
| 63 | + ], |
| 64 | + }, |
| 65 | + { |
| 66 | + linterOptions: { |
| 67 | + reportUnusedDisableDirectives: 'error', |
| 68 | + }, |
| 69 | + }, |
| 70 | + |
| 71 | + eslint.configs.recommended, |
| 72 | + tseslint.configs.strict, |
| 73 | + eslintPluginJsdoc.configs['flat/recommended'], |
| 74 | + eslintPluginUnicorn.configs.recommended, |
| 75 | + eslintConfigPrettier, |
| 76 | + { |
| 77 | + plugins: { |
| 78 | + 'simple-import-sort': eslintPluginSimpleImportSort, |
| 79 | + }, |
| 80 | + rules: { |
| 81 | + 'simple-import-sort/imports': 'error', |
| 82 | + 'simple-import-sort/exports': 'error', |
| 83 | + }, |
| 84 | + }, |
| 85 | + customRules, |
| 86 | + |
| 87 | + // JavaScript files |
| 88 | + { |
| 89 | + files: ['**/*.js'], |
| 90 | + languageOptions: { |
| 91 | + parser: babelEslintParser, |
| 92 | + parserOptions: parserOptionsJs, |
| 93 | + }, |
| 94 | + }, |
| 95 | + |
| 96 | + // TypeScript files |
| 97 | + { |
| 98 | + extends: [tseslint.configs.recommendedTypeChecked], |
| 99 | + files: ['**/*.ts'], |
| 100 | + languageOptions: { |
| 101 | + parserOptions: parserOptionsTs, |
| 102 | + }, |
| 103 | + }, |
| 104 | + |
| 105 | + // Test Files |
| 106 | + { |
| 107 | + ...eslintPluginVitest.configs.recommended, |
| 108 | + files: ['tests/**/*.test.{js,ts}'], |
| 109 | + plugins: { |
| 110 | + vitest: eslintPluginVitest, |
| 111 | + }, |
| 112 | + }, |
| 113 | + |
| 114 | + // Configuration files |
| 115 | + { |
| 116 | + ...eslintPluginN.configs['flat/recommended-script'], |
| 117 | + files: ['**/*.cjs'], |
| 118 | + languageOptions: { |
| 119 | + ecmaVersion: 'latest', |
| 120 | + globals: globals.node, |
| 121 | + sourceType: 'script', |
| 122 | + }, |
| 123 | + plugins: { |
| 124 | + n: eslintPluginN, |
| 125 | + }, |
| 126 | + }, |
| 127 | + { |
| 128 | + ...eslintPluginN.configs['flat/recommended-module'], |
| 129 | + files: ['**/*.mjs'], |
| 130 | + languageOptions: { |
| 131 | + ecmaVersion: 'latest', |
| 132 | + globals: globals.node, |
| 133 | + parserOptions: parserOptionsJs, |
| 134 | + sourceType: 'module', |
| 135 | + }, |
| 136 | + plugins: { |
| 137 | + n: eslintPluginN, |
| 138 | + }, |
| 139 | + }, |
| 140 | +); |
0 commit comments