@@ -25,13 +25,41 @@ function calculateLoc (node, base = null) {
2525 }
2626}
2727
28+ function testValue ( value ) {
29+ return typeof value !== 'string' ||
30+ hasOnlyWhitespace ( value ) ||
31+ config . ignorePattern . test ( value . trim ( ) ) ||
32+ config . ignoreText . includes ( value . trim ( ) )
33+ }
34+
35+ // parent is directive (e.g <p v-xxx="..."></p>)
36+ function checkVAttributeDirective ( context , node , baseNode = null ) {
37+ const attrNode = node . parent
38+ if ( attrNode . key && attrNode . key . type === 'VDirectiveKey' ) {
39+ if ( ( attrNode . key . name === 'text' || attrNode . key . name . name === 'text' ) && node . expression . type === 'Literal' ) {
40+ const literalNode = node . expression
41+ const value = literalNode . value
42+
43+ if ( testValue ( value ) ) { return }
44+
45+ const loc = calculateLoc ( literalNode , baseNode )
46+ context . report ( {
47+ loc,
48+ message : `raw text '${ literalNode . value } ' is used`
49+ } )
50+ }
51+ }
52+ }
53+
2854function checkVExpressionContainerText ( context , node , baseNode = null ) {
2955 if ( ! node . expression ) { return }
3056
3157 if ( node . parent && node . parent . type === 'VElement' ) {
3258 // parent is element (e.g. <p>{{ ... }}</p>)
3359 if ( node . expression . type === 'Literal' ) {
3460 const literalNode = node . expression
61+ if ( testValue ( literalNode . value ) ) { return }
62+
3563 const loc = calculateLoc ( literalNode , baseNode )
3664 context . report ( {
3765 loc,
@@ -41,6 +69,8 @@ function checkVExpressionContainerText (context, node, baseNode = null) {
4169 const targets = [ node . expression . consequent , node . expression . alternate ]
4270 targets . forEach ( target => {
4371 if ( target . type === 'Literal' ) {
72+ if ( testValue ( target . value ) ) { return }
73+
4474 const loc = calculateLoc ( target , baseNode )
4575 context . report ( {
4676 loc,
@@ -50,27 +80,12 @@ function checkVExpressionContainerText (context, node, baseNode = null) {
5080 } )
5181 }
5282 } else if ( node . parent && node . parent . type === 'VAttribute' && node . parent . directive ) {
53- // parent is directive (e.g <p v-xxx="..."></p>)
54- const attrNode = node . parent
55- if ( attrNode . key && attrNode . key . type === 'VDirectiveKey' ) {
56- if ( ( attrNode . key . name === 'text' || attrNode . key . name . name === 'text' ) && node . expression . type === 'Literal' ) {
57- const literalNode = node . expression
58- const loc = calculateLoc ( literalNode , baseNode )
59- context . report ( {
60- loc,
61- message : `raw text '${ literalNode . value } ' is used`
62- } )
63- }
64- }
83+ checkVAttributeDirective ( context , node )
6584 }
6685}
6786
6887function checkRawText ( context , value , loc ) {
69- if ( typeof value !== 'string' || hasOnlyWhitespace ( value ) ) { return }
70-
71- if ( config . ignorePattern . test ( value . trim ( ) ) ) { return }
72-
73- if ( config . ignoreText . includes ( value . trim ( ) ) ) { return }
88+ if ( testValue ( value ) ) { return }
7489
7590 context . report ( {
7691 loc,
0 commit comments