Skip to content

Commit 34866bc

Browse files
committedOct 1, 2024
fix(check-alignment): handle zero indent; fixes #1322
1 parent 3b18435 commit 34866bc

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed
 

Diff for: ‎docs/rules/check-alignment.md

+7
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ class Foo {
110110
quux(a) {}
111111
}
112112
// Message: Expected JSDoc block to be aligned.
113+
114+
export const myVar = {/**
115+
* This is JSDoc
116+
*/
117+
myProperty: 'hello'
118+
}
119+
// Message: Expected JSDoc block to be aligned.
113120
````
114121

115122

Diff for: ‎src/iterateJsdoc.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1999,7 +1999,13 @@ const getIndentAndJSDoc = function (lines, jsdocNode) {
19991999
/** @type {import('estree').SourceLocation} */
20002000
(jsdocNode.loc).start.line - 1
20012001
];
2002-
const indnt = sourceLine.charAt(0).repeat(
2002+
2003+
let indentChar = sourceLine.charAt(0);
2004+
if (indentChar !== ' ' && indentChar !== '\t') {
2005+
indentChar = ' ';
2006+
}
2007+
2008+
const indnt = indentChar.repeat(
20032009
/** @type {import('estree').SourceLocation} */
20042010
(jsdocNode.loc).start.column,
20052011
);

Diff for: ‎test/rules/assertions/checkAlignment.js

+22
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,28 @@ function quux (foo) {
236236
}
237237
`,
238238
},
239+
{
240+
code: `
241+
export const myVar = {/**
242+
* This is JSDoc
243+
*/
244+
myProperty: 'hello'
245+
}
246+
`,
247+
errors: [
248+
{
249+
line: 3,
250+
message: 'Expected JSDoc block to be aligned.',
251+
},
252+
],
253+
output: `
254+
export const myVar = {/**
255+
* This is JSDoc
256+
*/
257+
myProperty: 'hello'
258+
}
259+
`,
260+
},
239261
],
240262
valid: [
241263
{

0 commit comments

Comments
 (0)