Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/rules/indent.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,5 @@ This rule has an object option:
- `Attribute` (default: 1): Specifies the attribute indentation level. e.g. indent of 2 spaces with `Attribute` set to `2` will indent the attributes with `4` spaces (2 x 2).

- `tagChildrenIndent` (default: `{}`): Specifies the indent increment of the child tags of the specified tag. e.g. For example, `"tagChildrenIndent": { "html": 0 }` will set the `<html/>` tag children to 0 indent (2 x 0).

- `ignoreComment` (default: `false`): When set to `true`, the indentation of HTML comments (including opening `<!--`, closing `-->`, and content) will not be checked. This is useful when you want to allow free-form indentation for comments.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "node_modules/@lerna-lite/cli/schemas/lerna-schema.json",
"version": "0.47.1",
"version": "0.48.0",
"npmClient": "yarn",
"useWorkspaces": true,
"syncWorkspaceLock": true
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@html-eslint/cli",
"version": "0.47.1",
"version": "0.48.0",
"description": "HTML-ESLint CLI",
"author": "yeonjuan <yeonjuan93@naver.com>",
"homepage": "https://github.com/yeonjuan/html-eslint#readme",
Expand All @@ -23,8 +23,8 @@
"url": "https://github.com/yeonjuan/html-eslint/issues"
},
"dependencies": {
"@html-eslint/eslint-plugin": "^0.47.1",
"@html-eslint/parser": "^0.47.1",
"@html-eslint/eslint-plugin": "^0.48.0",
"@html-eslint/parser": "^0.48.0",
"axios": "^1.9.0",
"chalk": "^4.1.1",
"eslint": "^9.19.0",
Expand Down
85 changes: 49 additions & 36 deletions packages/eslint-plugin/lib/rules/indent/indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @typedef {Object} Option2
* @property {number} [Option2.Attribute]
* @property {Record<string, number>} [Option2.tagChildrenIndent]
* @property {boolean} [Option2.ignoreComment]
*/

const { parseTemplateLiteral } = require("../utils/template-literal");
Expand Down Expand Up @@ -97,6 +98,10 @@ module.exports = {
},
additionalProperties: false,
},
ignoreComment: {
type: "boolean",
default: false,
},
},
additionalProperties: false,
},
Expand All @@ -110,6 +115,7 @@ module.exports = {
const sourceCode = getSourceCode(context);
const indentLevelOptions = (context.options && context.options[1]) || {};
const lines = sourceCode.getLines();
const ignoreComment = indentLevelOptions.ignoreComment === true;
const { indentType, indentSize, indentChar } = getIndentOptionInfo(context);

/**
Expand Down Expand Up @@ -265,6 +271,48 @@ module.exports = {
}
}

/**
* @type {RuleListener}
*/
const commentVisitor = {
Comment(node) {
indentLevel.indent(node);
},
CommentOpen: checkIndent,
CommentContent(node) {
indentLevel.indent(node);
if (hasTemplate(node)) {
node.parts.forEach((part) => {
if (part.type !== NODE_TYPES.Part) {
if (part.open) {
checkIndent(part.open);
}
if (part.close) {
checkIndent(part.close);
}
}
});
}

const lineNodes = splitToLineNodes(node);
lineNodes.forEach((lineNode) => {
if (lineNode.hasTemplate) {
return;
}
if (lineNode.value.trim().length) {
checkIndent(lineNode);
}
});
},
CommentClose: checkIndent,
"Comment:exit"(node) {
indentLevel.dedent(node);
},
"CommentContent:exit"(node) {
indentLevel.dedent(node);
},
};

/**
* @type {RuleListener}
*/
Expand Down Expand Up @@ -342,42 +390,7 @@ module.exports = {
"Text:exit"(node) {
indentLevel.dedent(node);
},
Comment(node) {
indentLevel.indent(node);
},
CommentOpen: checkIndent,
CommentContent(node) {
indentLevel.indent(node);
if (hasTemplate(node)) {
node.parts.forEach((part) => {
if (part.type !== NODE_TYPES.Part) {
if (part.open) {
checkIndent(part.open);
}
if (part.close) {
checkIndent(part.close);
}
}
});
}

const lineNodes = splitToLineNodes(node);
lineNodes.forEach((lineNode) => {
if (lineNode.hasTemplate) {
return;
}
if (lineNode.value.trim().length) {
checkIndent(lineNode);
}
});
},
CommentClose: checkIndent,
"Comment:exit"(node) {
indentLevel.dedent(node);
},
"CommentContent:exit"(node) {
indentLevel.dedent(node);
},
...(ignoreComment ? {} : commentVisitor),
};
return visitor;
}
Expand Down
10 changes: 5 additions & 5 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@html-eslint/eslint-plugin",
"version": "0.47.1",
"version": "0.48.0",
"type": "commonjs",
"description": "ESLint plugin for HTML",
"author": "yeonjuan",
Expand Down Expand Up @@ -40,10 +40,10 @@
],
"dependencies": {
"@eslint/plugin-kit": "^0.3.1",
"@html-eslint/parser": "^0.47.1",
"@html-eslint/template-parser": "^0.47.1",
"@html-eslint/template-syntax-parser": "^0.47.1",
"@html-eslint/types": "^0.47.1"
"@html-eslint/parser": "^0.48.0",
"@html-eslint/template-parser": "^0.48.0",
"@html-eslint/template-syntax-parser": "^0.48.0",
"@html-eslint/types": "^0.48.0"
},
"peerDependencies": {
"eslint": "^8.0.0 || ^9.0.0"
Expand Down
61 changes: 61 additions & 0 deletions packages/eslint-plugin/tests/rules/indent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,40 @@ text
},
],
},
{
code: `
<div>
text
<!--
comment
<div></div>
-->
</div>
`,
options: [
2,
{
ignoreComment: true,
},
],
},
{
code: `
<div>
text
<!--
comment
<div></div>
-->
</div>
`,
options: [
2,
{
ignoreComment: true,
},
],
},
],
invalid: [
{
Expand Down Expand Up @@ -1409,6 +1443,33 @@ text
</div>
`,
},
{
code: `
<div>
text
<!--
comment
<div></div>
-->
</div>
`,
output: `
<div>
text
<!--
comment
<div></div>
-->
</div>
`,
options: [
2,
{
ignoreComment: false,
},
],
errors: wrongIndentErrors(2),
},
],
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/integration-test/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "integration-test",
"version": "0.47.0",
"version": "0.48.0",
"private": true,
"scripts": {
"test:integration": "jest --coverage --verbose"
Expand Down
6 changes: 3 additions & 3 deletions packages/parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@html-eslint/parser",
"version": "0.47.1",
"version": "0.48.0",
"description": "Parser for @html-eslint/eslint-plugin",
"author": "yeonjuan",
"homepage": "https://github.com/yeonjuan/html-eslint#readme",
Expand All @@ -27,8 +27,8 @@
"url": "https://github.com/yeonjuan/html-eslint/issues"
},
"dependencies": {
"@html-eslint/template-syntax-parser": "^0.47.1",
"@html-eslint/types": "^0.47.1",
"@html-eslint/template-syntax-parser": "^0.48.0",
"@html-eslint/types": "^0.48.0",
"es-html-parser": "0.3.1"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/template-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@html-eslint/template-parser",
"version": "0.47.1",
"version": "0.48.0",
"description": "HTML parser for template literals ",
"author": "yeonjuan",
"homepage": "https://github.com/yeonjuan/html-eslint#readme",
Expand Down Expand Up @@ -28,7 +28,7 @@
"url": "https://github.com/yeonjuan/html-eslint/issues"
},
"dependencies": {
"@html-eslint/types": "^0.47.1",
"@html-eslint/types": "^0.48.0",
"es-html-parser": "0.3.1"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/template-syntax-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@html-eslint/template-syntax-parser",
"version": "0.47.1",
"version": "0.48.0",
"description": "Parse template syntax",
"author": "yeonjuan",
"homepage": "https://github.com/yeonjuan/html-eslint#readme",
Expand Down Expand Up @@ -28,7 +28,7 @@
"url": "https://github.com/yeonjuan/html-eslint/issues"
},
"dependencies": {
"@html-eslint/types": "^0.47.1"
"@html-eslint/types": "^0.48.0"
},
"devDependencies": {
"eslint": "^9.19.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@html-eslint/types",
"version": "0.47.1",
"version": "0.48.0",
"description": "Types for @html-eslint/eslint-plugin",
"author": "yeonjuan",
"homepage": "https://github.com/yeonjuan/html-eslint#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/web-linter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@html-eslint/web-linter",
"version": "0.47.0",
"version": "0.48.0",
"description": "",
"private": true,
"main": "out/output.js",
Expand Down
8 changes: 4 additions & 4 deletions packages/website/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "website",
"version": "0.47.1",
"version": "0.48.0",
"private": true,
"scripts": {
"clear:cache": "rimraf ../../parcel-cache",
Expand All @@ -12,9 +12,9 @@
"sitemap": "node ./scripts/sitemap"
},
"dependencies": {
"@html-eslint/eslint-plugin": "^0.47.1",
"@html-eslint/parser": "^0.47.1",
"@html-eslint/web-linter": "^0.47.0",
"@html-eslint/eslint-plugin": "^0.48.0",
"@html-eslint/parser": "^0.48.0",
"@html-eslint/web-linter": "^0.48.0",
"@html-kit/html": "^0.0.4",
"codemirror": "^5.58.3"
},
Expand Down
Loading