Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

🐛 Formatter detaches // rome-ignore comment from associated logic expression #3734

Open
1 task done
lgarron opened this issue Nov 15, 2022 · 0 comments
Open
1 task done
Labels
A-Formatter Area: formatter S-Bug: confirmed Status: report has been confirmed as a valid bug S-Planned Status: planned by the team, but not in the short term

Comments

@lgarron
Copy link

lgarron commented Nov 15, 2022

Environment information

Rome CLI version 10.0.1

What happened?

Consider the following code (from @github/webauthn-json):

export function supported(): boolean {
  return !!(
    // rome-ignore lint(style/useOptionalChain): Optional chaining creates more complicated ES2019 code
    navigator.credentials &&
    navigator.credentials.create &&
    navigator.credentials.get &&
    window.PublicKeyCredential
  );
}

Playground link

The // rome-ignore comment works as intended.

However, as the playground shows, the formatter introduces parentheses around the && logic:

export function supported(): boolean {
  return !!(
    // rome-ignore lint(style/useOptionalChain): Optional chaining creates more complicated ES2019 code
    (
      navigator.credentials &&
      navigator.credentials.create &&
      navigator.credentials.get &&
      window.PublicKeyCredential
    )
  );
}

This disconnects the // rome-ignore comment, which in turn causes the linter to error again.

Expected result

The formatter doesn't break linter compatibility of the code.

Code of Conduct

  • I agree to follow Rome's Code of Conduct
@lgarron lgarron added the S-To triage Status: user report of a possible bug that needs to be triaged label Nov 15, 2022
@lgarron lgarron changed the title 🐛 Formatter detaches rome-lint comment from associated logic expression 🐛 Formatter detaches // rome-ignore comment from associated logic expression Nov 15, 2022
lgarron added a commit to github/webauthn-json that referenced this issue Nov 15, 2022
lgarron added a commit to github/webauthn-json that referenced this issue Nov 15, 2022
lgarron added a commit to github/webauthn-json that referenced this issue Nov 15, 2022
@ematipico ematipico added S-Bug: confirmed Status: report has been confirmed as a valid bug A-Formatter Area: formatter S-Planned Status: planned by the team, but not in the short term and removed S-To triage Status: user report of a possible bug that needs to be triaged labels Nov 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Formatter Area: formatter S-Bug: confirmed Status: report has been confirmed as a valid bug S-Planned Status: planned by the team, but not in the short term
Projects
None yet
Development

No branches or pull requests

2 participants