@@ -70,7 +70,8 @@ module.exports = {
70
70
config . allowedStrings = new Set ( config . allowedStrings . map ( trimIfString ) ) ;
71
71
72
72
function defaultMessageId ( ) {
73
- if ( config . noAttributeStrings ) {
73
+ const ancestorIsJSXElement = arguments . length >= 1 && arguments [ 0 ] ;
74
+ if ( config . noAttributeStrings && ! ancestorIsJSXElement ) {
74
75
return 'noStringsInAttributes' ;
75
76
}
76
77
if ( config . noStrings ) {
@@ -79,17 +80,6 @@ module.exports = {
79
80
return 'literalNotInJSXExpression' ;
80
81
}
81
82
82
- function reportLiteralNode ( node , messageId ) {
83
- messageId = messageId || defaultMessageId ( ) ;
84
-
85
- report ( context , messages [ messageId ] , messageId , {
86
- node,
87
- data : {
88
- text : context . getSourceCode ( ) . getText ( node ) . trim ( ) ,
89
- } ,
90
- } ) ;
91
- }
92
-
93
83
function getParentIgnoringBinaryExpressions ( node ) {
94
84
let current = node ;
95
85
while ( current . parent . type === 'BinaryExpression' ) {
@@ -107,7 +97,7 @@ module.exports = {
107
97
function isParentNodeStandard ( ) {
108
98
if ( ! / ^ [ \s ] + $ / . test ( node . value ) && typeof node . value === 'string' && parent . type . includes ( 'JSX' ) ) {
109
99
if ( config . noAttributeStrings ) {
110
- return parent . type === 'JSXAttribute' ;
100
+ return parent . type === 'JSXAttribute' || parent . type === 'JSXElement' ;
111
101
}
112
102
if ( ! config . noAttributeStrings ) {
113
103
return parent . type !== 'JSXAttribute' ;
@@ -146,6 +136,18 @@ module.exports = {
146
136
return parentType === 'JSXFragment' || parentType === 'JSXElement' || grandParentType === 'JSXElement' ;
147
137
}
148
138
139
+ function reportLiteralNode ( node , messageId ) {
140
+ const ancestorIsJSXElement = hasJSXElementParentOrGrandParent ( node ) ;
141
+ messageId = messageId || defaultMessageId ( ancestorIsJSXElement ) ;
142
+
143
+ report ( context , messages [ messageId ] , messageId , {
144
+ node,
145
+ data : {
146
+ text : context . getSourceCode ( ) . getText ( node ) . trim ( ) ,
147
+ } ,
148
+ } ) ;
149
+ }
150
+
149
151
// --------------------------------------------------------------------------
150
152
// Public
151
153
// --------------------------------------------------------------------------
0 commit comments