Eslint-plugin-jsdoc: jsdoc/check-param-names incorrectly failing when using default params

Created on 7 Sep 2019  Â·  6Comments  Â·  Source: gajus/eslint-plugin-jsdoc

The error I'm getting.

  âš   632:0  Expected @param names to be "name". Got "name ".                                     jsdoc/check-param-names
    /**
     * Loads server with { async start(), async stop() } signature
     *
     * @name core.loadServer
     * @param {string} [name = 'server'] The name of the unraid server to load.
     */
    const loadServer = async(name = 'server') => {};
enhancement help wanted released

All 6 comments

/**
 * Loads server with { async start(), async stop() } signature
 *
 * @name core.loadServer
 * @param {string} [name='server'] The name of the unraid server to load.
 */

^would work

I have another rule that clashes as it requires spaces like this [node = 'server].

Sounds like a good first contribution.

@gajus would this be the "correct" way of fixing this? If so I'll open a PR.

diff --git a/src/rules/checkParamNames.js b/src/rules/checkParamNames.js
index 72cf61f..6675e35 100644
--- a/src/rules/checkParamNames.js
+++ b/src/rules/checkParamNames.js
@@ -40,7 +40,7 @@ const validateParameterNames = (targetTagName : string, functionParameterNames :
       return false;
     }

-    if (functionParameterName !== tag.name) {
+    if (functionParameterName !== tag.name.trim()) {
       const expectedNames = functionParameterNames.join(', ');
       const actualNames = paramTags.map(([, {name}]) => {
         return name;

Before:

  utils/vms/parse-domain/sanitize-vendor.js:11:NaN
  âš   11:0   Expected @param names to be "vendorName". Got "vendorName ".                         jsdoc/check-param-names

  utils/misc/exit-app.js:15:21
  âš   13:0   Expected @param names to be "error, code". Got "error, code ".                       jsdoc/check-param-names

After:
No errors.

Looks great to me. If you could just add the passing test, along with this config (assuming you are using async in the example), it should be good to go:

      parserOptions: {
        ecmaVersion: 2017,
      },

(While we could look at getting comment-parser to support the trimming of names itself, I think we'd probably rather not have it trim them for the sake of our fixers being able to leave such spacing alone.)

:tada: This issue has been resolved in version 18.4.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yvele picture yvele  Â·  4Comments

rasenplanscher picture rasenplanscher  Â·  3Comments

OmgImAlexis picture OmgImAlexis  Â·  5Comments

ibbignerd picture ibbignerd  Â·  3Comments

michaelfarrell76 picture michaelfarrell76  Â·  4Comments