Skip to content

Fix fixer for require-hyphen-before-param-description #265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3031,6 +3031,16 @@ function quux () {
}
// Options: ["never"]
// Message: There must be no hyphen before @param description.

/**
* @param foo - Foo.
* @param foo Foo.
*/
function quux () {

}
// Options: ["always"]
// Message: There must be a hyphen before @param description.
````

The following patterns are not considered problems:
Expand Down
7 changes: 6 additions & 1 deletion src/rules/requireHyphenBeforeParamDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ export default iterateJsdoc(({
if (always) {
if (!jsdocTag.description.startsWith('-')) {
report('There must be a hyphen before @' + targetTagName + ' description.', (fixer) => {
const replacement = sourceCode.getText(jsdocNode).replace(jsdocTag.description, '- ' + jsdocTag.description);
const lineIndex = jsdocTag.line;
const sourceLines = sourceCode.getText(jsdocNode).split('\n');
const replacementLine = sourceLines[lineIndex]
.replace(jsdocTag.description, '- ' + jsdocTag.description);
sourceLines.splice(lineIndex, 1, replacementLine);
const replacement = sourceLines.join('\n');

return fixer.replaceText(jsdocNode, replacement);
}, jsdocTag);
Expand Down
29 changes: 29 additions & 0 deletions test/rules/assertions/requireHyphenBeforeParamDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,35 @@ export default {
*/
function quux () {

}
`
},
{
code: `
/**
* @param foo - Foo.
* @param foo Foo.
*/
function quux () {

}
`,
errors: [
{
line: 4,
message: 'There must be a hyphen before @param description.'
}
],
options: [
'always'
],
output: `
/**
* @param foo - Foo.
* @param foo - Foo.
*/
function quux () {

}
`
}
Expand Down