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

Return type {Object | String} crashes ESLint JSdoc #861

Closed
bugwelle opened this issue Mar 28, 2022 · 3 comments
Closed

Return type {Object | String} crashes ESLint JSdoc #861

bugwelle opened this issue Mar 28, 2022 · 3 comments

Comments

@bugwelle
Copy link

bugwelle commented Mar 28, 2022

Thank you very much for this useful plugin. It appears, that the latest patch version (38.1.1) introduced a bug.
I'll do my best to describe it below. A minimal example as well as demo-repository is attached.

Expected behavior

ESLint (jsdoc plugin) reports issues, if any.

Actual behavior

ESLint (jsdoc plugin) crashes with an internal error TypeError: Cannot read properties of undefined (reading 'type').

If I use @return {Object | String}, it crashes. @return {object | String} works.

Full stack:

❯ npm run lint

> eslint-issue@1.0.0 lint
> eslint index.js


Oops! Something went wrong! :(

ESLint: 8.12.0

TypeError: Cannot read properties of undefined (reading 'type')
Occurred while linting /path/to/eslint-issue/index.js:8
Rule: "jsdoc/check-types"
    at checkNativeTypes (/path/to/eslint-issue/node_modules/eslint-plugin-jsdoc/dist/rules/checkTypes.js:173:158)
    at getInvalidTypes (/path/to/eslint-issue/node_modules/eslint-plugin-jsdoc/dist/rules/checkTypes.js:231:19)
    at /path/to/eslint-issue/node_modules/eslint-plugin-jsdoc/dist/rules/checkTypes.js:261:7
    at _traverse (/path/to/eslint-issue/node_modules/jsdoc-type-pratt-parser/dist/index.js:2334:59)
    at _traverse (/path/to/eslint-issue/node_modules/jsdoc-type-pratt-parser/dist/index.js:2341:25)
    at traverse (/path/to/eslint-issue/node_modules/jsdoc-type-pratt-parser/dist/index.js:2358:9)
    at _default.iterateAllJsdocs (/path/to/eslint-issue/node_modules/eslint-plugin-jsdoc/dist/rules/checkTypes.js:251:32)
    at iterate (/path/to/eslint-issue/node_modules/eslint-plugin-jsdoc/dist/iterateJsdoc.js:830:3)
    at callIterator (/path/to/eslint-issue/node_modules/eslint-plugin-jsdoc/dist/iterateJsdoc.js:914:7)
    at *:not(Program) (/path/to/eslint-issue/node_modules/eslint-plugin-jsdoc/dist/iterateJsdoc.js:973:11)

Everything worked in 38.1.0, but 38.1.1 crashes. Seems to be related to #860

For an example, see below.

ESLint Config

{
  "root": true,
  "plugins": ["jsdoc"],
  "extends": ["plugin:jsdoc/recommended"]
}

ESLint sample

'use strict';

/**
 *
 * @param {Object} param
 * @return {Object | String}
 */
function abc(param) {
  if (param.a)
    return {};
  return 'abc';
}

Furthermore, I have created a minimal example here: https://github.com/bugwelle/eslint-issue

Environment

  • Node version: v16.14.1
  • ESLint version v8.12.0
  • eslint-plugin-jsdoc version: 38.1.1
@gajus
Copy link
Owner

gajus commented Mar 28, 2022

🎉 This issue has been resolved in version 38.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Mar 28, 2022
@bugwelle
Copy link
Author

bugwelle commented Mar 28, 2022

That was fast! I didn't expect this be fixed within 15min after reporting. That is amazing! 💯 🎉

Thank you very much, @brettz9 !

@brettz9
Copy link
Collaborator

brettz9 commented Mar 28, 2022

Sure, my pleasure. 🙏 I did a little more tightening just now in 38.1.3 though your particular example was fixed in 38.1.2.

crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this issue Mar 31, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [eslint-plugin-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc) | devDependencies | minor | [`38.0.8` -> `38.1.3`](https://renovatebot.com/diffs/npm/eslint-plugin-jsdoc/38.0.8/38.1.3) |

---

### Release Notes

<details>
<summary>gajus/eslint-plugin-jsdoc</summary>

### [`v38.1.3`](https://github.com/gajus/eslint-plugin-jsdoc/releases/v38.1.3)

[Compare Source](gajus/eslint-plugin-jsdoc@v38.1.2...v38.1.3)

##### Bug Fixes

-   **`check-types`, `no-undefined-types`:** safer optional chaining ([63a96ee](gajus/eslint-plugin-jsdoc@63a96ee))

### [`v38.1.2`](https://github.com/gajus/eslint-plugin-jsdoc/releases/v38.1.2)

[Compare Source](gajus/eslint-plugin-jsdoc@v38.1.1...v38.1.2)

##### Bug Fixes

-   **`check-types`:** proper use of optional chaining; fixes [#&#8203;861](gajus/eslint-plugin-jsdoc#861) ([7dbdd9f](gajus/eslint-plugin-jsdoc@7dbdd9f))

### [`v38.1.1`](https://github.com/gajus/eslint-plugin-jsdoc/releases/v38.1.1)

[Compare Source](gajus/eslint-plugin-jsdoc@v38.1.0...v38.1.1)

##### Bug Fixes

-   **`check-types`:** for `jsdoc` mode, avoid objecting to upper-case; fixes [#&#8203;860](gajus/eslint-plugin-jsdoc#860) ([d11d271](gajus/eslint-plugin-jsdoc@d11d271))

### [`v38.1.0`](https://github.com/gajus/eslint-plugin-jsdoc/releases/v38.1.0)

[Compare Source](gajus/eslint-plugin-jsdoc@v38.0.8...v38.1.0)

##### Features

-   unless the user supplies their own `object` type `preferredTypes`, prefer `object` for plain objects and otherwise prefer `Object<>`; fixes [#&#8203;800](gajus/eslint-plugin-jsdoc#800) ([#&#8203;855](gajus/eslint-plugin-jsdoc#855)) ([0f27282](gajus/eslint-plugin-jsdoc@0f27282))

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1262
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants