@@ -234,6 +234,21 @@ const messages = {
234
234
spaceDelimited : '”{{attributeName}}“ attribute values should be space delimited.' ,
235
235
} ;
236
236
237
+ const fixModes = {
238
+ remove : 'remove' ,
239
+ replaceTextRange : 'removeTextRange' ,
240
+ removeRange : 'removeRange'
241
+ }
242
+
243
+ const fixMessages = {
244
+ removeDefault : '"remove {{attributeName}}"' ,
245
+ removeEmpty :'"remove empty attribute {{attributeName}}"' ,
246
+ removeInvalid : '“remove invalid attribute {{reportingValue}}”' ,
247
+ removeWhitespaces : 'remove whitespaces in “{{reportingValue}}”' ,
248
+
249
+
250
+ }
251
+
237
252
function splitIntoRangedParts ( node , regex ) {
238
253
const valueRangeStart = node . range [ 0 ] + 1 ; // the plus one is for the initial quote
239
254
@@ -254,14 +269,7 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN
254
269
report ( context , messages . onlyStrings , 'onlyStrings' , {
255
270
node,
256
271
data : { attributeName } ,
257
- suggest : [
258
- {
259
- desc : "To Be Replaced By Appropriate Message" ,
260
- fix : function ( fixer ) {
261
- return fixer . remove ( parentNode ) ;
262
- }
263
- }
264
- ]
272
+ suggestion ( fixMessages . removeNonString , fixer , fixModes . remove , parentNode )
265
273
} ) ;
266
274
return ;
267
275
}
@@ -270,14 +278,7 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN
270
278
report ( context , messages . noEmpty , 'noEmpty' , {
271
279
node,
272
280
data : { attributeName } ,
273
- suggest : [
274
- {
275
- desc : "To Be Replaced By Appropriate Message" ,
276
- fix : function ( fixer ) {
277
- return fixer . remove ( parentNode ) ;
278
- }
279
- }
280
- ]
281
+ suggestion ( fixMessages . removeEmpty , fixer , fixModes . remove , attributeName )
281
282
} ) ;
282
283
return ;
283
284
}
@@ -293,14 +294,7 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN
293
294
attributeName,
294
295
reportingValue,
295
296
} ,
296
- suggest : [
297
- {
298
- desc : "To Be Replaced By Appropriate Message" ,
299
- fix : function ( fixer ) {
300
- return fixer . removeRange ( singlePart . range ) ;
301
- }
302
- }
303
- ]
297
+ suggestion ( fixMessages . removeInvalid , fixer , fixModes . removeRange , singlePart . range )
304
298
} ) ;
305
299
} else if ( ! allowedTags . has ( parentNodeName ) ) {
306
300
report ( context , messages . notValidFor , 'notValidFor' , {
@@ -310,14 +304,7 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN
310
304
reportingValue,
311
305
elementName : parentNodeName ,
312
306
} ,
313
- suggest : [
314
- {
315
- desc : "To Be Replaced By Appropriate Message" ,
316
- fix : function ( fixer ) {
317
- return fixer . removeRange ( singlePart . range ) ;
318
- }
319
- }
320
- ]
307
+ suggestion ( fixMessages . removeInvalid , fixer , fixModes . removeRange , singlePart . range )
321
308
} ) ;
322
309
}
323
310
}
@@ -357,27 +344,13 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN
357
344
report ( context , messages . spaceDelimited , 'spaceDelimited' , {
358
345
node,
359
346
data : { attributeName } ,
360
- suggest : [
361
- {
362
- desc : "To Be Replaced By Appropriate Message" ,
363
- fix : function ( fixer ) {
364
- return fixer . removeRange ( whitespacePart . range ) ;
365
- }
366
- }
367
- ]
347
+ suggestion ( fixMessages . removeWhitespaces , fixer , fixModes . removeRange , whitespacePart . range )
368
348
} ) ;
369
349
} else if ( whitespacePart . value !== '\u0020' ) {
370
350
report ( context , messages . spaceDelimited , 'spaceDelimited' , {
371
351
node ,
372
352
data : { attributeName } ,
373
- suggest : [
374
- {
375
- desc : "To Be Replaced By Appropriate Message" ,
376
- fix : function ( fixer ) {
377
- return fixer . removeRange ( whitespacePart . range , '\u0020' ) ;
378
- }
379
- }
380
- ]
353
+ suggestion ( fixMessages . removeWhitespaces , fixer , mofixModes . replaceTextRange , whitespacePart . range , '\u0020' )
381
354
} ) ;
382
355
}
383
356
}
@@ -388,17 +361,23 @@ const DEFAULT_ATTRIBUTES = ['rel'];
388
361
function checkAttribute ( context , node ) {
389
362
const attribute = node . name . name ;
390
363
391
- function fix ( fixer ) {
392
- return fixer . remove ( node ) ;
364
+ function fix ( fixer , mode , ...args ) {
365
+ if ( mode === 'removeTextRange' ) {
366
+ return fixer . replaceTextRange ( args )
367
+ }
368
+ else if ( mode === 'removeRange' ) {
369
+ return fixer . removeRange ( args )
370
+ }
371
+ else {
372
+ return fixer . remove ( args )
373
+ }
393
374
}
394
375
395
- function suggestion ( desc , fixer ) {
376
+ function suggestion ( desc , fixer , mode , ... args ) {
396
377
return [
397
378
{
398
- desc : desc ,
399
- fix : function ( fixer ) {
400
- return fixer . remove ( node ) ;
401
- }
379
+ desc : desc ,
380
+ fix ( fixer , mode , args )
402
381
}
403
382
]
404
383
}
@@ -415,7 +394,7 @@ function checkAttribute(context, node) {
415
394
attributeName : attribute ,
416
395
tagNames,
417
396
} ,
418
- suggest : suggestion ( "hehe" ) ,
397
+ suggestion ( fixMessages . removeDefault , fixer , fixModes . remove , attributeName )
419
398
} ) ;
420
399
return ;
421
400
}
@@ -424,7 +403,7 @@ function checkAttribute(context, node) {
424
403
report ( context , messages . emptyIsMeaningless , 'emptyIsMeaningless' , {
425
404
node,
426
405
data : { attributeName : attribute } ,
427
- suggest : suggestion ( "hehe" ) ,
406
+ suggestion ( fixMessages . removeEmpty , fixer , fixModes . removemode , attributeName )
428
407
} ) ;
429
408
return ;
430
409
}
@@ -445,7 +424,7 @@ function checkAttribute(context, node) {
445
424
report ( context , messages . onlyStrings , 'onlyStrings' , {
446
425
node,
447
426
data : { attributeName : attribute } ,
448
- suggest : suggestion ( "hehe" ) ,
427
+ suggestion ( fixMessages . removeDefault , fixer , fixModes . remove , attributeName )
449
428
} ) ;
450
429
return ;
451
430
}
@@ -454,7 +433,7 @@ function checkAttribute(context, node) {
454
433
report ( context , messages . onlyStrings , 'onlyStrings' , {
455
434
node,
456
435
data : { attributeName : attribute } ,
457
- suggest : suggestion ( "hehe" ) ,
436
+ suggestion ( fixMessages . removeDefault fixer , fixModes . remove , attributeName )
458
437
} ) ;
459
438
}
460
439
}
0 commit comments