1
- // @ts -nocheck
2
1
/**
3
2
* @fileoverview Enforce or disallow spaces inside of curly braces in JSX attributes.
4
3
* @author Jamund Ferguson
12
11
13
12
'use strict' ;
14
13
14
+ // @ts -ignore
15
15
const has = require ( 'object.hasown/polyfill' ) ( ) ;
16
16
const docsUrl = require ( '../util/docsUrl' ) ;
17
17
const report = require ( '../util/report' ) ;
@@ -373,7 +373,9 @@ module.exports = {
373
373
}
374
374
375
375
const sourceCode = context . getSourceCode ( ) ;
376
+ // @ts -expect-error The types differ between ASTNode and ESTree.Node.
376
377
const first = sourceCode . getFirstToken ( node ) ;
378
+ // @ts -expect-error The types differ between ASTNode and ESTree.Node.
377
379
const last = sourceCode . getLastToken ( node ) ;
378
380
let second = sourceCode . getTokenAfter ( first , { includeComments : true } ) ;
379
381
let penultimate = sourceCode . getTokenBefore ( last , { includeComments : true } ) ;
@@ -388,15 +390,21 @@ module.exports = {
388
390
const trailingComments = sourceCode . getNodeByRangeIndex ( penultimate . range [ 0 ] ) . trailingComments ;
389
391
penultimate = trailingComments ? trailingComments [ trailingComments . length - 1 ] : penultimate ;
390
392
}
393
+ if ( first . type !== 'Punctuator' || last . type !== 'Punctuator' ) {
394
+ return ;
395
+ }
391
396
392
397
const isObjectLiteral = first . value === second . value ;
393
398
const spacing = isObjectLiteral ? config . objectLiteralSpaces : config . when ;
394
399
if ( spacing === SPACING . always ) {
400
+ // @ts -expect-error second has a Comment type.
395
401
if ( ! sourceCode . isSpaceBetweenTokens ( first , second ) ) {
396
402
reportRequiredBeginningSpace ( node , first ) ;
397
- } else if ( ! config . allowMultiline && isMultiline ( first , second ) ) {
403
+ } else if ( ! config . allowMultiline && isMultiline ( first , second )
404
+ ) {
398
405
reportNoBeginningNewline ( node , first , spacing ) ;
399
406
}
407
+ // @ts -expect-error penultimate has a Comment type.
400
408
if ( ! sourceCode . isSpaceBetweenTokens ( penultimate , last ) ) {
401
409
reportRequiredEndingSpace ( node , last ) ;
402
410
} else if ( ! config . allowMultiline && isMultiline ( penultimate , last ) ) {
@@ -407,13 +415,16 @@ module.exports = {
407
415
if ( ! config . allowMultiline ) {
408
416
reportNoBeginningNewline ( node , first , spacing ) ;
409
417
}
418
+ // @ts -expect-error second has a Comment type.
410
419
} else if ( sourceCode . isSpaceBetweenTokens ( first , second ) ) {
411
420
reportNoBeginningSpace ( node , first ) ;
412
421
}
413
422
if ( isMultiline ( penultimate , last ) ) {
414
- if ( ! config . allowMultiline ) {
415
- reportNoEndingNewline ( node , last , spacing ) ;
423
+ if ( config . allowMultiline ) {
424
+ return ;
416
425
}
426
+ reportNoEndingNewline ( node , last , spacing ) ;
427
+ // @ts -expect-error penultimate has a Comment type.
417
428
} else if ( sourceCode . isSpaceBetweenTokens ( penultimate , last ) ) {
418
429
reportNoEndingSpace ( node , last ) ;
419
430
}
0 commit comments