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
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 50 additions & 50 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"files": {
"include": ["src/**/*.ts", "src/**/*.tsx"],
"ignore": ["example", "expo-example", "docs", "plugin", "lib"]
},
"formatter": {
"enabled": true,
"indentStyle": "tab"
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"suspicious": {
"noEmptyInterface": "off",
"noExplicitAny": "off"
},
"complexity": {
"noForEach": "off",
"noUselessSwitchCase": "off",
"noBannedTypes": "off"
},
"correctness": {
"useExhaustiveDependencies": "off"
}
}
},
"organizeImports": {
"enabled": true
},
"javascript": {
"formatter": {
"enabled": true,
"quoteStyle": "single",
"jsxQuoteStyle": "double",
"trailingCommas": "all",
"semicolons": "asNeeded",
"arrowParentheses": "asNeeded",
"indentStyle": "tab",
"indentWidth": 4,
"lineWidth": 120
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"files": {
"include": ["src/**/*.ts", "src/**/*.tsx"],
"ignore": ["example", "expo-example", "docs", "plugin", "lib"]
},
"globals": [],
"jsxRuntime": "reactClassic"
},
"json": {
"formatter": {
"enabled": true,
"indentWidth": 2,
"indentStyle": "tab",
"lineWidth": 120
"enabled": true,
"indentStyle": "space"
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"suspicious": {
"noEmptyInterface": "off",
"noExplicitAny": "off"
},
"complexity": {
"noForEach": "off",
"noUselessSwitchCase": "off",
"noBannedTypes": "off"
},
"correctness": {
"useExhaustiveDependencies": "off"
}
}
},
"organizeImports": {
"enabled": true
},
"javascript": {
"formatter": {
"enabled": true,
"quoteStyle": "single",
"jsxQuoteStyle": "double",
"trailingCommas": "all",
"semicolons": "asNeeded",
"arrowParentheses": "asNeeded",
"indentStyle": "space",
"indentWidth": 4,
"lineWidth": 120
},
"globals": [],
"jsxRuntime": "reactClassic"
},
"json": {
"formatter": {
"enabled": true,
"indentWidth": 4,
"indentStyle": "space",
"lineWidth": 120
}
}
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"test:coverage": "jest --passWithNoTests --coverage",
"tsc": "node_modules/typescript/bin/tsc --noEmit",
"lint": "biome lint",
"check": "biome check --write",
"prepare": "husky && bob build",
"precommit": "concurrently 'yarn tsc' 'yarn lint' 'yarn test'",
"release": "release-it"
Expand Down
4 changes: 1 addition & 3 deletions src/components/Display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ type DisplayProps = { mq: symbol } & PropsWithChildren
export const Display: React.FunctionComponent<DisplayProps> = ({ children, ...props }) => {
const { isVisible } = useMedia(props)

return isVisible
? children
: null
return isVisible ? children : null
}
4 changes: 1 addition & 3 deletions src/components/Hide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ type HideProps = { mq: symbol } & PropsWithChildren
export const Hide: React.FunctionComponent<HideProps> = ({ children, ...props }) => {
const { isVisible } = useMedia(props)

return !isVisible
? children
: null
return !isVisible ? children : null
}
8 changes: 2 additions & 6 deletions src/components/ScopedTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ export const ScopedTheme: React.FunctionComponent<React.PropsWithChildren<ThemeP
const mappedChildren = [
<Apply key={name} name={name} />,
children,
<Apply key='dispose' name={previousScopedTheme as keyof UnistylesThemes | undefined} />
<Apply key="dispose" name={previousScopedTheme as keyof UnistylesThemes | undefined} />,
]

return (
<React.Fragment>
{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

}
6 changes: 3 additions & 3 deletions src/components/native/Animated.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Animated as RNAnimated } from 'react-native'
import { View } from './View'
import { Text } from './Text'
import { FlatList } from './FlatList'
import { Image } from './Image'
import { ScrollView } from './ScrollView'
import { SectionList } from './SectionList'
import { Text } from './Text'
import { View } from './View'

export const Animated = {
...RNAnimated,
Expand All @@ -13,5 +13,5 @@ export const Animated = {
FlatList: RNAnimated.createAnimatedComponent(FlatList),
Image: RNAnimated.createAnimatedComponent(Image),
ScrollView: RNAnimated.createAnimatedComponent(ScrollView),
SectionList: RNAnimated.createAnimatedComponent(SectionList)
SectionList: RNAnimated.createAnimatedComponent(SectionList),
}
72 changes: 40 additions & 32 deletions src/components/native/ImageBackground.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react'
import { ImageBackground as NativeImageBackground } from 'react-native'
import { forwardRef } from 'react'
import type { UnistylesValues } from '../../types'
import { ImageBackground as NativeImageBackground } from 'react-native'
import { getClassName } from '../../core'
import { isServer } from '../../web/utils'
import { UnistylesShadowRegistry } from '../../web'
import type { UnistylesValues } from '../../types'
import { copyComponentProperties } from '../../utils'
import { UnistylesShadowRegistry } from '../../web'
import { isServer } from '../../web/utils'

type Props = {
style?: UnistylesValues
Expand All @@ -24,34 +24,42 @@ const UnistylesImageBackground = forwardRef<unknown, Props>((props, forwardedRef
{...props}
style={styleClassNames}
imageStyle={imageClassNames}
ref={isServer() ? undefined : ref => {
if (!ref) {
// @ts-expect-error hidden from TS
UnistylesShadowRegistry.remove(storedRef, styleClassNames?.hash)
}

storedRef = ref
// @ts-expect-error hidden from TS
UnistylesShadowRegistry.add(ref, styleClassNames?.hash)

if (typeof forwardedRef === 'function') {
return forwardedRef(ref)
}

if (forwardedRef) {
forwardedRef.current = ref
}
}}
imageRef={isServer() ? undefined : ref => {
if (!ref) {
// @ts-expect-error hidden from TS
UnistylesShadowRegistry.remove(storedImageRef, imageClassNames?.hash)
}

storedImageRef = ref
// @ts-expect-error hidden from TS
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

? undefined
: ref => {
if (!ref) {
// @ts-expect-error hidden from TS
UnistylesShadowRegistry.remove(storedRef, styleClassNames?.hash)
}

storedRef = ref
// @ts-expect-error hidden from TS
UnistylesShadowRegistry.add(ref, styleClassNames?.hash)

if (typeof forwardedRef === 'function') {
return forwardedRef(ref)
}

if (forwardedRef) {
forwardedRef.current = ref
}
}
}
imageRef={
isServer()
? undefined
: ref => {
if (!ref) {
// @ts-expect-error hidden from TS
UnistylesShadowRegistry.remove(storedImageRef, imageClassNames?.hash)
}

storedImageRef = ref
// @ts-expect-error hidden from TS
UnistylesShadowRegistry.add(ref, imageClassNames?.hash)
}
}
/>
)
})
Expand Down
2 changes: 1 addition & 1 deletion src/components/native/NativeText.native.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { TextProps } from 'react-native'
import { type ComponentType, createElement, forwardRef } from 'react'
import type { TextProps } from 'react-native'
import { createUnistylesElement } from '../../core'

// credits to @hirbod
Expand Down
2 changes: 1 addition & 1 deletion src/components/native/NativeView.native.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ViewProps } from 'react-native'
import { type ComponentType, createElement, forwardRef } from 'react'
import type { ViewProps } from 'react-native'
import { createUnistylesElement } from '../../core'

// credits to @hirbod
Expand Down
17 changes: 6 additions & 11 deletions src/components/native/Pressable.native.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import React, { forwardRef, useLayoutEffect, useRef } from 'react'
import { Pressable as NativePressableReactNative } from 'react-native'
import type { PressableProps as Props, View } from 'react-native'
import { UnistylesShadowRegistry } from '../../specs'
import { passForwardedRef } from '../../core'
import { UnistylesShadowRegistry } from '../../specs'

type PressableProps = Props & {
variants?: Record<string, string | boolean>
}

const getStyles = (styleProps: Record<string, any> = {}) => {
const unistyleKey = Object
.keys(styleProps)
.find(key => key.startsWith('unistyles-'))
const unistyleKey = Object.keys(styleProps).find(key => key.startsWith('unistyles-'))

if (!unistyleKey) {
return styleProps
Expand All @@ -20,7 +18,7 @@ const getStyles = (styleProps: Record<string, any> = {}) => {
return {
// styles without C++ state
...styleProps[unistyleKey].uni__getStyles(),
[unistyleKey]: styleProps[unistyleKey].uni__getStyles()
[unistyleKey]: styleProps[unistyleKey].uni__getStyles(),
}
}

Expand All @@ -40,9 +38,7 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ..
<NativePressableReactNative
{...props}
ref={ref => {
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


// @ts-expect-error - this is hidden from TS
UnistylesShadowRegistry.add(ref, unistyles)
Expand All @@ -54,9 +50,8 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ..
return passForwardedRef(props, ref, forwardedRef)
}}
style={state => {
const unistyles = typeof style === 'function'
? 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


if (!storedRef.current) {
return unistyles
Expand Down
38 changes: 20 additions & 18 deletions src/components/native/Pressable.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import React, { forwardRef } from 'react'
import { Pressable as NativePressableReactNative } from 'react-native'
import type { PressableProps as Props, View } from 'react-native'
import { getClassName } from '../../core'
import { UnistylesShadowRegistry } from '../../specs'
import type { UnistylesValues } from '../../types'
import { getClassName } from '../../core'
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

hovered: boolean
focused: boolean
}

type WebPressableStyle = ((state: WebPressableState) => UnistylesValues) | UnistylesValues

type PressableProps = Props & {
variants?: Variants
style?: WebPressableStyle,
style?: WebPressableStyle
}

export const Pressable = forwardRef<View, PressableProps>(({ style, ...props }, forwardedRef) => {
Expand All @@ -28,23 +28,25 @@ export const Pressable = forwardRef<View, PressableProps>(({ style, ...props },
return (
<NativePressableReactNative
{...props}
ref={isServer() ? undefined : ref => {
storedRef = ref as unknown as HTMLElement
// @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

? undefined
: ref => {
storedRef = ref as unknown as HTMLElement
// @ts-expect-error hidden from TS
UnistylesShadowRegistry.add(storedRef, classNames?.hash)

if (typeof forwardedRef === 'function') {
return forwardedRef(ref)
}
if (typeof forwardedRef === 'function') {
return forwardedRef(ref)
}

if (forwardedRef) {
forwardedRef.current = ref
}
}}
if (forwardedRef) {
forwardedRef.current = ref
}
}
}
style={state => {
const styleResult = typeof style === 'function'
? style(state as WebPressableState)
: style
const styleResult = typeof style === 'function' ? style(state as WebPressableState) : style
const previousScopedTheme = UnistylesShadowRegistry.getScopedTheme()

UnistylesShadowRegistry.setScopedTheme(scopedTheme)
Expand Down
2 changes: 1 addition & 1 deletion src/core/createUnistylesElement.native.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useLayoutEffect, useRef } from 'react'
import { UnistylesShadowRegistry } from '../specs'
import { copyComponentProperties } from '../utils'
import { passForwardedRef } from './passForwardRef'
import { maybeWarnAboutMultipleUnistyles } from './warn'
import { copyComponentProperties } from '../utils'

const getNativeRef = (Component: any, ref: any) => {
switch (Component.name) {
Expand Down
Loading