@@ -7,6 +7,48 @@ const { parse, AST } = require('vue-eslint-parser')
7
7
const { defineTemplateBodyVisitor } = require ( '../utils/index' )
8
8
9
9
const hasOnlyLineBreak = value => / ^ [ \r \n \t \f \v ] + $ / . test ( value . replace ( / / g, '' ) )
10
+ const INNER_START_OFFSET = '<template>' . length
11
+
12
+ function calculateLoc ( node , base = null ) {
13
+ return ! base
14
+ ? node . loc
15
+ : {
16
+ start : {
17
+ line : base . loc . start . line ,
18
+ column : base . loc . start . column + ( node . loc . start . column - INNER_START_OFFSET )
19
+ } ,
20
+ end : {
21
+ line : base . loc . end . line ,
22
+ column : base . loc . end . column + ( node . loc . end . column - INNER_START_OFFSET )
23
+ }
24
+ }
25
+ }
26
+
27
+ function checkVExpressionContainerText ( context , node , baseNode = null ) {
28
+ if ( ! node . expression ) { return }
29
+
30
+ if ( node . expression . type === 'Literal' ) {
31
+ const literalNode = node . expression
32
+ const loc = calculateLoc ( literalNode , baseNode )
33
+ context . report ( {
34
+ loc,
35
+ message : `raw text '${ literalNode . value } ' is used`
36
+ } )
37
+ } else if ( node . expression . type === 'ConditionalExpression' ) {
38
+ const targets = [ node . expression . consequent , node . expression . alternate ]
39
+ targets . forEach ( target => {
40
+ if ( target . type === 'Literal' ) {
41
+ const loc = calculateLoc ( target , baseNode )
42
+ context . report ( {
43
+ loc,
44
+ message : `raw text '${ target . value } ' is used`
45
+ } )
46
+ }
47
+ } )
48
+ } else if ( ( node . parent && node . parent . type === 'VAttribute' && node . parent . directive ) &&
49
+ ( node . parent . key && node . parent . key . type === 'VDirectiveKey' ) ) {
50
+ }
51
+ }
10
52
11
53
function checkRawText ( context , value , loc ) {
12
54
if ( typeof value !== 'string' || hasOnlyLineBreak ( value ) ) { return }
@@ -52,6 +94,10 @@ function getComponentTemplateNode (value) {
52
94
53
95
function create ( context ) {
54
96
return defineTemplateBodyVisitor ( context , { // template block
97
+ VExpressionContainer ( node ) {
98
+ checkVExpressionContainerText ( context , node )
99
+ } ,
100
+
55
101
VText ( node ) {
56
102
checkRawText ( context , node . value , node . loc )
57
103
}
@@ -65,6 +111,8 @@ function create (context) {
65
111
enterNode ( node ) {
66
112
if ( node . type === 'VText' ) {
67
113
checkRawText ( context , node . value , valueNode . loc )
114
+ } else if ( node . type === 'VExpressionContainer' ) {
115
+ checkVExpressionContainerText ( context , node , valueNode )
68
116
}
69
117
} ,
70
118
leaveNode ( ) { }
0 commit comments