Skip to content

Commit

Permalink
INCOMPLETE: Need to get tests passing, apply to else-if branch, and t…
Browse files Browse the repository at this point in the history
…hen 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
  • Loading branch information
brettz9 committed Dec 4, 2019
1 parent bc9fa44 commit e18dfee
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/rules/newlineAfterDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default iterateJsdoc(({
jsdocNode,
sourceCode,
indent,
utils,
}) => {
let always;

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

if (always) {
if (!descriptionEndsWithANewline) {
const sourceLines = sourceCode.getText(jsdocNode).split('\n');
const splitDesc = jsdoc.description.split('\n');
const lastDescriptionLine = splitDesc.length - 1;
report('There must be a newline after the description of the JSDoc block.', (fixer) => {
// Add the new line
const injectedLine = `${indent} *` +
(sourceLines[lastDescriptionLine].endsWith('\r') ? '\r' : '');
sourceLines.splice(lastDescriptionLine + 1, 0, injectedLine);

return fixer.replaceText(jsdocNode, sourceLines.join('\n'));
}, {
utils.reportJSDoc('There must be a newline after the description of the JSDoc block.', {
line: lastDescriptionLine,
}, () => {
const injectedLine = jsdoc.description.endsWith('\r') ? '\r' : '';
jsdoc.description += '\n' + injectedLine;
});
}
} else if (descriptionEndsWithANewline) {
Expand Down

0 comments on commit e18dfee

Please sign in to comment.