Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format Babel plugin test inputs #4356

Merged
merged 3 commits into from
Apr 13, 2023
Merged

Conversation

tomekzaw
Copy link
Member

@tomekzaw tomekzaw commented Apr 12, 2023

Summary

This PR changes the way how JavaScript code snippets are embedded in Reanimated Babel plugin unit tests so that the code can be properly formatted and indented using Prettier.

For details on --embedded-language-formatting, see here and here. Unfortunately, it looks like currently Prettier doesn't support js code tag directly (see prettier/prettier#5993). The workaround is to use html code tag and embed the JavaScript code in HTML <script> tag.

Note
Dear future reader, if you wish to embed TypeScript code, e.g. useSharedValue<number>(42), you will need to specify lang="ts" attribute for the <script> tag and also modify the implementation of runPlugin function.

Test plan

  1. Break formatting in some code input in __tests__/plugin.test.js
  2. Confirm that yarn lint:js fails
  3. Run yarn format:js
  4. Confirm that the file has been formatted properly
  5. Break formatting again
  6. Stage the changes
  7. Confirm that git commit fails due to an empty commit

@tomekzaw tomekzaw marked this pull request as ready for review April 12, 2023 15:11
Copy link
Contributor

@tjzel tjzel left a comment

Choose a reason for hiding this comment

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

㊗️ on your PR

@tomekzaw tomekzaw added this pull request to the merge queue Apr 13, 2023
Merged via the queue into main with commit 3891d09 Apr 13, 2023
8 checks passed
@tomekzaw tomekzaw deleted the @tomekzaw/format-plugin-test-input branch April 13, 2023 10:27
fluiddot pushed a commit to wordpress-mobile/react-native-reanimated that referenced this pull request Jun 5, 2023
## Summary

This PR changes the way how JavaScript code snippets are embedded in
Reanimated Babel plugin unit tests so that the code can be properly
formatted and indented using Prettier.

For details on `--embedded-language-formatting`, see
[here](https://prettier.io/blog/2020/08/24/2.1.0.html) and
[here](https://github.com/thorn0/prettier/blob/master/src/language-js/embed.js).
Unfortunately, it looks like currently Prettier doesn't support `js`
code tag directly (see prettier/prettier#5993).
The workaround is to use `html` code tag and embed the JavaScript code
in HTML `<script>` tag.

> **Note**
> Dear future reader, if you wish to embed TypeScript code, e.g.
`useSharedValue<number>(42)`, you will need to specify `lang="ts"`
attribute for the `<script>` tag and also modify the implementation of
`runPlugin` function.


## Test plan

1. Break formatting in some code input in `__tests__/plugin.test.js`
2. Confirm that `yarn lint:js` fails
3. Run `yarn format:js`
4. Confirm that the file has been formatted properly
5. Break formatting again
6. Stage the changes
7. Confirm that `git commit` fails due to an empty commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants