1
- import process from 'node:process'
2
- import { getPackageInfoSync } from 'local-pkg'
3
1
import { GLOB_VUE } from '../globs'
4
2
import { parserVue , pluginVue , tseslint } from '../plugins'
5
- import type { Rules } from '../typegen'
6
3
import type { Config } from '../types'
7
4
import { typescriptCore } from './typescript'
8
5
import type { ESLint } from 'eslint'
9
6
10
- export function getVueVersion ( ) : number {
11
- const pkg = getPackageInfoSync ( 'vue' , { paths : [ process . cwd ( ) ] } )
12
- if (
13
- pkg &&
14
- typeof pkg . version === 'string' &&
15
- ! Number . isNaN ( + pkg . version [ 0 ] )
16
- ) {
17
- return + pkg . version [ 0 ]
18
- }
19
- return 3
20
- }
21
- const isVue2 = getVueVersion ( ) === 2
22
- if ( isVue2 ) {
23
- console . warn ( 'Support for Vue 2 is deprecated. Please upgrade to Vue 3.' )
24
- }
25
-
26
7
export const reactivityTransform = ( ) : Config [ ] => [
27
8
{
28
9
languageOptions : {
@@ -46,64 +27,6 @@ export const reactivityTransform = (): Config[] => [
46
27
} ,
47
28
]
48
29
49
- const vueCustomRules : Rules = {
50
- 'vue/block-order' : [ 'error' , { order : [ 'script' , 'template' , 'style' ] } ] ,
51
- 'vue/custom-event-name-casing' : [ 'error' , 'camelCase' ] ,
52
- 'vue/eqeqeq' : [ 'error' , 'smart' ] ,
53
- 'vue/html-self-closing' : [
54
- 'error' ,
55
- {
56
- html : {
57
- component : 'always' ,
58
- normal : 'always' ,
59
- void : 'any' ,
60
- } ,
61
- math : 'always' ,
62
- svg : 'always' ,
63
- } ,
64
- ] ,
65
- 'vue/max-attributes-per-line' : 'off' ,
66
-
67
- 'vue/multi-word-component-names' : 'off' ,
68
- 'vue/no-constant-condition' : 'warn' ,
69
- 'vue/no-empty-pattern' : 'error' ,
70
- 'vue/no-loss-of-precision' : 'error' ,
71
- 'vue/no-unused-refs' : 'error' ,
72
- 'vue/no-useless-v-bind' : 'error' ,
73
-
74
- 'vue/no-v-html' : 'off' ,
75
- 'vue/object-shorthand' : [
76
- 'error' ,
77
- 'always' ,
78
- {
79
- avoidQuotes : true ,
80
- ignoreConstructors : false ,
81
- } ,
82
- ] ,
83
- 'vue/one-component-per-file' : 'off' ,
84
- 'vue/padding-line-between-blocks' : [ 'error' , 'always' ] ,
85
- 'vue/prefer-template' : 'error' ,
86
- 'vue/require-default-prop' : 'off' ,
87
- 'vue/require-prop-types' : 'off' ,
88
- }
89
-
90
- const vue3Rules : Rules = {
91
- ...pluginVue . configs . base . rules ,
92
- ...pluginVue . configs [ 'vue3-essential' ] . rules ,
93
- ...pluginVue . configs [ 'vue3-strongly-recommended' ] . rules ,
94
- ...pluginVue . configs [ 'vue3-recommended' ] . rules ,
95
- }
96
-
97
- const vue2Rules : Rules = {
98
- ...pluginVue . configs . base . rules ,
99
- ...pluginVue . configs . essential . rules ,
100
- ...pluginVue . configs [ 'strongly-recommended' ] . rules ,
101
- ...pluginVue . configs . recommended . rules ,
102
- }
103
-
104
- delete vue2Rules [ 'vue/component-tags-order' ]
105
- delete vue3Rules [ 'vue/component-tags-order' ]
106
-
107
30
const vueTs : Config [ ] = typescriptCore
108
31
. filter ( ( config ) => config . name !== 'typescript-eslint/base' )
109
32
. map ( ( config ) => {
@@ -114,6 +37,10 @@ const vueTs: Config[] = typescriptCore
114
37
}
115
38
} )
116
39
40
+ const recommendedRules = pluginVue . configs [ 'flat/recommended' ]
41
+ . map ( ( c ) => c . rules )
42
+ . reduce ( ( acc , c ) => ( { ...acc , ...c } ) , { } ) as any
43
+
117
44
export const vue = ( ) : Config [ ] => [
118
45
...vueTs ,
119
46
{
@@ -125,7 +52,7 @@ export const vue = (): Config[] => [
125
52
jsx : true ,
126
53
} ,
127
54
extraFileExtensions : [ '.vue' ] ,
128
- parser : '@typescript-eslint/ parser' ,
55
+ parser : tseslint . parser ,
129
56
sourceType : 'module' ,
130
57
} ,
131
58
} ,
@@ -136,8 +63,46 @@ export const vue = (): Config[] => [
136
63
} ,
137
64
processor : pluginVue . processors [ '.vue' ] ,
138
65
rules : {
139
- ...( isVue2 ? vue2Rules : vue3Rules ) ,
140
- ...vueCustomRules ,
66
+ ...recommendedRules ,
67
+
68
+ 'vue/block-order' : [ 'error' , { order : [ 'script' , 'template' , 'style' ] } ] ,
69
+ 'vue/custom-event-name-casing' : [ 'error' , 'camelCase' ] ,
70
+ 'vue/eqeqeq' : [ 'error' , 'smart' ] ,
71
+ 'vue/html-self-closing' : [
72
+ 'error' ,
73
+ {
74
+ html : {
75
+ component : 'always' ,
76
+ normal : 'always' ,
77
+ void : 'any' ,
78
+ } ,
79
+ math : 'always' ,
80
+ svg : 'always' ,
81
+ } ,
82
+ ] ,
83
+ 'vue/max-attributes-per-line' : 'off' ,
84
+
85
+ 'vue/multi-word-component-names' : 'off' ,
86
+ 'vue/no-constant-condition' : 'warn' ,
87
+ 'vue/no-empty-pattern' : 'error' ,
88
+ 'vue/no-loss-of-precision' : 'error' ,
89
+ 'vue/no-unused-refs' : 'error' ,
90
+ 'vue/no-useless-v-bind' : 'error' ,
91
+
92
+ 'vue/no-v-html' : 'off' ,
93
+ 'vue/object-shorthand' : [
94
+ 'error' ,
95
+ 'always' ,
96
+ {
97
+ avoidQuotes : true ,
98
+ ignoreConstructors : false ,
99
+ } ,
100
+ ] ,
101
+ 'vue/one-component-per-file' : 'off' ,
102
+ 'vue/padding-line-between-blocks' : [ 'error' , 'always' ] ,
103
+ 'vue/prefer-template' : 'error' ,
104
+ 'vue/require-default-prop' : 'off' ,
105
+ 'vue/require-prop-types' : 'off' ,
141
106
} ,
142
107
} ,
143
108
...reactivityTransform ( ) ,
0 commit comments