Skip to content

Commit 92ea22d

Browse files
fix: fixing code structure
1 parent e28bd3e commit 92ea22d

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

lib/rules/no-invalid-html-attribute.js

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,21 @@ const fixMessages = {
247247
removeWhitespaces: 'remove whitespaces in “{{reportingValue}}”',
248248
}
249249

250+
function fix (fixer, mode, ...args) {
251+
if (mode === 'removeTextRange') {
252+
return fixer.replaceTextRange(args)
253+
}
254+
if (mode === 'removeRange') {
255+
return fixer.removeRange(args)
256+
}
257+
return fixer.remove(args)
258+
}
259+
260+
function suggestion(desc, mode, ...args) {
261+
return {desc: desc, ...fix(mode, args)}
262+
}
263+
264+
250265
function splitIntoRangedParts(node, regex) {
251266
const valueRangeStart = node.range[0] + 1; // the plus one is for the initial quote
252267

@@ -267,7 +282,7 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN
267282
report(context, messages.onlyStrings, 'onlyStrings', {
268283
node,
269284
data: { attributeName },
270-
suggestion(fixMessages.removeNonString, fixer, fixModes.remove, parentNode)
285+
suggestion :suggestion(fixMessages.removeNonString,fixModes.remove, parentNode)
271286
});
272287
return;
273288
}
@@ -276,7 +291,7 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN
276291
report(context, messages.noEmpty, 'noEmpty', {
277292
node,
278293
data: { attributeName },
279-
suggestion(fixMessages.removeEmpty, fixer, fixModes.remove, attributeName)
294+
suggestion :suggestion(fixMessages.removeEmpty, fixModes.remove, attributeName)
280295
});
281296
return;
282297
}
@@ -292,7 +307,7 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN
292307
attributeName,
293308
reportingValue,
294309
},
295-
suggestion(fixMessages.removeInvalid, fixer, fixModes.removeRange, singlePart.range)
310+
suggestion :suggestion(fixMessages.removeInvalid, fixModes.removeRange, singlePart.range)
296311
});
297312
} else if (!allowedTags.has(parentNodeName)) {
298313
report(context, messages.notValidFor, 'notValidFor', {
@@ -302,7 +317,7 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN
302317
reportingValue,
303318
elementName: parentNodeName,
304319
},
305-
suggestion(fixMessages.removeInvalid, fixer, fixModes.removeRange, singlePart.range)
320+
suggestion :suggestion(fixMessages.removeInvalid, fixModes.removeRange, singlePart.range)
306321
});
307322
}
308323
}
@@ -342,13 +357,13 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN
342357
report(context, messages.spaceDelimited, 'spaceDelimited', {
343358
node,
344359
data: { attributeName },
345-
suggestion(fixMessages.removeWhitespaces, fixer, fixModes.removeRange, whitespacePart.range)
360+
suggestion :suggestion(fixMessages.removeWhitespaces, fixModes.removeRange, whitespacePart.range)
346361
});
347362
} else if (whitespacePart.value !== '\u0020') {
348363
report(context, messages.spaceDelimited, 'spaceDelimited', {
349364
node,
350365
data: { attributeName },
351-
suggestion(fixMessages.removeWhitespaces, fixer, mofixModes.replaceTextRange, whitespacePart.range, '\u0020' )
366+
suggestion :suggestion(fixMessages.removeWhitespaces, fixModes.replaceTextRange, whitespacePart.range, '\u0020' )
352367
});
353368
}
354369
}
@@ -359,25 +374,7 @@ const DEFAULT_ATTRIBUTES = ['rel'];
359374
function checkAttribute(context, node) {
360375
const attribute = node.name.name;
361376

362-
function fix(fixer, mode, ...args) {
363-
if (mode === 'removeTextRange') {
364-
return fixer.replaceTextRange(args)
365-
}
366-
if (mode === 'removeRange') {
367-
return fixer.removeRange(args)
368-
}
369-
return fixer.remove(args)
370-
}
371-
372-
function suggestion(desc, fixer, mode, ...args) {
373-
return [
374-
{
375-
desc: desc,
376-
fix(fixer, mode, args)
377-
}
378-
]
379-
}
380-
377+
381378
const parentNodeName = node.parent.name.name;
382379
if (!COMPONENT_ATTRIBUTE_MAP.has(attribute) || !COMPONENT_ATTRIBUTE_MAP.get(attribute).has(parentNodeName)) {
383380
const tagNames = Array.from(
@@ -390,7 +387,7 @@ function checkAttribute(context, node) {
390387
attributeName: attribute,
391388
tagNames,
392389
},
393-
suggestion(fixMessages.removeDefault, fixer, fixModes.remove, attributeName)
390+
suggestion :suggestion(fixMessages.removeDefault, fixModes.remove, attribute)
394391
});
395392
return;
396393
}
@@ -399,7 +396,7 @@ function checkAttribute(context, node) {
399396
report(context, messages.emptyIsMeaningless, 'emptyIsMeaningless', {
400397
node,
401398
data: { attributeName: attribute },
402-
suggestion(fixMessages.removeEmpty, fixer, fixModes.removemode, attributeName)
399+
suggestion :suggestion(fixMessages.removeEmpty, fixModes.removemode, node)
403400
});
404401
return;
405402
}
@@ -420,7 +417,7 @@ function checkAttribute(context, node) {
420417
report(context, messages.onlyStrings, 'onlyStrings', {
421418
node,
422419
data: { attributeName: attribute },
423-
suggestion(fixMessages.removeDefault, fixer, fixModes.remove, attributeName)
420+
suggestion :suggestion(fixMessages.removeDefault, fixModes.remove, node)
424421
});
425422
return;
426423
}
@@ -429,7 +426,7 @@ function checkAttribute(context, node) {
429426
report(context, messages.onlyStrings, 'onlyStrings', {
430427
node,
431428
data: { attributeName: attribute },
432-
suggestion(fixMessages.removeDefault fixer, fixModes.remove, attributeName)
429+
suggestion :suggestion(fixMessages.removeDefault, fixModes.remove, node)
433430
});
434431
}
435432
}

0 commit comments

Comments
 (0)