Skip to content

Commit

Permalink
feat: run biome check on src files
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremybarbet committed Feb 4, 2025
1 parent 2dee94f commit 807848b
Show file tree
Hide file tree
Showing 78 changed files with 919 additions and 773 deletions.
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}</>
}
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()
? 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

// @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>)

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
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()
? 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

0 comments on commit 807848b

Please sign in to comment.