@html-eslint/eslint-plugin
Advanced tools
Comparing version 0.7.3 to 0.8.0
@@ -0,4 +1,6 @@ | ||
// @ts-check | ||
/** | ||
* @typedef {import("../types").HTMLNode} HTMLNode | ||
* | ||
* @typedef {import("../types").AttrNode} AttrNode | ||
* @typedef {import("../types").BaseNode} BaseNode | ||
* @typedef {Object} IndentType | ||
@@ -70,3 +72,3 @@ * @property {"tab"} TAB | ||
/** | ||
* @param {HTMLNode} node | ||
* @param {BaseNode} node | ||
*/ | ||
@@ -80,3 +82,3 @@ function getLineCodeBefore(node) { | ||
/** | ||
* @param {HTMLNode} node | ||
* @param {BaseNode} node | ||
* @param {HTMLNode} [nodeToReport] | ||
@@ -127,3 +129,36 @@ */ | ||
} | ||
let ignoreChildren = false; | ||
/** | ||
* @param {AttrNode[]} attrs | ||
*/ | ||
function checkAttrsIndent(attrs) { | ||
attrs.forEach((attr) => checkIndent(attr)); | ||
} | ||
/** | ||
* @param {BaseNode} startTag | ||
*/ | ||
function checkEndOfStartTag(startTag) { | ||
const start = startTag.range[1] - 1; | ||
const end = startTag.range[1]; | ||
const line = startTag.loc.end.line; | ||
const endCol = startTag.loc.end.column; | ||
const startCol = startTag.loc.end.column - 1; | ||
checkIndent({ | ||
range: [start, end], | ||
start, | ||
end, | ||
loc: { | ||
start: { | ||
line, | ||
column: startCol, | ||
}, | ||
end: { | ||
line, | ||
column: endCol, | ||
}, | ||
}, | ||
}); | ||
} | ||
let nodesToIgnoreChildren = []; | ||
return { | ||
@@ -134,9 +169,16 @@ /** | ||
"*"(node) { | ||
if (IGNORING_NODES.includes(node.type) || ignoreChildren) { | ||
ignoreChildren = true; | ||
if (IGNORING_NODES.includes(node.type)) { | ||
nodesToIgnoreChildren.push(node); | ||
return; | ||
} | ||
if (nodesToIgnoreChildren.length) { | ||
return; | ||
} | ||
indentLevel.up(); | ||
if (Array.isArray(node.attrs)) { | ||
checkAttrsIndent(node.attrs); | ||
} | ||
(node.childNodes || []).forEach((current) => { | ||
@@ -166,10 +208,14 @@ if (current.startTag) { | ||
"*:exit"(node) { | ||
if (ignoreChildren) { | ||
if (IGNORING_NODES.includes(node.type)) { | ||
nodesToIgnoreChildren.pop(); | ||
return; | ||
} | ||
if (IGNORING_NODES.includes(node.type)) { | ||
ignoreChildren = false; | ||
if (nodesToIgnoreChildren.length) { | ||
return; | ||
} | ||
indentLevel.down(); | ||
if (node.startTag) { | ||
checkEndOfStartTag(node.startTag); | ||
} | ||
}, | ||
@@ -176,0 +222,0 @@ }; |
@@ -22,2 +22,3 @@ const requireLang = require("./require-lang"); | ||
const requireMetaViewport = require("./require-meta-viewport"); | ||
const requireMetaCharset = require("./require-meta-charset"); | ||
@@ -46,2 +47,3 @@ module.exports = { | ||
"require-meta-viewport": requireMetaViewport, | ||
"require-meta-charset": requireMetaCharset, | ||
}; |
@@ -16,3 +16,5 @@ // @ts-check | ||
return node | ||
? (node.attrs || []).find((attr) => attr.name === name) | ||
? (node.attrs || []).find( | ||
(attr) => attr.name.toLowerCase() === name.toLowerCase() | ||
) | ||
: undefined; | ||
@@ -19,0 +21,0 @@ }, |
@@ -23,2 +23,4 @@ export type RuleCategory = { | ||
interface BaseNode { | ||
start: number; | ||
end: number; | ||
range: [number, number]; | ||
@@ -39,4 +41,4 @@ loc: { | ||
childNodes?: HTMLNode[]; | ||
startTag: BaseNode | null; | ||
endTag: BaseNode | null; | ||
startTag?: BaseNode; | ||
endTag?: BaseNode; | ||
type: string; | ||
@@ -43,0 +45,0 @@ attrs?: AttrNode[]; |
{ | ||
"name": "@html-eslint/eslint-plugin", | ||
"version": "0.7.3", | ||
"version": "0.8.0", | ||
"description": "ESLint plugin for html", | ||
@@ -42,5 +42,5 @@ "author": "yeonjuan", | ||
"devDependencies": { | ||
"@html-eslint/parser": "^0.7.3" | ||
"@html-eslint/parser": "^0.8.0" | ||
}, | ||
"gitHead": "87d19ef8c2a61ca1018b89743587d6426607d208" | ||
"gitHead": "1b86f4c68af6b4a973e12bdfa205dfc28a239b20" | ||
} |
47206
37
1663