4
4
*/
5
5
'use strict'
6
6
7
- // ------------------------------------------------------------------------------
8
- // Requirements
9
- // ------------------------------------------------------------------------------
10
-
11
7
const utils = require ( 'eslint-plugin-vue/lib/utils' )
12
8
const casing = require ( 'eslint-plugin-vue/lib/utils/casing' )
13
9
const { toRegExp } = require ( 'eslint-plugin-vue/lib/utils/regexp' )
14
10
15
- // -----------------------------------------------------------------------------
16
- // Helpers
17
- // -----------------------------------------------------------------------------
18
-
19
11
const allowedCaseOptions = [ 'PascalCase' , 'kebab-case' ]
20
12
const defaultCase = 'PascalCase'
21
13
14
+ /**
15
+ * Checks whether the given variable is the type-only import object.
16
+ * @param {Variable } variable
17
+ * @returns {boolean } `true` if the given variable is the type-only import.
18
+ */
19
+ function isTypeOnlyImport ( variable ) {
20
+ if ( variable . defs . length === 0 ) return false
21
+
22
+ return variable . defs . every ( ( def ) => {
23
+ if ( def . type !== 'ImportBinding' ) {
24
+ return false
25
+ }
26
+ if ( def . parent . importKind === 'type' ) {
27
+ // check for `import type Foo from './xxx'`
28
+ return true
29
+ }
30
+ if ( def . node . type === 'ImportSpecifier' && def . node . importKind === 'type' ) {
31
+ // check for `import { type Foo } from './xxx'`
32
+ return true
33
+ }
34
+ return false
35
+ } )
36
+ }
37
+
22
38
module . exports = {
23
39
meta : {
24
40
type : 'suggestion' ,
@@ -53,7 +69,10 @@ module.exports = {
53
69
} ,
54
70
additionalProperties : false
55
71
}
56
- ]
72
+ ] ,
73
+ messages : {
74
+ incorrectCase : 'Component name "{{name}}" is not {{caseType}}.'
75
+ }
57
76
} ,
58
77
/** @param {RuleContext } context */
59
78
create ( context ) {
@@ -67,9 +86,10 @@ module.exports = {
67
86
/** @type {string[] } */
68
87
const globals = ( options . globals || [ ] ) . map ( casing . pascalCase )
69
88
const registeredComponentsOnly = options . registeredComponentsOnly !== false
89
+ const sourceCode = context . getSourceCode ( )
70
90
const tokens =
71
- context . parserServices . getTemplateBodyTokenStore &&
72
- context . parserServices . getTemplateBodyTokenStore ( )
91
+ sourceCode . parserServices . getTemplateBodyTokenStore &&
92
+ sourceCode . parserServices . getTemplateBodyTokenStore ( )
73
93
74
94
/** @type { Set<string> } */
75
95
const registeredComponents = new Set ( globals )
@@ -83,7 +103,9 @@ module.exports = {
83
103
( scope ) => scope . type === 'module'
84
104
)
85
105
for ( const variable of ( moduleScope && moduleScope . variables ) || [ ] ) {
86
- registeredComponents . add ( variable . name )
106
+ if ( ! isTypeOnlyImport ( variable ) ) {
107
+ registeredComponents . add ( variable . name )
108
+ }
87
109
}
88
110
}
89
111
}
@@ -99,9 +121,13 @@ module.exports = {
99
121
}
100
122
101
123
if (
102
- ( ! utils . isHtmlElementNode ( node ) && ! utils . isSvgElementNode ( node ) ) ||
124
+ ( ! utils . isHtmlElementNode ( node ) &&
125
+ ! utils . isSvgElementNode ( node ) &&
126
+ ! utils . isMathElementNode ( node ) ) ||
103
127
utils . isHtmlWellKnownElementName ( node . rawName ) ||
104
- utils . isSvgWellKnownElementName ( node . rawName )
128
+ utils . isSvgWellKnownElementName ( node . rawName ) ||
129
+ utils . isMathWellKnownElementName ( node . rawName ) ||
130
+ utils . isVueBuiltInElementName ( node . rawName )
105
131
) {
106
132
return false
107
133
}
@@ -137,7 +163,7 @@ module.exports = {
137
163
context . report ( {
138
164
node : open ,
139
165
loc : open . loc ,
140
- message : 'Component name "{{name}}" is not {{caseType}}. ' ,
166
+ messageId : 'incorrectCase ' ,
141
167
data : {
142
168
name,
143
169
caseType
0 commit comments