-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathindex.ts
77 lines (69 loc) · 2.33 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import * as tseslint from 'typescript-eslint'
import * as tseslintParser from '@typescript-eslint/parser'
import pluginVue from 'eslint-plugin-vue'
type ExtendableConfigName = keyof typeof tseslint.configs
type ScriptLang = 'ts' | 'tsx' | 'js' | 'jsx'
type ConfigOptions = {
extends?: Array<ExtendableConfigName>
supportedScriptLangs?: Record<ScriptLang, boolean>
}
type ConfigArray = ReturnType<typeof tseslint.config>
export default function createConfig({
extends: configNamesToExtend = ['recommended'],
supportedScriptLangs = { ts: true, tsx: false, js: false, jsx: false },
}: ConfigOptions = {}): ConfigArray {
const mayHaveJsx = supportedScriptLangs.jsx || supportedScriptLangs.tsx
return tseslint.config(
...configNamesToExtend
.map(configName => tseslint.configs[configName])
.flat()
.map(config =>
config.files && config.files.includes('**/*.ts')
? {
...config,
files: [...config.files, '**/*.vue'],
}
: config,
),
// Must set eslint-plugin-vue's base config again no matter whether the user
// has set it before. Otherwise it would be overridden by the tseslint's config.
...pluginVue.configs['flat/base'],
{
name: 'vue-typescript/setup',
files: ['*.vue', '**/*.vue'],
languageOptions: {
parserOptions: {
parser: {
// Fallback to espree for js/jsx scripts, as well as SFCs without scripts
// for better performance.
'js': 'espree',
'jsx': 'espree',
'ts': tseslintParser,
'tsx': tseslintParser,
// Leave the template parser unspecified,
// so that it could be determined by `<script lang="...">`
},
ecmaFeatures: {
jsx: mayHaveJsx,
},
extraFileExtensions: ['vue'],
// type-aware linting is in conflict with jsx syntax in `.vue` files
projectService: !mayHaveJsx,
},
},
rules: {
'vue/block-lang': [
'error',
{
script: {
lang: Object.keys(supportedScriptLangs).filter(
lang => supportedScriptLangs[lang as ScriptLang],
),
allowNoLang: supportedScriptLangs.js,
},
},
],
},
},
)
}