Skip to content
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

"Error: Unsupported function signature format." - Class constructor param. destruction #699

Closed

Comments

@exodus4d
Copy link

exodus4d commented Feb 22, 2021

Expected behavior

If parameter destruction is used in a class constructor with dynamic property names, ESLint should not crash.

Since I don't know how jsdoc could proper document this, a first step might be not to break the entire ESLint.

Actual behavior

Parameter destruction in class constructor currently breaks ESLint.

Error: Unsupported function signature format.
Occurred while linting G:\webpages\pathfinder\js\app\component\abstractComponent.mjs:92

Error: Unsupported function signature format.
Occurred while linting G:\webpages\pathfinder\js\app\component\abstractComponent.mjs:92
    at getParamName (G:\webpages\pathfinder\node_modules\eslint-plugin-jsdoc\dist\jsdocUtils.js:231:11)
    at G:\webpages\pathfinder\node_modules\eslint-plugin-jsdoc\dist\jsdocUtils.js:142:16
    at Array.map (<anonymous>)
    at getParamName (G:\webpages\pathfinder\node_modules\eslint-plugin-jsdoc\dist\jsdocUtils.js:141:32)
    at G:\webpages\pathfinder\node_modules\eslint-plugin-jsdoc\dist\jsdocUtils.js:235:12
    at Array.map (<anonymous>)
    at Object.getFunctionParameterNames (G:\webpages\pathfinder\node_modules\eslint-plugin-jsdoc\dist\jsdocUtils.js:234:61)
    at Object.utils.getFunctionParameterNames (G:\webpages\pathfinder\node_modules\eslint-plugin-jsdoc\dist\iterateJsdoc.js:307:32)
    at _default.meta.docs.description (G:\webpages\pathfinder\node_modules\eslint-plugin-jsdoc\dist\rules\checkParamNames.js:228:40)
    at iterate (G:\webpages\pathfinder\node_modules\eslint-plugin-jsdoc\dist\iterateJsdoc.js:688:3)

ESLint sample

class A {
    static prop = 'c1';
    constructor({
        [new.target.prop]: cX,
        ...data
    }) {
         console.log(cX, data);
    }
}

class B extends A {
    static prop = 'c2';
    constructor(data) {
        super(data);
    }
}

let data = {
    id: 1,
    c1: 'c1Val',
    c2: 'c2Val'
};

new A(data);  // c1Val {id: 1, c2: "c2Val"}
new B(data);  // c2Val {id: 1, c1: "c1Val"}

Environment

  • Node version: 15.8.0
  • ESLint version 7.20.0
  • eslint-plugin-jsdoc version: 32.1.0
@brettz9
Copy link
Collaborator

brettz9 commented Feb 23, 2021

Please provide your ESLint config--including any settings, your parser and parserOptions, and any tweaking of the eslint-plugin-jsdoc rules (e.g., any options to jsdoc/check-param-names).

brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Feb 23, 2021
…ing upon `MemberExpression` or other constructions within dynamic properties; fixes gajus#699
@gajus
Copy link
Owner

gajus commented Feb 23, 2021

🎉 This issue has been resolved in version 32.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Feb 23, 2021
@brettz9
Copy link
Collaborator

brettz9 commented Feb 23, 2021

I've fixed it so that it should no longer throw with such dynamic properties.

However, this does not currently allow for any documentation in the place of the dynamic property. Ideally we'd add an option like our checkRestProperty (on jsdoc/check-param-names and jsdoc/require-param) but for dynamic properties, where one slot (and one slot only) would be reserved for such dynamic properties, and documentation would therefore be allowed or expected for such extra param if the option were enabled, bearing in mind, that, as with checkRestProperty, there is no way in jsdoc to distinguish a regular named property from a dynamic one as far as I am aware (unless perhaps to define the parameter parent object as a TypeScript-style type).

If you want to be able to have such a capability to document these, feel free to file such an issue as an enhancement for tracking purposes, but no guarantees of getting to it.

This was referenced Mar 11, 2021
This was referenced Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment