File tree 1 file changed +20
-2
lines changed 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -228,7 +228,16 @@ module.exports = {
228
228
message : `There should be no space after '${ token . value } '` ,
229
229
fix : function ( fixer ) {
230
230
const nextToken = sourceCode . getTokenAfter ( token ) ;
231
- const nextComment = sourceCode . getCommentsAfter ( token ) ;
231
+ let nextComment ;
232
+
233
+ // ESLint >=4.x
234
+ if ( sourceCode . getCommentsAfter ) {
235
+ nextComment = sourceCode . getCommentsAfter ( token ) ;
236
+ // ESLint 3.x
237
+ } else {
238
+ const potentialComment = sourceCode . getTokenAfter ( token , { includeComments : true } ) ;
239
+ nextComment = nextToken === potentialComment ? [ ] : [ potentialComment ] ;
240
+ }
232
241
233
242
// Take comments into consideration to narrow the fix range to what is actually affected. (See #1414)
234
243
if ( nextComment . length > 0 ) {
@@ -253,7 +262,16 @@ module.exports = {
253
262
message : `There should be no space before '${ token . value } '` ,
254
263
fix : function ( fixer ) {
255
264
const previousToken = sourceCode . getTokenBefore ( token ) ;
256
- const previousComment = sourceCode . getCommentsBefore ( token ) ;
265
+ let previousComment ;
266
+
267
+ // ESLint >=4.x
268
+ if ( sourceCode . getCommentsBefore ) {
269
+ previousComment = sourceCode . getCommentsBefore ( token ) ;
270
+ // ESLint 3.x
271
+ } else {
272
+ const potentialComment = sourceCode . getTokenBefore ( token , { includeComments : true } ) ;
273
+ previousComment = previousToken === potentialComment ? [ ] : [ potentialComment ] ;
274
+ }
257
275
258
276
// Take comments into consideration to narrow the fix range to what is actually affected. (See #1414)
259
277
if ( previousComment . length > 0 ) {
You can’t perform that action at this time.
0 commit comments