Skip to content

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

Closed
@joezappie

Description

@joezappie

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions