Skip to content
Permalink
Browse files
fix(require-hyphen-before-param-description): allow whitespace befo…
…re hyphen when checking for hyphens; fixes #664
  • Loading branch information
brettz9 committed Jan 3, 2021
1 parent f345419 commit fb906ded845afb73cbe0047a5ab4b0f7bb96b666
Showing with 61 additions and 3 deletions.
  1. +17 −0 README.md
  2. +4 −3 src/rules/requireHyphenBeforeParamDescription.js
  3. +40 −0 test/rules/assertions/requireHyphenBeforeParamDescription.js
@@ -9432,6 +9432,15 @@ function quux () {
// Options: ["never"]
// Message: There must be no hyphen before @param description.
/**
* @param foo - Foo.
*/
function quux () {
}
// Options: ["never"]
// Message: There must be no hyphen before @param description.
/**
* @param foo - foo
* @param foo foo
@@ -9504,6 +9513,14 @@ function quux () {
}
// Options: ["always"]
/**
* @param foo - Foo.
*/
function quux () {
}
// Options: ["always"]
/**
* @param foo - Foo.
* @returns {SomeType} A description.
@@ -16,8 +16,9 @@ export default iterateJsdoc(({
return;
}

const startsWithHyphen = (/-/u).test(jsdocTag.description);
if (always) {
if (!jsdocTag.description.startsWith('-')) {
if (!startsWithHyphen) {
report(`There must be a hyphen before @${targetTagName} description.`, (fixer) => {
const lineIndex = jsdocTag.line;
const sourceLines = sourceCode.getText(jsdocNode).split('\n');
@@ -34,9 +35,9 @@ export default iterateJsdoc(({
return fixer.replaceText(jsdocNode, replacement);
}, jsdocTag);
}
} else if (jsdocTag.description.startsWith('-')) {
} else if (startsWithHyphen) {
report(`There must be no hyphen before @${targetTagName} description.`, (fixer) => {
const [unwantedPart] = /-\s*/u.exec(jsdocTag.description);
const [unwantedPart] = /\s*-\s*/u.exec(jsdocTag.description);

const replacement = sourceCode
.getText(jsdocNode)
@@ -145,6 +145,33 @@ export default {
}
`,
},
{
code: `
/**
* @param foo - Foo.
*/
function quux () {
}
`,
errors: [
{
line: 3,
message: 'There must be no hyphen before @param description.',
},
],
options: [
'never',
],
output: `
/**
* @param foo Foo.
*/
function quux () {
}
`,
},
{
code: `
/**
@@ -353,6 +380,19 @@ export default {
'always',
],
},
{
code: `
/**
* @param foo - Foo.
*/
function quux () {
}
`,
options: [
'always',
],
},
{
code: `
/**

0 comments on commit fb906de

Please sign in to comment.