Skip to content

Commit c7f79fa

Browse files
committed
fix(newline-after-description): avoid matching duplicate or partial matches within tag descriptions after the block description; fixes #328
1 parent 87110ed commit c7f79fa

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

src/rules/newlineAfterDescription.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default iterateJsdoc(({
3030
if (!descriptionEndsWithANewline) {
3131
const sourceLines = sourceCode.getText(jsdocNode).split('\n');
3232
const lastDescriptionLine = _.findLastIndex(sourceLines, (line) => {
33-
return line.includes(_.last(jsdoc.description.split('\n')));
33+
return line.replace(/^\s*\*\s*/, '') === _.last(jsdoc.description.split('\n'));
3434
});
3535
report('There must be a newline after the description of the JSDoc block.', (fixer) => {
3636
// Add the new line
@@ -44,7 +44,7 @@ export default iterateJsdoc(({
4444
} else if (descriptionEndsWithANewline) {
4545
const sourceLines = sourceCode.getText(jsdocNode).split('\n');
4646
const lastDescriptionLine = _.findLastIndex(sourceLines, (line) => {
47-
return line.includes(_.last(jsdoc.description.split('\n')));
47+
return line.replace(/^\s*\*\s*/, '') === _.last(jsdoc.description.split('\n'));
4848
});
4949
report('There must be no newline after the description of the JSDoc block.', (fixer) => {
5050
// Remove the extra line

test/rules/assertions/newlineAfterDescription.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,56 @@ export default {
9898
9999
}
100100
`
101+
},
102+
{
103+
code: `
104+
/**
105+
* A.
106+
*
107+
* @typedef {Object} A
108+
* @prop {boolean} a A.
109+
*/
110+
`,
111+
errors: [
112+
{
113+
message: 'There must be no newline after the description of the JSDoc block.'
114+
}
115+
],
116+
options: [
117+
'never'
118+
],
119+
output: `
120+
/**
121+
* A.
122+
* @typedef {Object} A
123+
* @prop {boolean} a A.
124+
*/
125+
`
126+
},
127+
{
128+
code: `
129+
/**
130+
* A.
131+
* @typedef {Object} A
132+
* @prop {boolean} a A.
133+
*/
134+
`,
135+
errors: [
136+
{
137+
message: 'There must be a newline after the description of the JSDoc block.'
138+
}
139+
],
140+
options: [
141+
'always'
142+
],
143+
output: `
144+
/**
145+
* A.
146+
*
147+
* @typedef {Object} A
148+
* @prop {boolean} a A.
149+
*/
150+
`
101151
}
102152
],
103153
valid: [

0 commit comments

Comments
 (0)