diff --git a/docs/rules/check-alignment.md b/docs/rules/check-alignment.md index 22f21988a..fdbf534ba 100644 --- a/docs/rules/check-alignment.md +++ b/docs/rules/check-alignment.md @@ -110,6 +110,13 @@ class Foo { quux(a) {} } // Message: Expected JSDoc block to be aligned. + +export const myVar = {/** + * This is JSDoc + */ + myProperty: 'hello' +} +// Message: Expected JSDoc block to be aligned. ```` diff --git a/src/iterateJsdoc.js b/src/iterateJsdoc.js index b5f93a3cf..eec9a974c 100644 --- a/src/iterateJsdoc.js +++ b/src/iterateJsdoc.js @@ -1999,7 +1999,13 @@ const getIndentAndJSDoc = function (lines, jsdocNode) { /** @type {import('estree').SourceLocation} */ (jsdocNode.loc).start.line - 1 ]; - const indnt = sourceLine.charAt(0).repeat( + + let indentChar = sourceLine.charAt(0); + if (indentChar !== ' ' && indentChar !== '\t') { + indentChar = ' '; + } + + const indnt = indentChar.repeat( /** @type {import('estree').SourceLocation} */ (jsdocNode.loc).start.column, ); diff --git a/test/rules/assertions/checkAlignment.js b/test/rules/assertions/checkAlignment.js index 2c395f1e4..ca6e64027 100644 --- a/test/rules/assertions/checkAlignment.js +++ b/test/rules/assertions/checkAlignment.js @@ -236,6 +236,28 @@ function quux (foo) { } `, }, + { + code: ` +export const myVar = {/** + * This is JSDoc + */ + myProperty: 'hello' +} +`, + errors: [ + { + line: 3, + message: 'Expected JSDoc block to be aligned.', + }, + ], + output: ` +export const myVar = {/** + * This is JSDoc + */ + myProperty: 'hello' +} +`, + }, ], valid: [ {