Skip to content

fix: fix unsafe property access#21

Merged
brettz9 merged 2 commits into
es-joy:mainfrom
ntnyq:fix/jsdoccomment
Jun 22, 2025
Merged

fix: fix unsafe property access#21
brettz9 merged 2 commits into
es-joy:mainfrom
ntnyq:fix/jsdoccomment

Conversation

@ntnyq
Copy link
Copy Markdown
Contributor

@ntnyq ntnyq commented Jun 22, 2025

This PR fixes the issue occurs while accessing an unsafe property.

Issue reproduction:

https://github.com/ntnyq/eslint-plugin-ntnyq/actions/runs/15802108983/job/44541751654?pr=126

Copilot AI review requested due to automatic review settings June 22, 2025 09:07
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

A concise fix to improve safety when accessing properties in getJSDocComment by using optional chaining.

  • Changed unsafe property access of prevSibling.declaration.type to use optional chaining.
  • Ensured consistency in safely accessing properties for TSDeclareFunction checks.

@brettz9
Copy link
Copy Markdown
Contributor

brettz9 commented Jun 22, 2025

Thanks! Can I ask though--do you happen to know what the triggering code was?

@brettz9
Copy link
Copy Markdown
Contributor

brettz9 commented Jun 22, 2025

Also, looks like I needed to bump package.json engines to >=20.11.0 and update CI. Done. Would you mind rebasing on my latest commit?

BREAKING CHANGE:

Requires Node >= 20.11.0
@brettz9 brettz9 merged commit c28693a into es-joy:main Jun 22, 2025
@brettz9
Copy link
Copy Markdown
Contributor

brettz9 commented Jun 22, 2025

Released as part of v0.52.0 ... I'll look to add to eslint-plugin-jsdoc now as well.

@ntnyq
Copy link
Copy Markdown
Contributor Author

ntnyq commented Jun 22, 2025

The error happens while linting this line of code

https://github.com/ntnyq/eslint-plugin-ntnyq/blob/775405a5a684ccaa2aa6c76b5ad13c7d6d30e715/tests/internal.ts#L10

prevSibling is type ExportNamedDeclaration and has no declaration property.

@brettz9
Copy link
Copy Markdown
Contributor

brettz9 commented Jun 22, 2025

Ah, thanks! So there is such a thing as a declaration without a declaration--go figure! :-)

eslint-plugin-jsdoc updated with v51.1.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants