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