@@ -7,6 +7,48 @@ const { parse, AST } = require('vue-eslint-parser')
77const { defineTemplateBodyVisitor } = require ( '../utils/index' )
88
99const 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+ }
1052
1153function checkRawText ( context , value , loc ) {
1254 if ( typeof value !== 'string' || hasOnlyLineBreak ( value ) ) { return }
@@ -52,6 +94,10 @@ function getComponentTemplateNode (value) {
5294
5395function create ( context ) {
5496 return defineTemplateBodyVisitor ( context , { // template block
97+ VExpressionContainer ( node ) {
98+ checkVExpressionContainerText ( context , node )
99+ } ,
100+
55101 VText ( node ) {
56102 checkRawText ( context , node . value , node . loc )
57103 }
@@ -65,6 +111,8 @@ function create (context) {
65111 enterNode ( node ) {
66112 if ( node . type === 'VText' ) {
67113 checkRawText ( context , node . value , valueNode . loc )
114+ } else if ( node . type === 'VExpressionContainer' ) {
115+ checkVExpressionContainerText ( context , node , valueNode )
68116 }
69117 } ,
70118 leaveNode ( ) { }
0 commit comments