Skip to content

Commit be9c24e

Browse files
authored
Merge pull request #266 from jasminexie/master
fix(require-hyphen-before-param-description): fix fixer to account for multiline descriptions
2 parents e9aa652 + 41fdbe8 commit be9c24e

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3033,8 +3033,19 @@ function quux () {
30333033
// Message: There must be no hyphen before @param description.
30343034

30353035
/**
3036-
* @param foo - Foo.
3037-
* @param bar Foo.
3036+
* @param foo - foo
3037+
* @param foo foo
3038+
*/
3039+
function quux () {
3040+
3041+
}
3042+
// Options: ["always"]
3043+
// Message: There must be a hyphen before @param description.
3044+
3045+
/**
3046+
* @param foo foo
3047+
* bar
3048+
* @param bar - bar
30383049
*/
30393050
function quux () {
30403051

src/rules/requireHyphenBeforeParamDescription.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ export default iterateJsdoc(({
2828
report('There must be a hyphen before @' + targetTagName + ' description.', (fixer) => {
2929
const lineIndex = jsdocTag.line;
3030
const sourceLines = sourceCode.getText(jsdocNode).split('\n');
31+
32+
// Get start index of description, accounting for multi-line descriptions
33+
const description = jsdocTag.description.split('\n')[0];
34+
const descriptionIndex = sourceLines[lineIndex].lastIndexOf(description);
35+
3136
const replacementLine = sourceLines[lineIndex]
32-
.replace(jsdocTag.description, '- ' + jsdocTag.description);
37+
.substring(0, descriptionIndex) + '- ' + description;
3338
sourceLines.splice(lineIndex, 1, replacementLine);
3439
const replacement = sourceLines.join('\n');
3540

test/rules/assertions/requireHyphenBeforeParamDescription.js

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ export default {
5757
{
5858
code: `
5959
/**
60-
* @param foo - Foo.
61-
* @param bar Foo.
60+
* @param foo - foo
61+
* @param foo foo
6262
*/
6363
function quux () {
6464
@@ -75,8 +75,39 @@ export default {
7575
],
7676
output: `
7777
/**
78-
* @param foo - Foo.
79-
* @param bar - Foo.
78+
* @param foo - foo
79+
* @param foo - foo
80+
*/
81+
function quux () {
82+
83+
}
84+
`
85+
},
86+
{
87+
code: `
88+
/**
89+
* @param foo foo
90+
* bar
91+
* @param bar - bar
92+
*/
93+
function quux () {
94+
95+
}
96+
`,
97+
errors: [
98+
{
99+
line: 3,
100+
message: 'There must be a hyphen before @param description.'
101+
}
102+
],
103+
options: [
104+
'always'
105+
],
106+
output: `
107+
/**
108+
* @param foo - foo
109+
* bar
110+
* @param bar - bar
80111
*/
81112
function quux () {
82113

0 commit comments

Comments
 (0)