gajus / eslint-plugin-jsdoc

JSDoc specific linting rules for ESLint.
Other
1.08k stars 155 forks source link

Allow implicit 'this' with destructured param #1190

Closed scronay closed 6 months ago

scronay commented 6 months ago

Expected behavior

No warning should be triggered when this param is accompanied by a destructured parameter.

Actual behavior

A warning is triggered, implying that the @param for the destructured root is being referenced as a match for this

image

Note: this warning does not trigger when the parameter following this is not destructured, or when @param is explicitly provided for this, as in the following cases:

/**
 * Returns the sum of two numbers
 * @param {number} a First value
 * @param {number} b Second value
 * @returns {number} Sum of a and b
 */
function sum(this: unknown, a: number, b: number) {
    return a + b;
}
/**
 * Returns the sum of two numbers
 * @param this 'this'
 * @param options Object to destructure
 * @param options.a First value
 * @param options.b Second value
 * @returns Sum of a and b
 */
function sumDestructure(this: T, { a, b }: { a: number, b: number }) {
    return a + b;
}

ESLint Config

module.exports = {
    env: {
        node: true
    },
    extends: [
        'eslint:recommended',
        'plugin:@typescript-eslint/recommended',
        'plugin:jsdoc/recommended'
    ],
    parser: '@typescript-eslint/parser',
    plugins: [
        '@typescript-eslint',
        'jsdoc'
    ],
    rules: {
        'jsdoc/require-param-type': 0,
        'jsdoc/require-returns-type': 0
    }
}

ESLint sample

image

/**
 * Returns the sum of two numbers
 * @param options Object to destructure
 * @param options.a First value
 * @param options.b Second value
 * @returns Sum of a and b
 */
function sumDestructure(this: unknown, { a, b }: { a: number, b: number }) {
    return a + b;
}

Environment

github-actions[bot] commented 6 months ago

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

The release is available on:

Your semantic-release bot :package::rocket: