Skip to content

Commit dd7d19f

Browse files
committed
Add test case for fixing check-alignment with tabs.
1 parent 2e3c3cd commit dd7d19f

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

src/iterateJsdoc.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,9 @@ export default function iterateJsdoc (iterator, ruleConfig) {
499499
return;
500500
}
501501

502-
const indent = ' '.repeat(jsdocNode.loc.start.column);
502+
const sourceLine = sourceCode.lines[jsdocNode.loc.start.line - 1];
503+
504+
const indent = sourceLine.charAt(0).repeat(jsdocNode.loc.start.column);
503505

504506
const jsdoc = parseComment(jsdocNode, indent);
505507

src/rules/checkAlignment.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import _ from 'lodash';
21
import iterateJsdoc from '../iterateJsdoc';
32

3+
const trimStart = (string) => {
4+
return string.replace(/^\s+/, '');
5+
};
6+
47
export default iterateJsdoc(({
58
sourceCode,
69
jsdocNode,
@@ -15,16 +18,16 @@ export default iterateJsdoc(({
1518
return line.split('*')[0];
1619
})
1720
.filter((line) => {
18-
return !line.trim().length;
21+
return !trimStart(line).length;
1922
});
2023

2124
const fix = (fixer) => {
2225
const replacement = sourceCode.getText(jsdocNode).split('\n')
2326
.map((line, index) => {
2427
// Ignore the first line and all lines not starting with `*`
25-
const ignored = !index || line.split('*')[0].trim().length;
28+
const ignored = !index || trimStart(line.split('*')[0]).length;
2629

27-
return ignored ? line : `${indent} ${_.trimStart(line)}`;
30+
return ignored ? line : `${indent} ${trimStart(line)}`;
2831
})
2932
.join('\n');
3033

test/rules/assertions/checkAlignment.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
* @param {Number} foo
77
*/
88
function quux (foo) {
9-
9+
// with spaces
1010
}
1111
`,
1212
errors: [
@@ -20,10 +20,36 @@ export default {
2020
* @param {Number} foo
2121
*/
2222
function quux (foo) {
23-
23+
// with spaces
2424
}
2525
`,
2626
},
27+
/* eslint-disable no-tabs */
28+
{
29+
code: `
30+
/**
31+
* @param {Number} foo
32+
*/
33+
function quux (foo) {
34+
// with tabs
35+
}
36+
`,
37+
errors: [
38+
{
39+
line: 3,
40+
message: 'Expected JSDoc block to be aligned.',
41+
},
42+
],
43+
output: `
44+
/**
45+
* @param {Number} foo
46+
*/
47+
function quux (foo) {
48+
// with tabs
49+
}
50+
`,
51+
},
52+
/* eslint-enable no-tabs */
2753
{
2854
code: `
2955
/**

0 commit comments

Comments
 (0)