gajus / eslint-plugin-jsdoc

JSDoc specific linting rules for ESLint.
Other
1.09k stars 157 forks source link

`jsdoc/check-line-alignment` incorrectly triggered if `@returns` description starts with `-1` #1091

Closed willeastcott closed 1 year ago

willeastcott commented 1 year ago

It seems that the jsdoc/check-line-alignment rule is triggered if an @returns description begins with -1 (number).

Expected behavior

AFAIK, the dash is not recommended to delimit the @returns type from the description. So I would expect this to not trigger the error.

Actual behavior

Error is output:

C:\dev\engineclean\src\scene\graph-node.js
  915:1  error  Expected JSDoc block lines to not be aligned  jsdoc/check-line-alignment

✖ 1 problem (1 error, 0 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

ESLint Config

Include this:

"jsdoc/check-alignment": "error"

This appears in this full config:

https://github.com/playcanvas/playcanvas-eslint-config/blob/9dac541d64a73876ed27d5298eed7197981e6958/index.js#L400

ESLint sample

This code triggers the error:

    /**
     * Returns cached value of negative scale of the world transform.
     *
     * @returns {number} -1 if world transform has negative scale, 1 otherwise.
     * @ignore
     */
    get worldScaleSign() {

        if (this._worldScaleSign === 0) {
            this._worldScaleSign = this.getWorldTransform().scaleSign;
        }

        return this._worldScaleSign;
    }

Error output is:

image

Doing an autofix will update this:

     * @returns {number} -1 if world transform has negative scale, 1 otherwise.

To this:

     * @returns {number} - 1 if world transform has negative scale, 1 otherwise.

This completely changes the meaning of the docs, of course.

Environment

brettz9 commented 1 year ago

The hyphen sometimes is used to delimit alignment, but the new fix will only do so if the hyphen has at least some whitespace after it.

github-actions[bot] commented 1 year ago

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

The release is available on:

Your semantic-release bot :package::rocket: