question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

valid-jsdoc fails on functions that use ES6 destructuring assignment in signature

See original GitHub issue

Given the following code:

/**
 * @param {object} options
 * @return {number}
 */
const test = function({ a, b, c }) {
  return a + b + c;
};
module.exports = test;

The valid-jsdoc rule fails with the following message:

Expected JSDoc for ‘undefined’ but found ‘options’. (valid-jsdoc)

Changing the variable name in the @param tag to “undefined” doesn’t work either.

ESLint 0.17.0

<bountysource-plugin>

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:5
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

13reactions
aaronrobersoncommented, Nov 18, 2016

It seems like this is a good behavior. Using destructuring in a method or function signature seems like a poor contract to make.

I would suggest that it is a good practice to have all required items listed separately in the method signature and use a single parameter for a config object.

Within the function body, it makes sense to use destructuring to pull out distinct properties from the provided config/options object. And it would make sense to use destructing when calling the method. But I don’t think destructing belongs in the method signature itself.

8reactions
robcolburncommented, Jan 21, 2016

@nzakas, The fix in a1da3b4 sort of dodges the issue a bit, and doesn’t quite do what we’d hope it could…

It turns out JSDoc does support destructing via making up a placeholder name. It is lacking in official documentation. https://github.com/jsdoc3/jsdoc/issues/987

/**
 * @param {object} param
 * @param {number} param.a - First value
 * @param {object} param.b - Wrapper
 * @param {number} param.b.c - Second value
 * @return {number} sum a and b
 */
letters = ({a, b: {c}}) => a + c;

Perhaps, we can support this kind of grammar?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Destructuring assignment - JavaScript - MDN Web Docs
The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from ...
Read more >
Destructuring assignment in function call while preserving the ...
This means that using destructuring with rest parameters - for objects and arrays alike - would not preserve the entire array or object...
Read more >
valid-jsdoc - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Destructuring Mixed Objects and Function Arguments in ES6
Learn more ways to destructure mixed objects in and function arguments using JavaScript, HTML, and ES6 in this JS tutorial.
Read more >
eslint | Yarn - Package Manager
... 1d443a0 Fix: valid-jsdoc does not know async function returns (fixes #9881) ... 075ec25 Chore: update to use ES6 classes (refs #7849) (#7891)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found