55 * @typedef { import("../../types").Tag } Tag
66 * @typedef { import("../../types").RuleListener } RuleListener
77 * @typedef { import("../../types").Context } Context
8+ * @typedef { import("../../types").TemplateText } TemplateText
89 * @typedef { import("eslint").AST.Token } Token
910 * @typedef { import("eslint").SourceCode } SourceCode
1011 * @typedef { import("eslint").AST.Range } Range
2425 */
2526
2627const { parse } = require ( "@html-eslint/template-parser" ) ;
28+ const { NodeTypes } = require ( "es-html-parser" ) ;
2729const { RULE_CATEGORY } = require ( "../../constants" ) ;
28- const { splitToLineNodes, isLine, isTag } = require ( "../utils/node" ) ;
30+ const {
31+ splitToLineNodes,
32+ isLine,
33+ isTag,
34+ hasTemplate,
35+ } = require ( "../utils/node" ) ;
2936const {
3037 shouldCheckTaggedTemplateExpression,
3138 shouldCheckTemplateLiteral,
@@ -173,7 +180,7 @@ module.exports = {
173180 let parentIgnoringChildCount = 0 ;
174181
175182 /**
176- * @param {AnyNode | Line } node
183+ * @param {AnyNode | Line | TemplateText } node
177184 * @returns {string }
178185 */
179186 function getActualIndent ( node ) {
@@ -228,7 +235,7 @@ module.exports = {
228235 }
229236
230237 /**
231- * @param {AnyNode | Line } node
238+ * @param {AnyNode | Line | TemplateText } node
232239 */
233240 function checkIndent ( node ) {
234241 if ( parentIgnoringChildCount > 0 ) {
@@ -303,10 +310,23 @@ module.exports = {
303310 } ,
304311 Text ( node ) {
305312 indentLevel . indent ( node ) ;
313+ if ( hasTemplate ( node ) ) {
314+ node . parts . forEach ( ( part ) => {
315+ if ( part . type !== NodeTypes . Part ) {
316+ if ( part . open ) {
317+ checkIndent ( part . open ) ;
318+ }
319+ if ( part . close ) {
320+ checkIndent ( part . close ) ;
321+ }
322+ }
323+ } ) ;
324+ }
325+
306326 const lineNodes = splitToLineNodes ( node ) ;
307327
308328 lineNodes . forEach ( ( lineNode ) => {
309- if ( lineNode . skipIndentCheck ) {
329+ if ( lineNode . hasTemplate ) {
310330 return ;
311331 }
312332 if ( lineNode . value . trim ( ) . length ) {
@@ -323,9 +343,22 @@ module.exports = {
323343 CommentOpen : checkIndent ,
324344 CommentContent ( node ) {
325345 indentLevel . indent ( node ) ;
346+ if ( hasTemplate ( node ) ) {
347+ node . parts . forEach ( ( part ) => {
348+ if ( part . type !== NodeTypes . Part ) {
349+ if ( part . open ) {
350+ checkIndent ( part . open ) ;
351+ }
352+ if ( part . close ) {
353+ checkIndent ( part . close ) ;
354+ }
355+ }
356+ } ) ;
357+ }
358+
326359 const lineNodes = splitToLineNodes ( node ) ;
327360 lineNodes . forEach ( ( lineNode ) => {
328- if ( lineNode . skipIndentCheck ) {
361+ if ( lineNode . hasTemplate ) {
329362 return ;
330363 }
331364 if ( lineNode . value . trim ( ) . length ) {
@@ -363,7 +396,7 @@ module.exports = {
363396} ;
364397
365398/**
366- * @param {AnyNode | Line } node
399+ * @param {AnyNode | Line | TemplateText } node
367400 * @param {string } actualIndent
368401 * @return {{range: Range; loc: SourceLocation} }
369402 */
0 commit comments