Skip to content

Commit

Permalink
fix(match-description): single empty line was not being reported
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Mar 12, 2022
1 parent 3fe8ec2 commit ec34e66
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -7171,6 +7171,13 @@ function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"matchDescription":"^\\S[\\s\\S]*\\S$"}]
// Message: JSDoc description does not satisfy the regex pattern.

/**
*
* @param
*/
// "jsdoc/match-description": ["error"|"warn", {"contexts":["any"],"matchDescription":"^\\S[\\s\\S]*\\S$"}]
// Message: JSDoc description does not satisfy the regex pattern.
````

The following patterns are not considered problems:
Expand Down
2 changes: 1 addition & 1 deletion src/iterateJsdoc.js
Expand Up @@ -182,7 +182,7 @@ const getUtils = (
}

if (idx || description) {
descriptions.push(description);
descriptions.push(description || (descriptions.length ? '' : '\n'));
}

return false;
Expand Down
24 changes: 12 additions & 12 deletions src/rules/matchDescription.js
Expand Up @@ -23,7 +23,7 @@ export default iterateJsdoc(({
tags,
} = context.options[0] || {};

const validateDescription = (description, tag) => {
const validateDescription = (desc, tag) => {
let mainDescriptionMatch = mainDescription;
let errorMessage = message;
if (typeof mainDescription === 'object') {
Expand Down Expand Up @@ -52,7 +52,7 @@ export default iterateJsdoc(({
stringOrDefault(tagValue, matchDescription),
);

if (!regex.test(description)) {
if (!regex.test(desc)) {
report(
errorMessage || 'JSDoc description does not satisfy the regex pattern.',
null,
Expand All @@ -64,10 +64,10 @@ export default iterateJsdoc(({
}
};

if (jsdoc.description) {
const {
description,
} = utils.getDescription();
const {
description,
} = utils.getDescription();
if (description) {
validateDescription(description);
}

Expand All @@ -80,9 +80,9 @@ export default iterateJsdoc(({
};

utils.forEachPreferredTag('description', (matchingJsdocTag, targetTagName) => {
const description = (matchingJsdocTag.name + ' ' + utils.getTagDescription(matchingJsdocTag)).trim();
const desc = (matchingJsdocTag.name + ' ' + utils.getTagDescription(matchingJsdocTag)).trim();
if (hasOptionTag(targetTagName)) {
validateDescription(description, matchingJsdocTag);
validateDescription(desc, matchingJsdocTag);
}
}, true);

Expand All @@ -97,16 +97,16 @@ export default iterateJsdoc(({
} = utils.getTagsByType(whitelistedTags);

tagsWithNames.some((tag) => {
const description = utils.getTagDescription(tag).replace(/^[- ]*/u, '')
const desc = utils.getTagDescription(tag).replace(/^[- ]*/u, '')
.trim();

return validateDescription(description, tag);
return validateDescription(desc, tag);
});

tagsWithoutNames.some((tag) => {
const description = (tag.name + ' ' + utils.getTagDescription(tag)).trim();
const desc = (tag.name + ' ' + utils.getTagDescription(tag)).trim();

return validateDescription(description, tag);
return validateDescription(desc, tag);
});
}, {
contextDefaults: true,
Expand Down
22 changes: 22 additions & 0 deletions test/rules/assertions/matchDescription.js
Expand Up @@ -956,6 +956,28 @@ export default {
},
],
},
{
code: `
/**
*
* @param
*/
`,
errors: [
{
line: 3,
message: 'JSDoc description does not satisfy the regex pattern.',
},
],
options: [
{
contexts: [
'any',
],
matchDescription: '^\\S[\\s\\S]*\\S$',
},
],
},
],
valid: [
{
Expand Down

0 comments on commit ec34e66

Please sign in to comment.