|
| 1 | +import globals from 'globals' |
| 2 | +import js from '@eslint/js' |
| 3 | +import { FlatCompat } from '@eslint/eslintrc' |
| 4 | +import ts from 'typescript-eslint' |
| 5 | +import eslintConfigPrettier from 'eslint-config-prettier' |
| 6 | + |
| 7 | +const vue = extendVuePlugin('plugin:vue/vue3-recommended', ts.parser) |
| 8 | + |
| 9 | +/** @type { import("eslint").Linter.FlatConfig[] } */ |
| 10 | +export default [ |
| 11 | + // ignore globally |
| 12 | + { |
| 13 | + ignores: [ |
| 14 | + '**/dist/**', |
| 15 | + '**/fixtures/**', |
| 16 | + '**/coverage/**', |
| 17 | + '**/.vitepress/**', |
| 18 | + '**/.vuepress/**', |
| 19 | + '**/test/**', |
| 20 | + '**/examples/**', |
| 21 | + 'shim.d.ts', |
| 22 | + '.eslintcache', |
| 23 | + '.eslintrc.cjs' |
| 24 | + ] |
| 25 | + }, |
| 26 | + |
| 27 | + js.configs.recommended, |
| 28 | + ...ts.configs.recommended, |
| 29 | + eslintConfigPrettier, |
| 30 | + ...vue, |
| 31 | + |
| 32 | + // globals |
| 33 | + { |
| 34 | + // files: ['**/*.js', '**/*.ts', '**/*.vue', '**/*.json'], |
| 35 | + languageOptions: { |
| 36 | + globals: { |
| 37 | + __DEV__: true, |
| 38 | + __COMMIT__: true, |
| 39 | + page: true, |
| 40 | + browser: true, |
| 41 | + context: true, |
| 42 | + ...globals.node |
| 43 | + }, |
| 44 | + parserOptions: { sourceType: 'module' } |
| 45 | + } |
| 46 | + }, |
| 47 | + |
| 48 | + // custom rules |
| 49 | + { |
| 50 | + rules: { |
| 51 | + 'object-curly-spacing': 'off', |
| 52 | + '@typescript-eslint/ban-types': 'off', |
| 53 | + '@typescript-eslint/ban-ts-ignore': 'off', |
| 54 | + '@typescript-eslint/ban-ts-comment': 'off', |
| 55 | + '@typescript-eslint/explicit-function-return-type': 'off', |
| 56 | + '@typescript-eslint/member-delimiter-style': 'off', |
| 57 | + '@typescript-eslint/no-use-before-define': 'off', |
| 58 | + '@typescript-eslint/no-var-requires': 'off', |
| 59 | + '@typescript-eslint/no-non-null-assertion': 'off', |
| 60 | + 'vue/one-component-per-file': 'off', |
| 61 | + 'vue/multi-word-component-names': 'off', |
| 62 | + 'vue/experimental-script-setup-vars': 'off', |
| 63 | + 'vue/no-deprecated-props-default-this': 'off' |
| 64 | + } |
| 65 | + } |
| 66 | +] |
| 67 | + |
| 68 | +/** |
| 69 | + * extend eslint-plugin-vue with @typescript-eslint/parser |
| 70 | + * (NOTE: eslint-plugin-vue flat config WIP currently https://github.com/vuejs/eslint-plugin-vue/issues/1291) |
| 71 | + * |
| 72 | + * @param { 'plugin:vue/vue3-essential' | 'plugin:vue/vue3-strongly-recommended' | 'plugin:vue/vue3-recommended' } vueConfigPattern |
| 73 | + * @param { import("typescript-eslint").Config.parser } tsParser |
| 74 | + * |
| 75 | + * @return { import("eslint").Linter.FlatConfig[] } |
| 76 | + */ |
| 77 | +function extendVuePlugin(vueConfigPattern, tsParser) { |
| 78 | + const compat = new FlatCompat() |
| 79 | + const vuePlugin = compat.extends(vueConfigPattern) |
| 80 | + const vueLangOptions = vuePlugin[2] |
| 81 | + vueLangOptions.files = [ |
| 82 | + '**/*.vue', |
| 83 | + '**/*.ts', |
| 84 | + '**/*.tsx', |
| 85 | + '**/*.mts', |
| 86 | + '**/*.cts' |
| 87 | + ] |
| 88 | + vueLangOptions.languageOptions = { |
| 89 | + // NOTE: |
| 90 | + // https://eslint.vuejs.org/user-guide/#how-to-use-a-custom-parser |
| 91 | + parserOptions: { |
| 92 | + parser: tsParser |
| 93 | + }, |
| 94 | + ecmaVersion: 'latest' |
| 95 | + } |
| 96 | + return vuePlugin |
| 97 | +} |
0 commit comments