Skip to content

Commit 8f8431d

Browse files
committed
fix(check-alignment, check-indentation, newline-after-description): report error line numbers
1 parent 4049db1 commit 8f8431d

File tree

6 files changed

+44
-18
lines changed

6 files changed

+44
-18
lines changed

src/rules/checkAlignment.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,17 @@ export default iterateJsdoc(({
3131
return fixer.replaceText(jsdocNode, replacement);
3232
};
3333

34-
for (const line of sourceLines) {
34+
sourceLines.some((line, lineNum) => {
3535
if (line.length !== indentLevel) {
36-
report('Expected JSDoc block to be aligned.', fix);
37-
break;
36+
report('Expected JSDoc block to be aligned.', fix, {
37+
line: lineNum + 1
38+
});
39+
40+
return true;
3841
}
39-
}
42+
43+
return false;
44+
});
4045
}, {
4146
iterateAllJsdocs: true,
4247
meta: {

src/rules/checkIndentation.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ export default iterateJsdoc(({
55
jsdocNode,
66
report
77
}) => {
8-
const reg = new RegExp(/^[ \t]+\*[ \t]{2}/m);
8+
const reg = new RegExp(/^[ \t]+\*[ \t]{2}/gm);
99
const text = sourceCode.getText(jsdocNode);
1010

1111
if (reg.test(text)) {
12-
report('There must be no indentation.');
12+
const lineBreaks = text.slice(0, reg.lastIndex).match(/\n/g) || [];
13+
report('There must be no indentation.', null, {
14+
line: lineBreaks.length
15+
});
1316
}
1417
}, {
1518
iterateAllJsdocs: true,

src/rules/newlineAfterDescription.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,31 @@ export default iterateJsdoc(({
2828

2929
if (always) {
3030
if (!descriptionEndsWithANewline) {
31+
const sourceLines = sourceCode.getText(jsdocNode).split('\n');
32+
const lastDescriptionLine = _.findLastIndex(sourceLines, (line) => {
33+
return line.includes(_.last(jsdoc.description.split('\n')));
34+
});
3135
report('There must be a newline after the description of the JSDoc block.', (fixer) => {
32-
const sourceLines = sourceCode.getText(jsdocNode).split('\n');
33-
const lastDescriptionLine = _.findLastIndex(sourceLines, (line) => {
34-
return line.includes(_.last(jsdoc.description.split('\n')));
35-
});
36-
3736
// Add the new line
3837
sourceLines.splice(lastDescriptionLine + 1, 0, `${indent} *`);
3938

4039
return fixer.replaceText(jsdocNode, sourceLines.join('\n'));
40+
}, {
41+
line: lastDescriptionLine
4142
});
4243
}
4344
} else if (descriptionEndsWithANewline) {
45+
const sourceLines = sourceCode.getText(jsdocNode).split('\n');
46+
const lastDescriptionLine = _.findLastIndex(sourceLines, (line) => {
47+
return line.includes(_.last(jsdoc.description.split('\n')));
48+
});
4449
report('There must be no newline after the description of the JSDoc block.', (fixer) => {
45-
const sourceLines = sourceCode.getText(jsdocNode).split('\n');
46-
const lastDescriptionLine = _.findLastIndex(sourceLines, (line) => {
47-
return line.includes(_.last(jsdoc.description.split('\n')));
48-
});
49-
5050
// Remove the extra line
5151
sourceLines.splice(lastDescriptionLine + 1, 1);
5252

5353
return fixer.replaceText(jsdocNode, sourceLines.join('\n'));
54+
}, {
55+
line: lastDescriptionLine + 1
5456
});
5557
}
5658
}, {

test/rules/assertions/checkAlignment.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default {
1111
`,
1212
errors: [
1313
{
14+
line: 3,
1415
message: 'Expected JSDoc block to be aligned.'
1516
}
1617
],
@@ -34,6 +35,7 @@ export default {
3435
`,
3536
errors: [
3637
{
38+
line: 4,
3739
message: 'Expected JSDoc block to be aligned.'
3840
}
3941
],
@@ -57,6 +59,7 @@ export default {
5759
`,
5860
errors: [
5961
{
62+
line: 3,
6063
message: 'Expected JSDoc block to be aligned.'
6164
}
6265
],
@@ -80,6 +83,7 @@ export default {
8083
`,
8184
errors: [
8285
{
86+
line: 4,
8387
message: 'Expected JSDoc block to be aligned.'
8488
}
8589
],
@@ -103,6 +107,7 @@ export default {
103107
`,
104108
errors: [
105109
{
110+
line: 3,
106111
message: 'Expected JSDoc block to be aligned.'
107112
}
108113
],
@@ -122,7 +127,10 @@ export default {
122127
*/
123128
`,
124129
errors: [
125-
{message: 'Expected JSDoc block to be aligned.'}
130+
{
131+
line: 3,
132+
message: 'Expected JSDoc block to be aligned.'
133+
}
126134
]
127135
},
128136
{
@@ -136,7 +144,10 @@ export default {
136144
}
137145
`,
138146
errors: [
139-
{message: 'Expected JSDoc block to be aligned.'}
147+
{
148+
line: 5,
149+
message: 'Expected JSDoc block to be aligned.'
150+
}
140151
]
141152
}
142153
],

test/rules/assertions/checkIndentation.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default {
1414
`,
1515
errors: [
1616
{
17+
line: 6,
1718
message: 'There must be no indentation.'
1819
}
1920
]
@@ -28,6 +29,7 @@ export default {
2829
`,
2930
errors: [
3031
{
32+
line: 4,
3133
message: 'There must be no indentation.'
3234
}
3335
]

test/rules/assertions/newlineAfterDescription.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default {
1414
`,
1515
errors: [
1616
{
17+
line: 5,
1718
message: 'There must be a newline after the description of the JSDoc block.'
1819
}
1920
],
@@ -47,6 +48,7 @@ export default {
4748
`,
4849
errors: [
4950
{
51+
line: 5,
5052
message: 'There must be a newline after the description of the JSDoc block.'
5153
}
5254
],
@@ -78,6 +80,7 @@ export default {
7880
`,
7981
errors: [
8082
{
83+
line: 6,
8184
message: 'There must be no newline after the description of the JSDoc block.'
8285
}
8386
],

0 commit comments

Comments
 (0)