@@ -672,6 +672,42 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
672672 }
673673 }
674674
675+ /**
676+ * Get the expected indent of comments.
677+ * @param {Token|null } nextToken The next token of comments.
678+ * @param {number|undefined } nextExpectedIndent The expected indent of the next token.
679+ * @param {number|undefined } lastExpectedIndent The expected indent of the last token.
680+ * @returns {{primary:number|undefined,secondary:number|undefined} }
681+ */
682+ function getCommentExpectedIndents ( nextToken , nextExpectedIndent , lastExpectedIndent ) {
683+ if ( typeof lastExpectedIndent === 'number' && isClosingToken ( nextToken ) ) {
684+ if ( nextExpectedIndent === lastExpectedIndent ) {
685+ // For solo comment. E.g.,
686+ // <div>
687+ // <!-- comment -->
688+ // </div>
689+ return {
690+ primary : nextExpectedIndent + options . indentSize ,
691+ secondary : undefined
692+ }
693+ }
694+
695+ // For last comment. E.g.,
696+ // <div>
697+ // <div></div>
698+ // <!-- comment -->
699+ // </div>
700+ return { primary : lastExpectedIndent , secondary : nextExpectedIndent }
701+ }
702+
703+ // Adjust to next normally. E.g.,
704+ // <div>
705+ // <!-- comment -->
706+ // <div></div>
707+ // </div>
708+ return { primary : nextExpectedIndent , secondary : undefined }
709+ }
710+
675711 /**
676712 * Validate indentation of the line that the given tokens are on.
677713 * @param {Token[] } tokens The tokens on the same line to validate.
@@ -732,9 +768,7 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
732768 // It allows the same indent level with the previous line.
733769 const lastOffsetInfo = offsets . get ( lastToken )
734770 const lastExpectedIndent = lastOffsetInfo && lastOffsetInfo . expectedIndent
735- const commentExpectedIndents = ( typeof lastExpectedIndent === 'number' && isClosingToken ( firstToken ) )
736- ? { primary : lastExpectedIndent , secondary : expectedIndent }
737- : { primary : expectedIndent , secondary : undefined }
771+ const commentExpectedIndents = getCommentExpectedIndents ( firstToken , expectedIndent , lastExpectedIndent )
738772
739773 // Validate.
740774 for ( const comment of comments ) {
0 commit comments