@html-eslint/eslint-plugin
Advanced tools
Comparing version 0.24.1 to 0.25.0
@@ -9,2 +9,3 @@ module.exports = { | ||
"@html-eslint/no-extra-spacing-attrs": "error", | ||
"@html-eslint/attrs-newline": "error", | ||
"@html-eslint/element-newline": "error", | ||
@@ -11,0 +12,0 @@ "@html-eslint/no-duplicate-id": "error", |
@@ -9,2 +9,3 @@ const requireLang = require("./require-lang"); | ||
const noExtraSpacingAttrs = require("./no-extra-spacing-attrs"); | ||
const attrsNewline = require("./attrs-newline"); | ||
const elementNewLine = require("./element-newline"); | ||
@@ -49,2 +50,3 @@ const noSkipHeadingLevels = require("./no-skip-heading-levels"); | ||
"no-extra-spacing-attrs": noExtraSpacingAttrs, | ||
"attrs-newline": attrsNewline, | ||
"element-newline": elementNewLine, | ||
@@ -51,0 +53,0 @@ "no-skip-heading-levels": noSkipHeadingLevels, |
@@ -37,4 +37,7 @@ /** | ||
}, | ||
allowSelfClosingCustom: { | ||
type: "boolean", | ||
selfClosingCustomPatterns: { | ||
type: "array", | ||
items: { | ||
type: "string", | ||
}, | ||
}, | ||
@@ -53,10 +56,17 @@ }, | ||
create(context) { | ||
const shouldSelfClose = | ||
/** @type {string[]} */ | ||
const foreignContext = []; | ||
const shouldSelfCloseVoid = | ||
context.options && context.options.length | ||
? context.options[0].selfClosing === "always" | ||
: false; | ||
const allowSelfClosingCustom = | ||
context.options && context.options.length | ||
? context.options[0].allowSelfClosingCustom === true | ||
: false; | ||
/** @type {string[]} */ | ||
const selfClosingCustomPatternsOption = | ||
(context.options && | ||
context.options.length && | ||
context.options[0].selfClosingCustomPatterns) || | ||
[]; | ||
const selfClosingCustomPatterns = selfClosingCustomPatternsOption.map( | ||
(i) => new RegExp(i) | ||
); | ||
@@ -96,3 +106,6 @@ /** | ||
} | ||
return fixer.replaceText(node.openEnd, " />"); | ||
const fixes = []; | ||
fixes.push(fixer.replaceText(node.openEnd, " />")); | ||
if (node.close) fixes.push(fixer.remove(node.close)); | ||
return fixes; | ||
}, | ||
@@ -121,16 +134,32 @@ }); | ||
const isVoidElement = VOID_ELEMENTS_SET.has(node.name); | ||
if ( | ||
node.selfClosing && | ||
allowSelfClosingCustom && | ||
node.name.indexOf("-") !== -1 | ||
) { | ||
checkVoidElement(node, true, false); | ||
} else if (node.selfClosing || isVoidElement) { | ||
checkVoidElement(node, shouldSelfClose, isVoidElement); | ||
const isSelfClosingCustomElement = !!selfClosingCustomPatterns.some( | ||
(i) => node.name.match(i) | ||
); | ||
const isForeign = foreignContext.length > 0; | ||
const shouldSelfCloseCustom = | ||
isSelfClosingCustomElement && !node.children.length; | ||
const shouldSelfCloseForeign = node.selfClosing; | ||
const shouldSelfClose = | ||
(isVoidElement && shouldSelfCloseVoid) || | ||
(isSelfClosingCustomElement && shouldSelfCloseCustom) || | ||
(isForeign && shouldSelfCloseForeign); | ||
const canSelfClose = | ||
isVoidElement || isSelfClosingCustomElement || isForeign; | ||
if (node.selfClosing || canSelfClose) { | ||
checkVoidElement(node, shouldSelfClose, canSelfClose); | ||
} else if (node.openEnd.value !== "/>") { | ||
checkClosingTag(node); | ||
} | ||
if (["svg", "math"].includes(node.name)) foreignContext.push(node.name); | ||
}, | ||
/** | ||
* @param {TagNode} node | ||
*/ | ||
"Tag:exit"(node) { | ||
if (node.name === foreignContext[foreignContext.length - 1]) { | ||
foreignContext.pop(); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
{ | ||
"name": "@html-eslint/eslint-plugin", | ||
"version": "0.24.1", | ||
"version": "0.25.0", | ||
"description": "ESLint plugin for html", | ||
@@ -48,3 +48,3 @@ "author": "yeonjuan", | ||
"devDependencies": { | ||
"@html-eslint/parser": "^0.24.1", | ||
"@html-eslint/parser": "^0.25.0", | ||
"@types/eslint": "^8.56.2", | ||
@@ -55,3 +55,3 @@ "@types/estree": "^0.0.47", | ||
}, | ||
"gitHead": "c9095f0738fea1688099937ebc0a93b1a26b7da9" | ||
"gitHead": "315631a66e9c626655c243ccb6a46319736383cf" | ||
} |
122096
76
4115