@@ -23,44 +23,34 @@ module.exports = {
2323 } ,
2424
2525 create ( context ) {
26+ const glimmerTemplateRanges = [ ] ;
27+
2628 return {
27- 'Program:exit' ( node ) {
28- // Check for HTML comments in the source text
29+ GlimmerTemplate ( node ) {
30+ glimmerTemplateRanges . push ( node . range ) ;
31+ } ,
32+
33+ 'Program:exit' ( ) {
2934 const sourceCode = context . sourceCode || context . getSourceCode ( ) ;
30- const text = sourceCode . getText ( node ) ;
35+ const fullText = sourceCode . getText ( ) ;
3136
32- // Find all HTML comments in template blocks
33- const htmlCommentRegex = / < ! - - ( [ \S \s ] * ?) - - > / g;
34- let match ;
37+ for ( const comment of sourceCode . getAllComments ( ) ) {
38+ if ( comment . type !== 'Block' ) { continue ; }
3539
36- const hasTemplateTag = text . includes ( '<template>' ) ;
40+ // getAllComments() returns both HTML (<!-- -->) and Handlebars ({{! }}, {{!-- --}})
41+ // comments as Block type — only flag actual HTML comments.
42+ if ( ! fullText . startsWith ( '<!--' , comment . range [ 0 ] ) ) { continue ; }
3743
38- while ( ( match = htmlCommentRegex . exec ( text ) ) !== null ) {
39- let isInTemplate = false ;
40-
41- if ( hasTemplateTag ) {
42- const beforeComment = text . slice ( 0 , match . index ) ;
43- const templateStart = beforeComment . lastIndexOf ( '<template>' ) ;
44- const templateEnd = text . indexOf ( '</template>' , match . index ) ;
45- isInTemplate = templateStart !== - 1 && templateEnd !== - 1 ;
46- } else {
47- // Standalone .hbs file — entire file is template content
48- isInTemplate = true ;
49- }
44+ const isInTemplate = glimmerTemplateRanges . some (
45+ ( [ start , end ] ) => comment . range [ 0 ] >= start && comment . range [ 1 ] <= end
46+ ) ;
5047
5148 if ( isInTemplate ) {
52- const commentContent = match [ 1 ] ;
53- const startIndex = match . index ;
54- const endIndex = match . index + match [ 0 ] . length ;
55-
5649 context . report ( {
57- loc : {
58- start : sourceCode . getLocFromIndex ( startIndex ) ,
59- end : sourceCode . getLocFromIndex ( endIndex ) ,
60- } ,
50+ loc : comment . loc ,
6151 messageId : 'noHtmlComments' ,
6252 fix ( fixer ) {
63- return fixer . replaceTextRange ( [ startIndex , endIndex ] , `{{!${ commentContent } }}` ) ;
53+ return fixer . replaceTextRange ( comment . range , `{{!${ comment . value } }}` ) ;
6454 } ,
6555 } ) ;
6656 }
0 commit comments