Skip to content

Enabling require-jsdoc for class methods causes weird formatting when automatically fixing. #524

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

Closed
joezappie opened this issue May 4, 2020 · 5 comments

Comments

@joezappie
Copy link

joezappie commented May 4, 2020

I turned on jsdoc/require-jsdoc and enabled it for both MethodDefinition and ClassDeclaration. I am using the eslint addon for Atom and when I save my file it tries to fix any class method without a jsdoc but it does not format it properly. This also occurs when I eslint it from the command line and pass in the --fix command so its not just an issue with how the Atom plugin is behaving. Here is an example (with function bodies removed for sake of readability):

Original:

class User {
  async updatePassword(password, repeat) {
    ...
  }
}

ESlint fix for require-jsdoc:

/**
 *
 */
class User {

  async updatePassword/**
 *
 */
/**
 *
 */
/**
 *
 */
/**
 *
 */
/**
 *
 */
/**
 *
 */
/**
 *
 */
/**
 *
 */
/**
 *
 */
/**
 *
 */
(password, repeat) {
...
  }
}

Expected:

/**
 *
 */
class User {
  /**
   * @param password
   * @param repeat
   */
  async updatePassword(password, repeat) {
    ...
  }
}

As you can see its trying to fix it by putting the JS doc comment in between the method name and its parameters. Its also for some reason adding a ton of comment blocks instead of just one. Since it doesnt fix the issue, everytime I save the file or run --fix it adds more empty comment blocks. Here is my .eslintrc.json:

    "env": {
        "browser": true,
        "commonjs": true,
        "es6": true
    },
    "plugins": [
      "jsdoc"
    ],
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    "parserOptions": {
        "ecmaVersion": 2018
    },
    "rules": {
      "jsdoc/require-jsdoc": ["error", {
        "require": {
            "FunctionDeclaration": true,
            "MethodDefinition": true,
            "ClassDeclaration": true
        }
    }]
    }
}```

I am using eslint version 6.8.0 and eslint-plugin-jsdoc version ^24.0.2
@brettz9
Copy link
Collaborator

brettz9 commented May 5, 2020

Thank you for the report.

I tried to reproduce a test case using the following (the test case needs to be complete, valid JS):

      class User {
        async updatePassword(password, repeat) {
        }
      }

...and using the same parserOptions and require option config, and there is no such output for me.

I also tried it outside of our testing suite and found no issues.

There is a separate issue with require-param which I expect will be fixed by #447 as per #447 (comment) . Do you get the same issue if you disable require-param (or have you already disabled it per your config)?

Please ensure the config you are using is limited to the config you have indicated above and that there is an exact reproducible test case. (Not doubting this is a real issue, but just need to get it boiled down a bit further so we can reproduce.)

Thanks!

@joezappie
Copy link
Author

I think I have a conflicting issue some place. I just made a test node project with just the jsdoc plugin enabled and with that test case and it properly formatted the JS Doc. If I copy that exact same eslintrc config into my actual project, it fails to format it properly. Not sure whats going on there but I'll update this when I find whats causing the issue.

@joezappie
Copy link
Author

I've seemed to fix the problem, without knowing exactly what was the issue. I ended up completely reinstalling NodeJS and now saving that same file with the same configuration works. Still makes no sense that it was working in some projects and not others using the exact same config files but I wont complain that its working now. I'm going to close this as it wasn't an issue with jsdoc plugin.

@brettz9
Copy link
Collaborator

brettz9 commented May 6, 2020

No worries. It was an issue before the latest fix, so maybe your environment was somehow using an old version. In any case, let us know if you find it recurring and can replicate. You might also see #526 and the fact that there is now a new bugfix release, as there were problems with exported named variables if you are using any of those.

@andrei9669
Copy link

Had the same problem, had to update/reinstall node to get this fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants