Skip to content

Commit

Permalink
fix(check-alignment): handle zero indent; fixes gajus#1322
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Oct 1, 2024
1 parent 3b18435 commit 34866bc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/rules/check-alignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
````


Expand Down
8 changes: 7 additions & 1 deletion src/iterateJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
22 changes: 22 additions & 0 deletions test/rules/assertions/checkAlignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down

0 comments on commit 34866bc

Please sign in to comment.