diff --git a/docs/rules/indent.md b/docs/rules/indent.md
index c46053c6..7e9bde25 100644
--- a/docs/rules/indent.md
+++ b/docs/rules/indent.md
@@ -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 `
` tag children to 0 indent (2 x 0).
+
+- `ignoreComment` (default: `false`): When set to `true`, the indentation of HTML comments (including opening ``, and content) will not be checked. This is useful when you want to allow free-form indentation for comments.
diff --git a/lerna.json b/lerna.json
index f2abd472..8f2b63cf 100644
--- a/lerna.json
+++ b/lerna.json
@@ -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
diff --git a/packages/cli/package.json b/packages/cli/package.json
index 774fbf16..aef2e2e4 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@html-eslint/cli",
- "version": "0.47.1",
+ "version": "0.48.0",
"description": "HTML-ESLint CLI",
"author": "yeonjuan ",
"homepage": "https://github.com/yeonjuan/html-eslint#readme",
@@ -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",
diff --git a/packages/eslint-plugin/lib/rules/indent/indent.js b/packages/eslint-plugin/lib/rules/indent/indent.js
index 13da640d..0f8ff3d5 100644
--- a/packages/eslint-plugin/lib/rules/indent/indent.js
+++ b/packages/eslint-plugin/lib/rules/indent/indent.js
@@ -18,6 +18,7 @@
* @typedef {Object} Option2
* @property {number} [Option2.Attribute]
* @property {Record} [Option2.tagChildrenIndent]
+ * @property {boolean} [Option2.ignoreComment]
*/
const { parseTemplateLiteral } = require("../utils/template-literal");
@@ -97,6 +98,10 @@ module.exports = {
},
additionalProperties: false,
},
+ ignoreComment: {
+ type: "boolean",
+ default: false,
+ },
},
additionalProperties: false,
},
@@ -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);
/**
@@ -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}
*/
@@ -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;
}
diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json
index a41bc76e..93bf7349 100644
--- a/packages/eslint-plugin/package.json
+++ b/packages/eslint-plugin/package.json
@@ -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",
@@ -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"
diff --git a/packages/eslint-plugin/tests/rules/indent.test.js b/packages/eslint-plugin/tests/rules/indent.test.js
index 9d1af6fe..ce8f6fab 100644
--- a/packages/eslint-plugin/tests/rules/indent.test.js
+++ b/packages/eslint-plugin/tests/rules/indent.test.js
@@ -519,6 +519,40 @@ text
},
],
},
+ {
+ code: `
+
+ text
+
+
+ `,
+ options: [
+ 2,
+ {
+ ignoreComment: true,
+ },
+ ],
+ },
+ {
+ code: `
+
+ text
+
+
+ `,
+ options: [
+ 2,
+ {
+ ignoreComment: true,
+ },
+ ],
+ },
],
invalid: [
{
@@ -1409,6 +1443,33 @@ text
`,
},
+ {
+ code: `
+
+ text
+
+
+ `,
+ output: `
+
+ text
+
+
+ `,
+ options: [
+ 2,
+ {
+ ignoreComment: false,
+ },
+ ],
+ errors: wrongIndentErrors(2),
+ },
],
};
}
diff --git a/packages/integration-test/package.json b/packages/integration-test/package.json
index 4af53c13..df96b63f 100644
--- a/packages/integration-test/package.json
+++ b/packages/integration-test/package.json
@@ -1,6 +1,6 @@
{
"name": "integration-test",
- "version": "0.47.0",
+ "version": "0.48.0",
"private": true,
"scripts": {
"test:integration": "jest --coverage --verbose"
diff --git a/packages/parser/package.json b/packages/parser/package.json
index e324b905..07e69e3d 100644
--- a/packages/parser/package.json
+++ b/packages/parser/package.json
@@ -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",
@@ -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": {
diff --git a/packages/template-parser/package.json b/packages/template-parser/package.json
index d3dacdac..213b11d8 100644
--- a/packages/template-parser/package.json
+++ b/packages/template-parser/package.json
@@ -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",
@@ -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": {
diff --git a/packages/template-syntax-parser/package.json b/packages/template-syntax-parser/package.json
index c1bd9620..ad31c399 100644
--- a/packages/template-syntax-parser/package.json
+++ b/packages/template-syntax-parser/package.json
@@ -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",
@@ -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",
diff --git a/packages/types/package.json b/packages/types/package.json
index 2ab61360..78d97014 100644
--- a/packages/types/package.json
+++ b/packages/types/package.json
@@ -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",
diff --git a/packages/web-linter/package.json b/packages/web-linter/package.json
index e8761811..71e015b8 100644
--- a/packages/web-linter/package.json
+++ b/packages/web-linter/package.json
@@ -1,6 +1,6 @@
{
"name": "@html-eslint/web-linter",
- "version": "0.47.0",
+ "version": "0.48.0",
"description": "",
"private": true,
"main": "out/output.js",
diff --git a/packages/website/package.json b/packages/website/package.json
index 243641d5..aed1bec5 100644
--- a/packages/website/package.json
+++ b/packages/website/package.json
@@ -1,6 +1,6 @@
{
"name": "website",
- "version": "0.47.1",
+ "version": "0.48.0",
"private": true,
"scripts": {
"clear:cache": "rimraf ../../parcel-cache",
@@ -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"
},
diff --git a/yarn.lock b/yarn.lock
index d9774ed6..3f7def74 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1213,8 +1213,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "@html-eslint/cli@workspace:packages/cli"
dependencies:
- "@html-eslint/eslint-plugin": "npm:^0.47.1"
- "@html-eslint/parser": "npm:^0.47.1"
+ "@html-eslint/eslint-plugin": "npm:^0.48.0"
+ "@html-eslint/parser": "npm:^0.48.0"
axios: "npm:^1.9.0"
chalk: "npm:^4.1.1"
eslint: "npm:^9.19.0"
@@ -1224,16 +1224,16 @@ __metadata:
languageName: unknown
linkType: soft
-"@html-eslint/eslint-plugin@npm:^0.47.1, @html-eslint/eslint-plugin@workspace:packages/eslint-plugin":
+"@html-eslint/eslint-plugin@npm:^0.48.0, @html-eslint/eslint-plugin@workspace:packages/eslint-plugin":
version: 0.0.0-use.local
resolution: "@html-eslint/eslint-plugin@workspace:packages/eslint-plugin"
dependencies:
"@eslint/core": "npm:^0.14.0"
"@eslint/plugin-kit": "npm:^0.3.1"
- "@html-eslint/parser": "npm:^0.47.1"
- "@html-eslint/template-parser": "npm:^0.47.1"
- "@html-eslint/template-syntax-parser": "npm:^0.47.1"
- "@html-eslint/types": "npm:^0.47.1"
+ "@html-eslint/parser": "npm:^0.48.0"
+ "@html-eslint/template-parser": "npm:^0.48.0"
+ "@html-eslint/template-syntax-parser": "npm:^0.48.0"
+ "@html-eslint/types": "npm:^0.48.0"
"@types/estree": "npm:^0.0.47"
es-html-parser: "npm:0.3.1"
eslint: "npm:^9.27.0"
@@ -1268,22 +1268,22 @@ __metadata:
languageName: unknown
linkType: soft
-"@html-eslint/parser@npm:^0.47.1, @html-eslint/parser@workspace:packages/parser":
+"@html-eslint/parser@npm:^0.48.0, @html-eslint/parser@workspace:packages/parser":
version: 0.0.0-use.local
resolution: "@html-eslint/parser@workspace:packages/parser"
dependencies:
- "@html-eslint/template-syntax-parser": "npm:^0.47.1"
- "@html-eslint/types": "npm:^0.47.1"
+ "@html-eslint/template-syntax-parser": "npm:^0.48.0"
+ "@html-eslint/types": "npm:^0.48.0"
es-html-parser: "npm:0.3.1"
typescript: "npm:^5.8.3"
languageName: unknown
linkType: soft
-"@html-eslint/template-parser@npm:^0.47.1, @html-eslint/template-parser@workspace:packages/template-parser":
+"@html-eslint/template-parser@npm:^0.48.0, @html-eslint/template-parser@workspace:packages/template-parser":
version: 0.0.0-use.local
resolution: "@html-eslint/template-parser@workspace:packages/template-parser"
dependencies:
- "@html-eslint/types": "npm:^0.47.1"
+ "@html-eslint/types": "npm:^0.48.0"
"@types/espree": "npm:^10.1.0"
"@types/estree": "npm:^0.0.47"
es-html-parser: "npm:0.3.1"
@@ -1293,17 +1293,17 @@ __metadata:
languageName: unknown
linkType: soft
-"@html-eslint/template-syntax-parser@npm:^0.47.1, @html-eslint/template-syntax-parser@workspace:packages/template-syntax-parser":
+"@html-eslint/template-syntax-parser@npm:^0.48.0, @html-eslint/template-syntax-parser@workspace:packages/template-syntax-parser":
version: 0.0.0-use.local
resolution: "@html-eslint/template-syntax-parser@workspace:packages/template-syntax-parser"
dependencies:
- "@html-eslint/types": "npm:^0.47.1"
+ "@html-eslint/types": "npm:^0.48.0"
eslint: "npm:^9.19.0"
globals: "npm:^15.12.0"
languageName: unknown
linkType: soft
-"@html-eslint/types@npm:^0.47.1, @html-eslint/types@workspace:packages/types":
+"@html-eslint/types@npm:^0.48.0, @html-eslint/types@workspace:packages/types":
version: 0.0.0-use.local
resolution: "@html-eslint/types@workspace:packages/types"
dependencies:
@@ -1314,7 +1314,7 @@ __metadata:
languageName: unknown
linkType: soft
-"@html-eslint/web-linter@npm:^0.47.0, @html-eslint/web-linter@workspace:packages/web-linter":
+"@html-eslint/web-linter@npm:^0.48.0, @html-eslint/web-linter@workspace:packages/web-linter":
version: 0.0.0-use.local
resolution: "@html-eslint/web-linter@workspace:packages/web-linter"
dependencies:
@@ -14814,9 +14814,9 @@ __metadata:
version: 0.0.0-use.local
resolution: "website@workspace:packages/website"
dependencies:
- "@html-eslint/eslint-plugin": "npm:^0.47.1"
- "@html-eslint/parser": "npm:^0.47.1"
- "@html-eslint/web-linter": "npm:^0.47.0"
+ "@html-eslint/eslint-plugin": "npm:^0.48.0"
+ "@html-eslint/parser": "npm:^0.48.0"
+ "@html-eslint/web-linter": "npm:^0.48.0"
"@html-kit/html": "npm:^0.0.4"
"@parcel/transformer-sass": "npm:2.13.0"
"@stylistic/eslint-plugin": "npm:^3.0.0"