@@ -125,26 +125,26 @@ function fixPropTypesSort(fixer, context, declarations, ignoreCase, requiredFirs
125
125
const node = allNodes [ i ] ;
126
126
let commentAfter = [ ] ;
127
127
let commentBefore = [ ] ;
128
+ let newStart = 0 ;
129
+ let newEnd = 0 ;
128
130
try {
129
131
commentBefore = sourceCode . getCommentsBefore ( node ) ;
130
132
commentAfter = sourceCode . getCommentsAfter ( node ) ;
131
133
} catch ( e ) { /**/ } ;
132
- if ( commentAfter . length === 0 && commentBefore . length === 0 ) {
133
- commentnodeMap . set ( node , { start : node . range [ 0 ] , end : node . range [ 1 ] , hasComment : false } ) ;
134
- } else {
135
- const firstCommentBefore = commentBefore [ 0 ] ;
136
- if ( commentBefore . length === 1 ) {
137
- commentnodeMap . set ( node , { start : firstCommentBefore . range [ 0 ] , end : node . range [ 1 ] , hasComment : true } ) ;
138
- }
139
- const firstCommentAfter = commentAfter [ 0 ] ;
140
- if ( commentAfter . length === 1 ) {
141
- commentnodeMap . set ( node , { start : node . range [ 0 ] , end : firstCommentAfter . range [ 1 ] , hasComment : true } ) ;
142
- }
143
- if ( commentBefore . length === 1 && commentAfter . length === 1 ) {
144
- commentnodeMap . set ( node , { start : firstCommentBefore . range [ 0 ] , end : firstCommentAfter . range [ 1 ] , hasComment : true } ) ;
145
- }
134
+ if ( commentAfter . length === 0 || commentBefore . length === 0 ) {
135
+ newStart = node . range [ 0 ]
136
+ newEnd = node . range [ 1 ]
137
+ }
138
+ const firstCommentBefore = commentBefore [ 0 ] ;
139
+ if ( commentBefore . length >= 1 ) {
140
+ newStart = firstCommentBefore . range [ 0 ]
141
+ }
142
+ const lastCommentAfter = commentAfter [ commentAfter . length - 1 ] ;
143
+ if ( commentAfter . length >= 1 ) {
144
+ newEnd = lastCommentAfter . range [ 1 ]
146
145
}
147
- } ;
146
+ commentnodeMap . set ( node , { start : newStart , end : newEnd , hasComment : true } ) ;
147
+ } ;
148
148
const nodeGroups = allNodes . reduce ( ( acc , curr ) => {
149
149
if ( curr . type === 'ExperimentalSpreadProperty' || curr . type === 'SpreadElement' ) {
150
150
acc . push ( [ ] ) ;
0 commit comments