@@ -25,13 +25,41 @@ function calculateLoc (node, base = null) {
25
25
}
26
26
}
27
27
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
+
28
54
function checkVExpressionContainerText ( context , node , baseNode = null ) {
29
55
if ( ! node . expression ) { return }
30
56
31
57
if ( node . parent && node . parent . type === 'VElement' ) {
32
58
// parent is element (e.g. <p>{{ ... }}</p>)
33
59
if ( node . expression . type === 'Literal' ) {
34
60
const literalNode = node . expression
61
+ if ( testValue ( literalNode . value ) ) { return }
62
+
35
63
const loc = calculateLoc ( literalNode , baseNode )
36
64
context . report ( {
37
65
loc,
@@ -41,6 +69,8 @@ function checkVExpressionContainerText (context, node, baseNode = null) {
41
69
const targets = [ node . expression . consequent , node . expression . alternate ]
42
70
targets . forEach ( target => {
43
71
if ( target . type === 'Literal' ) {
72
+ if ( testValue ( target . value ) ) { return }
73
+
44
74
const loc = calculateLoc ( target , baseNode )
45
75
context . report ( {
46
76
loc,
@@ -50,27 +80,12 @@ function checkVExpressionContainerText (context, node, baseNode = null) {
50
80
} )
51
81
}
52
82
} 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 )
65
84
}
66
85
}
67
86
68
87
function 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 }
74
89
75
90
context . report ( {
76
91
loc,
0 commit comments