Skip to content

Fix placement of // @ts-expect-error comments in member chains - #19809

Open
santhiprakash wants to merge 4 commits into
prettier:mainfrom
santhiprakash:fix-ts-expect-error-member-chain-18121
Open

Fix placement of // @ts-expect-error comments in member chains#19809
santhiprakash wants to merge 4 commits into
prettier:mainfrom
santhiprakash:fix-ts-expect-error-member-chain-18121

Conversation

@santhiprakash

@santhiprakash santhiprakash commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #18121

When a // @ts-expect-error comment is placed on its own line before a member-chain continuation, Prettier was attaching it as a leading comment of the whole member expression and printing it before the first member. This moved the TypeScript directive away from the line it is meant to suppress.

The member-expression printer now detects non-trailing comments located between object and property and prints them before the lookup, keeping the directive on the correct continuation line.

Verification

  • Added tests/format/typescript/comments/18121.ts with a Jest snapshot covering the reported case.
  • yarn test tests/format/js tests/format/typescript β€” 25,509 tests passed.
  • yarn test tests/format/typescript/comments/format.test.js β€” 104 tests passed.
  • yarn lint:eslint src/language-js/print/member.js src/language-js/comments/will-print-own-comments.js passed.
  • yarn prettier --check on changed files passed.
  • yarn lint:changelog passed.

Checklist

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.
  • I did not use AI to generate this PR.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

When a comment like `// @ts-expect-error` is placed between the
object and the property of a member expression continuation, it was
being printed as a leading comment of the whole expression, hoisting
it before the first member. This prevented TypeScript from seeing the
directive on the line it is meant to suppress.

Now the printer detects a comment located between `object` and
`property` and prints it there, keeping the directive on the correct
continuation line.

Closes prettier#18121
@pkg-pr-new

pkg-pr-new Bot commented Aug 8, 2026

Copy link
Copy Markdown

Open in StackBlitz

yarn add https://pkg.pr.new/@prettier/plugin-hermes@19809.tgz
yarn add https://pkg.pr.new/@prettier/plugin-oxc@19809.tgz
yarn add https://pkg.pr.new/@prettier/plugin-yuku@19809.tgz
yarn add https://pkg.pr.new/prettier@19809.tgz

commit: 6c8363a

@santhiprakash

Copy link
Copy Markdown
Contributor Author

This PR is ready for review. The available token can create draft pull requests on prettier/prettier but does not have permission to call the markPullRequestReadyForReview GraphQL mutation (it requires contents:write on the upstream repo, which only collaborators have). Please mark it ready for review when convenient.

@netlify

netlify Bot commented Aug 8, 2026

Copy link
Copy Markdown

βœ… Deploy Preview for prettier ready!

Built without sensitive environment variables

Name Link
πŸ”¨ Latest commit c7b07b4
πŸ” Latest deploy log https://app.netlify.com/projects/prettier/deploys/6a76f03d7f3841000744af4f
😎 Deploy Preview https://deploy-preview-19809--prettier.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
πŸ€– Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 8, 2026

Copy link
Copy Markdown

βœ… Deploy Preview for prettier ready!

Built without sensitive environment variables

Name Link
πŸ”¨ Latest commit 6ad2978
πŸ” Latest deploy log https://app.netlify.com/projects/prettier/deploys/6a76f07530149e000891979e
😎 Deploy Preview https://deploy-preview-19809--prettier.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
πŸ€– Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 8, 2026

Copy link
Copy Markdown

βœ… Deploy Preview for prettier ready!

Built without sensitive environment variables

Name Link
πŸ”¨ Latest commit 6c8363a
πŸ” Latest deploy log https://app.netlify.com/projects/prettier/deploys/6a76f1ef60f64d000883236b
😎 Deploy Preview https://deploy-preview-19809--prettier.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
πŸ€– Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@santhiprakash
santhiprakash marked this pull request as ready for review August 16, 2026 20:51
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.

@ts-expect-error comment is moved to another line

1 participant