1 | exports.config = (api, preset, rootOptions = {}) => {
|
2 | const config = {
|
3 | root: true,
|
4 | env: { node: true },
|
5 | extends: ['plugin:vue/essential'],
|
6 | parserOptions: {
|
7 | ecmaVersion: 2020
|
8 | },
|
9 | rules: {
|
10 | 'no-console': makeJSOnlyValue(`process.env.NODE_ENV === 'production' ? 'warn' : 'off'`),
|
11 | 'no-debugger': makeJSOnlyValue(`process.env.NODE_ENV === 'production' ? 'warn' : 'off'`)
|
12 | }
|
13 | }
|
14 |
|
15 | if (api.hasPlugin('babel') && !api.hasPlugin('typescript')) {
|
16 | config.parserOptions = {
|
17 | parser: 'babel-eslint'
|
18 | }
|
19 | }
|
20 |
|
21 | if (preset === 'airbnb') {
|
22 | config.extends.push('@vue/airbnb')
|
23 | } else if (preset === 'standard') {
|
24 | config.extends.push('@vue/standard')
|
25 | } else if (preset === 'prettier') {
|
26 | config.extends.push(...['eslint:recommended', '@vue/prettier'])
|
27 | } else {
|
28 |
|
29 | config.extends.push('eslint:recommended')
|
30 | }
|
31 |
|
32 | if (api.hasPlugin('typescript')) {
|
33 |
|
34 |
|
35 | if (preset === 'prettier') {
|
36 | config.extends.pop()
|
37 | config.extends.push(...['@vue/typescript/recommended', '@vue/prettier', '@vue/prettier/@typescript-eslint'])
|
38 | } else {
|
39 | config.extends.push('@vue/typescript/recommended')
|
40 | }
|
41 | }
|
42 |
|
43 | if (rootOptions.vueVersion === '3') {
|
44 | const updateConfig = cfg =>
|
45 | cfg.replace(
|
46 | /plugin:vue\/(essential|recommended|strongly-recommended)/gi,
|
47 | 'plugin:vue/vue3-$1'
|
48 | )
|
49 | config.extends = config.extends.map(updateConfig)
|
50 | }
|
51 |
|
52 | return config
|
53 | }
|
54 |
|
55 |
|
56 |
|
57 | function makeJSOnlyValue (str) {
|
58 | const fn = () => {}
|
59 | fn.__expression = str
|
60 | return fn
|
61 | }
|
62 |
|
63 | const baseExtensions = ['.js', '.jsx', '.vue']
|
64 | exports.extensions = api => api.hasPlugin('typescript')
|
65 | ? baseExtensions.concat('.ts', '.tsx')
|
66 | : baseExtensions
|