@html-eslint/eslint-plugin
Advanced tools
Comparing version 0.6.0 to 0.6.1
@@ -26,3 +26,3 @@ const { RULE_CATEGORY } = require("../constants"); | ||
create(context) { | ||
const IdNodesMap = new Map(); | ||
const IdAttrsMap = new Map(); | ||
return { | ||
@@ -32,15 +32,15 @@ "*"(node) { | ||
if (idAttr) { | ||
if (!IdNodesMap.has(idAttr.value)) { | ||
IdNodesMap.set(idAttr.value, []); | ||
if (!IdAttrsMap.has(idAttr.value)) { | ||
IdAttrsMap.set(idAttr.value, []); | ||
} | ||
const nodes = IdNodesMap.get(idAttr.value); | ||
nodes.push(node); | ||
const nodes = IdAttrsMap.get(idAttr.value); | ||
nodes.push(idAttr); | ||
} | ||
}, | ||
"Program:exit"() { | ||
IdNodesMap.forEach((nodes) => { | ||
if (Array.isArray(nodes) && nodes.length > 1) { | ||
nodes.forEach((node) => { | ||
IdAttrsMap.forEach((attrs) => { | ||
if (Array.isArray(attrs) && attrs.length > 1) { | ||
attrs.forEach((attr) => { | ||
context.report({ | ||
node: node.startTag, | ||
node: attr, | ||
messageId: MESSAGE_IDS.DUPLICATE_ID, | ||
@@ -47,0 +47,0 @@ }); |
@@ -62,4 +62,4 @@ const { RULE_CATEGORY } = require("../constants"); | ||
loc: { | ||
start: startTag.loc.end.column, | ||
end: lastAttr.loc.end.column, | ||
start: lastAttr.loc.end, | ||
end: startTag.loc.end, | ||
}, | ||
@@ -66,0 +66,0 @@ messageId: MESSAGE_IDS.EXTRA_AFTER, |
@@ -53,3 +53,5 @@ const { RULE_CATEGORY } = require("../constants"); | ||
function getValueRange(attr) { | ||
return [attr.range[1] - (attr.value.length + 2), attr.range[1]]; | ||
const attrCode = getCodeIn(attr.range); | ||
const [matched = ""] = attrCode.match(/\S*?\s*=\s*/) || []; | ||
return [attr.range[0] + matched.length, attr.range[1]]; | ||
} | ||
@@ -85,5 +87,8 @@ | ||
const range = getValueRange(attr); | ||
const originCode = getCodeIn(range); | ||
const onlyValue = originCode.slice(1, originCode.length - 1); | ||
return fixer.replaceTextRange( | ||
range, | ||
`${expectedQuote}${attr.value}${expectedQuote}` | ||
`${expectedQuote}${onlyValue}${expectedQuote}` | ||
); | ||
@@ -101,6 +106,7 @@ }, | ||
fix(fixer) { | ||
const [valueStart, valueEnd] = getValueRange(attr); | ||
const range = getValueRange(attr); | ||
const originCode = getCodeIn(range); | ||
return fixer.replaceTextRange( | ||
[valueStart + 2, valueEnd], | ||
`${expectedQuote}${attr.value}${expectedQuote}` | ||
range, | ||
`${expectedQuote}${originCode}${expectedQuote}` | ||
); | ||
@@ -107,0 +113,0 @@ }, |
{ | ||
"name": "@html-eslint/eslint-plugin", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "ESLint plugin for html", | ||
@@ -44,3 +44,3 @@ "author": "yeonjuan", | ||
}, | ||
"gitHead": "557303eeba0177eadc1d3213a874f68d31209cd8" | ||
"gitHead": "373375254f7f8f1232fe9ae1ef0469444deb64dd" | ||
} |
40337
1470