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

fix(rome_js_formatter): Arrow with JSX Body #3505

Merged
merged 1 commit into from
Oct 27, 2022
Merged

Conversation

MichaReiser
Copy link
Contributor

@MichaReiser MichaReiser commented Oct 26, 2022

This PR fixes two issues related to formatting arrow function expressions with an arrow body:

function ArrowBodyIsJsxWithComment({ action }) {
	return (action) => (
		// eslint-disable-next-line react/no-array-index-key
		<li />
	);
}

Keep the opening ( on the same line as the arrow for JSX Tag expressions with a leading comment.

<div
  onClick={() =>
    doSomething({
      foo: bar
    })
  }
/>;

Place the closing } of the arrow body on a new line if the arrow is inside a jsx attribute

Fixes #3377

Tests

I added new snapshot tests

@MichaReiser MichaReiser temporarily deployed to netlify-playground October 26, 2022 16:34 Inactive
@netlify
Copy link

netlify bot commented Oct 26, 2022

Deploy Preview for rometools ready!

Name Link
🔨 Latest commit d6de41b
🔍 Latest deploy log https://app.netlify.com/sites/rometools/deploys/635971bc7b081e000a2d0c9a
😎 Deploy Preview https://deploy-preview-3505--rometools.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
Copy link

github-actions bot commented Oct 26, 2022

@ematipico
Copy link
Contributor

It seems there are regressions in the test suite...

This PR fixes two issues related to formatting arrow function expressions with an arrow body:

```javascript
function ArrowBodyIsJsxWithComment({ action }) {
	return (action) => (
		// eslint-disable-next-line react/no-array-index-key
		<li />
	);
}

```

Keep the opening `(` on the same line as the arrow for JSX Tag expressions with a leading comment.

```javascript
<div
  onClick={() =>
    doSomething({
      foo: bar
    })
  }
/>;
```

Place the closing `}` of the arrow body on a new line if the arrow is inside a jsx attribute

## Tests

I added new snapshot tests
@MichaReiser MichaReiser requested a review from a team October 26, 2022 17:43
@MichaReiser MichaReiser temporarily deployed to netlify-playground October 26, 2022 17:43 Inactive
@MichaReiser MichaReiser merged commit c20f6da into main Oct 27, 2022
@MichaReiser MichaReiser deleted the fix/jsx-arrow branch October 27, 2022 11:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants