Skip to content

Commit d88db5e

Browse files
committed
INCOMPLETE: Need to get tests passing, apply to else-if branch, and then create as utility so new rule preventing newlines between tags can reuse; to use smoother stringification fixing approach, will probably need to get comment-parser stringify to add back asterisks for multiline descriptions (ideally preserving this info during parse; may be other stringification issues); gajus#93
1 parent dd5f015 commit d88db5e

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/rules/newlineAfterDescription.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default iterateJsdoc(({
88
jsdocNode,
99
sourceCode,
1010
indent,
11+
utils,
1112
}) => {
1213
let always;
1314

@@ -25,18 +26,13 @@ export default iterateJsdoc(({
2526

2627
if (always) {
2728
if (!descriptionEndsWithANewline) {
28-
const sourceLines = sourceCode.getText(jsdocNode).split('\n');
2929
const splitDesc = jsdoc.description.split('\n');
3030
const lastDescriptionLine = splitDesc.length - 1;
31-
report('There must be a newline after the description of the JSDoc block.', (fixer) => {
32-
// Add the new line
33-
const injectedLine = `${indent} *` +
34-
(sourceLines[lastDescriptionLine].endsWith('\r') ? '\r' : '');
35-
sourceLines.splice(lastDescriptionLine + 1, 0, injectedLine);
36-
37-
return fixer.replaceText(jsdocNode, sourceLines.join('\n'));
38-
}, {
31+
utils.reportJSDoc('There must be a newline after the description of the JSDoc block.', {
3932
line: lastDescriptionLine,
33+
}, () => {
34+
const injectedLine = jsdoc.description.endsWith('\r') ? '\r' : '';
35+
jsdoc.description += '\n' + injectedLine;
4036
});
4137
}
4238
} else if (descriptionEndsWithANewline) {

0 commit comments

Comments
 (0)