Skip to content

Commit

Permalink
fix: restore trim as relevant to tag description checking; fixes #670
Browse files Browse the repository at this point in the history
Impacts `check-values`,`empty-tags`,`no-defaults`, `require-hyphen-before-param-description`, `require-param-description`, `require-property-description`, `require-returns-description`, `valid-types`, `empty-tags`
  • Loading branch information
Brett Zamir committed Jan 14, 2021
1 parent 040d177 commit 9f69c36
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 9 deletions.
11 changes: 11 additions & 0 deletions README.md
Expand Up @@ -5477,6 +5477,17 @@ function quux () {
function quux () {
}
/**
* Create an array.
*
* @private
*
* @param {string[]} [elem] - Elements to make an array of.
* @param {boolean} [clone] - Optionally clone nodes.
* @returns {string[]} The array of nodes.
*/
function quux () {}
````
Expand Down
4 changes: 2 additions & 2 deletions src/rules/checkValues.js
Expand Up @@ -78,8 +78,8 @@ export default iterateJsdoc(({
});

utils.forEachPreferredTag('author', (jsdocParameter, targetTagName) => {
const author = jsdocParameter.description;
if (!author.trim()) {
const author = jsdocParameter.description.trim();
if (!author) {
report(
`Missing JSDoc @${targetTagName}.`,
null,
Expand Down
2 changes: 1 addition & 1 deletion src/rules/emptyTags.js
Expand Up @@ -33,7 +33,7 @@ export default iterateJsdoc(({
});
emptyTags.forEach((tag) => {
const content = tag.name || tag.description || tag.type;
if (content) {
if (content.trim()) {
const fix = () => {
utils.setTag(tag);
};
Expand Down
2 changes: 1 addition & 1 deletion src/rules/noDefaults.js
Expand Up @@ -23,7 +23,7 @@ export default iterateJsdoc(({
});
const defaultTags = utils.getPresentTags(['default', 'defaultvalue']);
defaultTags.forEach((tag) => {
if (tag.description) {
if (tag.description.trim()) {
utils.reportJSDoc(`Default values are not permitted on @${tag.tag}.`, tag, () => {
utils.changeTag(tag, {
description: '',
Expand Down
2 changes: 1 addition & 1 deletion src/rules/requireHyphenBeforeParamDescription.js
Expand Up @@ -12,7 +12,7 @@ export default iterateJsdoc(({

const checkHyphens = (jsdocTag, targetTagName, circumstance = mainCircumstance) => {
const always = !circumstance || circumstance === 'always';
if (!jsdocTag.description) {
if (!jsdocTag.description.trim()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/rules/requireParamDescription.js
Expand Up @@ -5,7 +5,7 @@ export default iterateJsdoc(({
utils,
}) => {
utils.forEachPreferredTag('param', (jsdocParameter, targetTagName) => {
if (!jsdocParameter.description) {
if (!jsdocParameter.description.trim()) {
report(
`Missing JSDoc @${targetTagName} "${jsdocParameter.name}" description.`,
null,
Expand Down
2 changes: 1 addition & 1 deletion src/rules/requirePropertyDescription.js
Expand Up @@ -5,7 +5,7 @@ export default iterateJsdoc(({
utils,
}) => {
utils.forEachPreferredTag('property', (jsdoc, targetTagName) => {
if (!jsdoc.description) {
if (!jsdoc.description.trim()) {
report(
`Missing JSDoc @${targetTagName} "${jsdoc.name}" description.`,
null,
Expand Down
2 changes: 1 addition & 1 deletion src/rules/requireReturnsDescription.js
Expand Up @@ -11,7 +11,7 @@ export default iterateJsdoc(({
return;
}

if (!jsdocTag.description) {
if (!jsdocTag.description.trim()) {
report(`Missing JSDoc @${targetTagName} description.`, null, jsdocTag);
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/rules/validTypes.js
Expand Up @@ -83,7 +83,7 @@ export default iterateJsdoc(({
};

if (tag.tag === 'borrows') {
const thisNamepath = tag.description.replace(asExpression, '');
const thisNamepath = tag.description.replace(asExpression, '').trim();

if (!asExpression.test(tag.description) || !thisNamepath) {
report(`@borrows must have an "as" expression. Found "${tag.description}"`, null, tag);
Expand Down
14 changes: 14 additions & 0 deletions test/rules/assertions/emptyTags.js
Expand Up @@ -269,5 +269,19 @@ export default {
}
`,
},
{
code: `
/**
* Create an array.
*
* @private
*
* @param {string[]} [elem] - Elements to make an array of.
* @param {boolean} [clone] - Optionally clone nodes.
* @returns {string[]} The array of nodes.
*/
function quux () {}
`,
},
],
};

0 comments on commit 9f69c36

Please sign in to comment.