Skip to content

Commit

Permalink
fix(newline-after-description): avoid matching duplicate or partial m…
Browse files Browse the repository at this point in the history
…atches within tag descriptions after the block description; fixes #328
  • Loading branch information
brettz9 committed Jul 12, 2019
1 parent 87110ed commit c7f79fa
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/rules/newlineAfterDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default iterateJsdoc(({
if (!descriptionEndsWithANewline) {
const sourceLines = sourceCode.getText(jsdocNode).split('\n');
const lastDescriptionLine = _.findLastIndex(sourceLines, (line) => {
return line.includes(_.last(jsdoc.description.split('\n')));
return line.replace(/^\s*\*\s*/, '') === _.last(jsdoc.description.split('\n'));
});
report('There must be a newline after the description of the JSDoc block.', (fixer) => {
// Add the new line
Expand All @@ -44,7 +44,7 @@ export default iterateJsdoc(({
} else if (descriptionEndsWithANewline) {
const sourceLines = sourceCode.getText(jsdocNode).split('\n');
const lastDescriptionLine = _.findLastIndex(sourceLines, (line) => {
return line.includes(_.last(jsdoc.description.split('\n')));
return line.replace(/^\s*\*\s*/, '') === _.last(jsdoc.description.split('\n'));
});
report('There must be no newline after the description of the JSDoc block.', (fixer) => {
// Remove the extra line
Expand Down
50 changes: 50 additions & 0 deletions test/rules/assertions/newlineAfterDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,56 @@ export default {
}
`
},
{
code: `
/**
* A.
*
* @typedef {Object} A
* @prop {boolean} a A.
*/
`,
errors: [
{
message: 'There must be no newline after the description of the JSDoc block.'
}
],
options: [
'never'
],
output: `
/**
* A.
* @typedef {Object} A
* @prop {boolean} a A.
*/
`
},
{
code: `
/**
* A.
* @typedef {Object} A
* @prop {boolean} a A.
*/
`,
errors: [
{
message: 'There must be a newline after the description of the JSDoc block.'
}
],
options: [
'always'
],
output: `
/**
* A.
*
* @typedef {Object} A
* @prop {boolean} a A.
*/
`
}
],
valid: [
Expand Down

0 comments on commit c7f79fa

Please sign in to comment.