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

feat: run biome check on src files #556

Closed
wants to merge 3 commits into from

Conversation

jeremybarbet
Copy link
Contributor

@jeremybarbet jeremybarbet commented Feb 4, 2025

Summary

So there is already a biome lint command, but no check --write command to format following the json config.

  • Added yarn check alias of biome check --write
  • Run the command for all src files

I am not sure what's your preferences for the formatter config.

Originally it was:

"javascript": {
  "formatter": {
    "indentStyle": "tab",
    "indentWidth": 4,
  },
},
"json": {
  "formatter": {
    "indentStyle": "tab",
    "indentWidth": 2,
  },
}

However, all the files were manually formatted with spaces instead so I run the check --write with:

"javascript/json": {
  "formatter": {
    "indentStyle": "space",
    "indentWidth": 4,
  },
}

Let me know if you want to change that config to whatever you prefer. Just thinking formatting javascript/json with the same config makes the DX easier.

Edit:

  • Do you want to run biome check on the CI to make sure it's correctly formatted?

Copy link

vercel bot commented Feb 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-native-unistyles-2.0 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 5, 2025 0:24am
react-native-unistyles-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 5, 2025 0:24am

{mappedChildren}
</React.Fragment>
)
return <>{mappedChildren}</>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only line where I fixed a biome lint warning

Copy link
Owner

Choose a reason for hiding this comment

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

Can we force <React.Fragment>, I'm not a big fan of <></>

Copy link
Contributor Author

@jeremybarbet jeremybarbet Feb 5, 2025

Choose a reason for hiding this comment

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

Alright, in this case the warning was because the fragment was unnecessary so I removed it

@jpudysz
Copy link
Owner

jpudysz commented Feb 5, 2025

Hey @jeremybarbet thanks for the PR. I'm not sure I want this to be implemented as I'm not a big fan of how it formats the code.

I'm not sure if this should be configured further, but i will point the places.

{mappedChildren}
</React.Fragment>
)
return <>{mappedChildren}</>
Copy link
Owner

Choose a reason for hiding this comment

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

Can we force <React.Fragment>, I'm not a big fan of <></>

UnistylesShadowRegistry.add(ref, imageClassNames?.hash)
}}
ref={
isServer()
Copy link
Owner

Choose a reason for hiding this comment

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

what about it ? Can we tweak it? Looks bad

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as comment below, related to ternary formatting biomejs/biome#2388

const unistyles = typeof style === 'function'
? style({ pressed: false })
: style
const unistyles = typeof style === 'function' ? style({ pressed: false }) : style
Copy link
Owner

Choose a reason for hiding this comment

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

why it's once in multiple lines and sometimes in single line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the default Biome's formatting for ternary, there is a discussion opened about it but no away at the moment to configure it

? style(state)
: getStyles(style as unknown as Record<string, any>)
const unistyles =
typeof style === 'function' ? style(state) : getStyles(style as unknown as Record<string, any>)
Copy link
Owner

Choose a reason for hiding this comment

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

can we increase line width?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I increased it to 130 but it may happen if it goes over that limit

// @ts-expect-error hidden from TS
UnistylesShadowRegistry.add(storedRef, classNames?.hash)
ref={
isServer()
Copy link
Owner

Choose a reason for hiding this comment

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

same here

import { isServer } from '../../web/utils'

type Variants = Record<string, string | boolean | undefined>
type WebPressableState = {
pressed: boolean,
hovered: boolean,
pressed: boolean
Copy link
Owner

Choose a reason for hiding this comment

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

can we have commas in types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did change trailingCommas: 'none' to fix one of your comment below, but it then removes commas for both types and interfaces

}
}}
ref={
isServer()
Copy link
Owner

Choose a reason for hiding this comment

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

as above

src/core/warn.ts Outdated
const unistylesKeys = Object
.keys(style)
.filter(key => key.startsWith('unistyles-'))
const unistylesKeys = Object.keys(style).filter(key => key.startsWith('unistyles-'))
Copy link
Owner

Choose a reason for hiding this comment

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

what if I prefer my style?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added an example, you can do // biome-ignore format: I like it better this way but it's a bit cumbersome to do

@@ -42,6 +44,6 @@ export const useMedia = (config: { mq: symbol }) => {
useEffect(() => () => disposeRef.current(), [])

return {
isVisible
isVisible,
Copy link
Owner

Choose a reason for hiding this comment

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

im not sure about trailing commas

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it with trailingCommas: 'none'

@jeremybarbet
Copy link
Contributor Author

As stated in Biome documentation, their formatter is very opinionated, similar to how prettier works.

Unfortunately (or fortunately), it can't be configured in many ways. Which make sense, the goal is to create/follow an industry standard.

If you prefer to follow your own formatting, I would then suggest disabling the formatter all together. It would be too much of an hassle to use biome-ignore here and there and make your life even harder.

Alternative, is to not think about it, and let the formatter take all these decisions for you and let it handle for you. I used to be like you before and having a very strong opinion on how things should be formatted; then I tried prettier and never looked back.

Feel free to close this PR if you are not happy with the latest configuration changes. I'll be happy to open another PR to remove the formatter instead.

@jpudysz
Copy link
Owner

jpudysz commented Feb 6, 2025

I really appreciate your contribution, @jeremybarbet, as you've already submitted a few great PRs. I think I'm going to skip this one since we don't use any code formatters in Codemask. We have our own rules that neither Prettier nor Biome can support.

Of course, we might miss some spots, but that's okay.

I hope you won't be upset, as I know this took you some time.

@jpudysz jpudysz closed this Feb 6, 2025
@jeremybarbet
Copy link
Contributor Author

No worries, I understand! Thanks for taking the time to look at it!

Cheers

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.

2 participants