diff --git a/lib/utils/indent-common.js b/lib/utils/indent-common.js
index de81799b4..1d02ba11b 100644
--- a/lib/utils/indent-common.js
+++ b/lib/utils/indent-common.js
@@ -672,6 +672,42 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
}
}
+ /**
+ * Get the expected indent of comments.
+ * @param {Token|null} nextToken The next token of comments.
+ * @param {number|undefined} nextExpectedIndent The expected indent of the next token.
+ * @param {number|undefined} lastExpectedIndent The expected indent of the last token.
+ * @returns {{primary:number|undefined,secondary:number|undefined}}
+ */
+ function getCommentExpectedIndents (nextToken, nextExpectedIndent, lastExpectedIndent) {
+ if (typeof lastExpectedIndent === 'number' && isClosingToken(nextToken)) {
+ if (nextExpectedIndent === lastExpectedIndent) {
+ // For solo comment. E.g.,
+ //
+ //
+ //
+ return {
+ primary: nextExpectedIndent + options.indentSize,
+ secondary: undefined
+ }
+ }
+
+ // For last comment. E.g.,
+ //
+ return { primary: lastExpectedIndent, secondary: nextExpectedIndent }
+ }
+
+ // Adjust to next normally. E.g.,
+ //
+ return { primary: nextExpectedIndent, secondary: undefined }
+ }
+
/**
* Validate indentation of the line that the given tokens are on.
* @param {Token[]} tokens The tokens on the same line to validate.
@@ -732,9 +768,7 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
// It allows the same indent level with the previous line.
const lastOffsetInfo = offsets.get(lastToken)
const lastExpectedIndent = lastOffsetInfo && lastOffsetInfo.expectedIndent
- const commentExpectedIndents = (typeof lastExpectedIndent === 'number' && isClosingToken(firstToken))
- ? { primary: lastExpectedIndent, secondary: expectedIndent }
- : { primary: expectedIndent, secondary: undefined }
+ const commentExpectedIndents = getCommentExpectedIndents(firstToken, expectedIndent, lastExpectedIndent)
// Validate.
for (const comment of comments) {
diff --git a/tests/fixtures/html-indent/solo-html-comment-01.vue b/tests/fixtures/html-indent/solo-html-comment-01.vue
new file mode 100644
index 000000000..4582b2754
--- /dev/null
+++ b/tests/fixtures/html-indent/solo-html-comment-01.vue
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/tests/lib/rules/html-indent.js b/tests/lib/rules/html-indent.js
index 18ce90748..e97aae5f2 100644
--- a/tests/lib/rules/html-indent.js
+++ b/tests/lib/rules/html-indent.js
@@ -191,6 +191,28 @@ tester.run('html-indent', rule, loadPatterns(
}}
`,
+ unIndent`
+
+