|
1 | 1 | /** |
2 | | - * @typedef { import("../../types").RuleModule } RuleModule |
3 | 2 | * @typedef { import("@html-eslint/types").AnyNode } AnyNode |
4 | 3 | * @typedef { import("../../types").Line } Line |
5 | 4 | * @typedef { import("@html-eslint/types").Tag } Tag |
6 | 5 | * @typedef { import("../../types").RuleListener } RuleListener |
7 | | - * @typedef { import("../../types").Context } Context |
| 6 | + * @typedef { import("../../types").Context<any[]> } Context |
8 | 7 | * @typedef { import("@html-eslint/types").TemplateText } TemplateText |
9 | 8 | * @typedef { import("eslint").AST.Token } Token |
10 | 9 | * @typedef { import("eslint").SourceCode } SourceCode |
|
24 | 23 | * @property {IndentType["TAB"] | IndentType["SPACE"]} indentType |
25 | 24 | * @property {number} indentSize |
26 | 25 | * @property {string} indentChar |
| 26 | + * |
| 27 | + * @typedef {"tab" | number} Option1 |
| 28 | + * @typedef {Object} Option2 |
| 29 | + * @property {number} [Option2.Attribute] |
| 30 | + * @property {Record<string, number>} [Option2.tagChildrenIndent] |
| 31 | + * |
| 32 | + * @typedef { import("../../types").RuleModule<[Option1, Option2]> } RuleModule |
27 | 33 | */ |
28 | 34 |
|
29 | 35 | const { parse } = require("@html-eslint/template-parser"); |
@@ -147,9 +153,14 @@ module.exports = { |
147 | 153 | if (isTag(node)) { |
148 | 154 | return getTagIncreasingLevel(node); |
149 | 155 | } |
150 | | - return typeof indentLevelOptions[node.type] === "number" |
151 | | - ? indentLevelOptions[node.type] |
152 | | - : 1; |
| 156 | + const type = node.type; |
| 157 | + if (type === NodeTypes.Attribute) { |
| 158 | + const optionIndent = indentLevelOptions[type]; |
| 159 | + if (typeof optionIndent === "number") { |
| 160 | + return optionIndent; |
| 161 | + } |
| 162 | + } |
| 163 | + return 1; |
153 | 164 | } |
154 | 165 |
|
155 | 166 | /** |
@@ -252,11 +263,11 @@ module.exports = { |
252 | 263 | if (actualIndent !== expectedIndent) { |
253 | 264 | const targetNode = getIndentNodeToReport(node, actualIndent); |
254 | 265 | context.report({ |
255 | | - node: targetNode, |
| 266 | + loc: targetNode.loc, |
256 | 267 | messageId: MESSAGE_ID.WRONG_INDENT, |
257 | 268 | data: getMessageData(actualIndent, indentLevel.value()), |
258 | 269 | fix(fixer) { |
259 | | - return fixer.replaceText(targetNode, expectedIndent); |
| 270 | + return fixer.replaceTextRange(targetNode.range, expectedIndent); |
260 | 271 | }, |
261 | 272 | }); |
262 | 273 | } |
|
0 commit comments