Skip to content

Commit 10cb318

Browse files
authored
fix: tagChildrenIndent does not work on script, style (#312)
1 parent da63b10 commit 10cb318

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

packages/eslint-plugin/lib/rules/indent/indent.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* @typedef { import("@html-eslint/types").TemplateLiteral } TemplateLiteral
1313
* @typedef { import("@html-eslint/types").OpenTemplate } OpenTemplate
1414
* @typedef { import("@html-eslint/types").CloseTemplate } CloseTemplate
15+
* @typedef { import("@html-eslint/types").ScriptTag } ScriptTag
16+
* @typedef { import("@html-eslint/types").StyleTag } StyleTag
1517
*
1618
* @typedef {AnyNode | Line} AnyNodeOrLine
1719
* @typedef {Object} IndentType
@@ -40,6 +42,8 @@ const {
4042
isLine,
4143
isTag,
4244
hasTemplate,
45+
isScript,
46+
isStyle,
4347
} = require("../utils/node");
4448
const {
4549
shouldCheckTaggedTemplateExpression,
@@ -121,7 +125,7 @@ module.exports = {
121125
const { indentType, indentSize, indentChar } = getIndentOptionInfo(context);
122126

123127
/**
124-
* @param {Tag} node
128+
* @param {Tag | ScriptTag | StyleTag} node
125129
* @return {number}
126130
*/
127131
function getTagIncreasingLevel(node) {
@@ -150,7 +154,7 @@ module.exports = {
150154
if (isLine(node)) {
151155
return 1;
152156
}
153-
if (isTag(node)) {
157+
if (isTag(node) || isScript(node) || isStyle(node)) {
154158
return getTagIncreasingLevel(node);
155159
}
156160
const type = node.type;

packages/eslint-plugin/tests/rules/indent.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,44 @@ function createTests() {
391391
},
392392
{
393393
code: `
394+
<!DOCTYPE html>
395+
<html>
396+
<body>
397+
</body>
398+
<script src=""></script>
399+
</html>
400+
`,
401+
options: [
402+
2,
403+
{
404+
tagChildrenIndent: {
405+
html: 0,
406+
body: 0,
407+
},
408+
},
409+
],
410+
},
411+
{
412+
code: `
413+
<!DOCTYPE html>
414+
<html>
415+
<body>
416+
</body>
417+
<style></style>
418+
</html>
419+
`,
420+
options: [
421+
2,
422+
{
423+
tagChildrenIndent: {
424+
html: 0,
425+
body: 0,
426+
},
427+
},
428+
],
429+
},
430+
{
431+
code: `
394432
<style>
395433
</style>
396434
<script>

0 commit comments

Comments
 (0)