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

fix(rome_formatter): Skipped token trivia spacing #3145

Merged
merged 1 commit into from
Sep 1, 2022

Conversation

MichaReiser
Copy link
Contributor

The formatting of JsxExpressionAttributeValue used to special handle the case when the } token has a skipped token trivia attached.

<div className={asdf asdf} />

The special handling ensured that the formatter inserts a whitespace between the expression and the skipped token trivia so that the above doesn't become

<div className={asdfasdf} />

The problem with the old solution is that it doesn't scale. We can't add these checks in every place where some skipped token trivia may be possibler (which, could be any node).

This PR improves the skipped token trivia formatting in rome formatter to account for any trailing whitespace of the previous token and preserves if it is followed by a skipped token trivia.

Tests

Verified that the test is still passing after removing the special handling in the attribute formatting.

<div className={asdf asdf} />;
<div className={asdf
/* comment */ asdf } />

@netlify
Copy link

netlify bot commented Sep 1, 2022

Deploy Preview for rometools canceled.

Name Link
🔨 Latest commit ac22cd6
🔍 Latest deploy log https://app.netlify.com/sites/rometools/deploys/6310a39effadac00085d4dd5

@MichaReiser MichaReiser added this to the 0.9.0 milestone Sep 1, 2022
@MichaReiser MichaReiser temporarily deployed to aws September 1, 2022 12:16 Inactive
The formatting of `JsxExpressionAttributeValue` used to special handle the case when the `}` token has a skipped token trivia attached.

```javascript
<div className={asdf asdf} />
```

The special handling ensured that the formatter inserts a whitespace between the expression and the skipped token trivia so that the above doesn't become

```javascript
<div className={asdfasdf} />
```

The problem with the old solution is that it doesn't scale. We can't add these checks in every place where some skipped token trivia may be possibler (which, could be any node).

This PR improves the skipped token trivia formatting in rome formatter to account for any trailing whitespace of the previous token and preserves if it is followed by a skipped token trivia.

## Tests

Verified that the test is still passing after removing the special handling in the attribute formatting.

https://github.com/rome/tools/blob/c6d0450c06e7bd357a3a30fab161c5537448fadc/crates/rome_js_formatter/tests/specs/jsx/attributes.jsx.snap#L54-L56
@MichaReiser MichaReiser force-pushed the fix/skipped-token-trivia-spacing branch from 122a1d5 to ac22cd6 Compare September 1, 2022 12:20
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Sep 1, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: ac22cd6
Status: ✅  Deploy successful!
Preview URL: https://e3726529.tools-8rn.pages.dev
Branch Preview URL: https://fix-skipped-token-trivia-spa.tools-8rn.pages.dev

View logs

@MichaReiser MichaReiser temporarily deployed to aws September 1, 2022 12:20 Inactive
@github-actions
Copy link

github-actions bot commented Sep 1, 2022

@ematipico ematipico added A-Formatter Area: formatter L-JSX Language: JSX labels Sep 1, 2022
@MichaReiser MichaReiser merged commit f016baf into main Sep 1, 2022
@MichaReiser MichaReiser deleted the fix/skipped-token-trivia-spacing branch September 1, 2022 16:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Formatter Area: formatter L-JSX Language: JSX
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants