6
6
'use strict' ;
7
7
8
8
const docsUrl = require ( '../util/docsUrl' ) ;
9
+ const jsxUtil = require ( '../util/jsx' ) ;
9
10
10
11
// ------------------------------------------------------------------------------
11
12
// Constants
@@ -168,13 +169,12 @@ module.exports = {
168
169
function lintUnnecessaryCurly ( JSXExpressionNode ) {
169
170
const expression = JSXExpressionNode . expression ;
170
171
const expressionType = expression . type ;
171
- const parentType = JSXExpressionNode . parent . type ;
172
172
173
173
if (
174
174
( expressionType === 'Literal' || expressionType === 'JSXText' ) &&
175
175
typeof expression . value === 'string' &&
176
176
! needToEscapeCharacterForJSX ( expression . raw ) && (
177
- parentType === 'JSXElement' ||
177
+ jsxUtil . isJSX ( JSXExpressionNode . parent ) ||
178
178
! containsQuoteCharacters ( expression . value )
179
179
)
180
180
) {
@@ -183,32 +183,30 @@ module.exports = {
183
183
expressionType === 'TemplateLiteral' &&
184
184
expression . expressions . length === 0 &&
185
185
! needToEscapeCharacterForJSX ( expression . quasis [ 0 ] . value . raw ) && (
186
- parentType === 'JSXElement' ||
186
+ jsxUtil . isJSX ( JSXExpressionNode . parent ) ||
187
187
! containsQuoteCharacters ( expression . quasis [ 0 ] . value . cooked )
188
188
)
189
189
) {
190
190
reportUnnecessaryCurly ( JSXExpressionNode ) ;
191
191
}
192
192
}
193
193
194
- function areRuleConditionsSatisfied ( parentType , config , ruleCondition ) {
194
+ function areRuleConditionsSatisfied ( parent , config , ruleCondition ) {
195
195
return (
196
- parentType === 'JSXAttribute' &&
196
+ parent . type === 'JSXAttribute' &&
197
197
typeof config . props === 'string' &&
198
198
config . props === ruleCondition
199
199
) || (
200
- parentType === 'JSXElement' &&
200
+ jsxUtil . isJSX ( parent ) &&
201
201
typeof config . children === 'string' &&
202
202
config . children === ruleCondition
203
203
) ;
204
204
}
205
205
206
206
function shouldCheckForUnnecessaryCurly ( parent , config ) {
207
- const parentType = parent . type ;
208
-
209
207
// If there are more than one JSX child, there is no need to check for
210
208
// unnecessary curly braces.
211
- if ( parentType === 'JSXElement' && parent . children . length !== 1 ) {
209
+ if ( jsxUtil . isJSX ( parent ) && parent . children . length !== 1 ) {
212
210
return false ;
213
211
}
214
212
@@ -220,7 +218,7 @@ module.exports = {
220
218
return false ;
221
219
}
222
220
223
- return areRuleConditionsSatisfied ( parentType , config , OPTION_NEVER ) ;
221
+ return areRuleConditionsSatisfied ( parent , config , OPTION_NEVER ) ;
224
222
}
225
223
226
224
function shouldCheckForMissingCurly ( parent , config ) {
@@ -232,7 +230,7 @@ module.exports = {
232
230
return false ;
233
231
}
234
232
235
- return areRuleConditionsSatisfied ( parent . type , config , OPTION_ALWAYS ) ;
233
+ return areRuleConditionsSatisfied ( parent , config , OPTION_ALWAYS ) ;
236
234
}
237
235
238
236
// --------------------------------------------------------------------------
0 commit comments