Skip to content

Commit

Permalink
update eslint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed Feb 18, 2025
1 parent 61fe685 commit 646f4f6
Show file tree
Hide file tree
Showing 51 changed files with 663 additions and 1,279 deletions.
8 changes: 6 additions & 2 deletions apps/main/app/+html.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ export default function Root({ children }: { children: React.ReactNode }) {
<style dangerouslySetInnerHTML={{ __html: responsiveBackground }} />
{/* Add any additional <head> elements that you want globally available on web... */}

<script dangerouslySetInnerHTML={{ __html: `
<script
dangerouslySetInnerHTML={{
__html: `
window.idbWorker = "/indexeddb.worker.js";
`}} />
`,
}}
/>
</head>
<body>{children}</body>
</html>
Expand Down
4 changes: 2 additions & 2 deletions apps/main/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import rules from "@wcpos/eslint-config";
export default rules;
import rules from '../../packages/eslint/index.js';
export default rules;
92 changes: 38 additions & 54 deletions apps/main/polyfills.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,51 @@
import * as Crypto from 'expo-crypto';

// Polyfill for global.crypto if it doesn't exist.
// Polyfill implementation for subtle.digest
// Note: This is only needed for DEV because of the RxDB schema validation
const subtlePolyfill = {
async digest(algorithm: string, data: BufferSource): Promise<ArrayBuffer> {
// Convert BufferSource to ArrayBuffer
let dataBuffer: ArrayBuffer;
if (data instanceof ArrayBuffer) {
dataBuffer = data;
} else if (ArrayBuffer.isView(data)) {
dataBuffer = data.buffer;
} else {
throw new Error('Unsupported data type for digest');
}

// Convert ArrayBuffer to a UTF-8 string.
// WARNING: This assumes that the input is valid UTF-8.
const decoded = new TextDecoder().decode(dataBuffer);

// Calculate digest as a hex string using Expo Crypto.
const digestHex = await Crypto.digestStringAsync(algorithm, decoded);

// Convert hex string back to ArrayBuffer.
const buffer = new ArrayBuffer(digestHex.length / 2);
const view = new Uint8Array(buffer);
for (let i = 0; i < digestHex.length; i += 2) {
view[i / 2] = parseInt(digestHex.substr(i, 2), 16);
}
return buffer;
},
};

if (typeof global.crypto === 'undefined') {
// If global.crypto doesn't exist, create it with a polyfill for getRandomValues.
global.crypto = {
// Polyfill getRandomValues
getRandomValues: <T extends ArrayBufferView | null>(buffer: T): T => {
if (!buffer) return buffer;
const ints = new Uint8Array(buffer.byteLength);
Crypto.getRandomValues(ints);
new Uint8Array(buffer.buffer).set(ints);
return buffer;
},
// Polyfill subtle if missing
subtle: {
async digest(algorithm: string, data: BufferSource): Promise<ArrayBuffer> {
// Convert BufferSource to ArrayBuffer
let dataBuffer: ArrayBuffer;
if (data instanceof ArrayBuffer) {
dataBuffer = data;
} else if (ArrayBuffer.isView(data)) {
dataBuffer = data.buffer;
} else {
throw new Error('Unsupported data type for digest');
}

// Convert ArrayBuffer to a UTF-8 string.
// WARNING: This assumes that the input is valid UTF-8.
const decoded = new TextDecoder().decode(dataBuffer);

// Calculate digest as a hex string using Expo Crypto.
const digestHex = await Crypto.digestStringAsync(algorithm, decoded);

// Convert hex string back to ArrayBuffer
const buffer = new ArrayBuffer(digestHex.length / 2);
const view = new Uint8Array(buffer);
for (let i = 0; i < digestHex.length; i += 2) {
view[i / 2] = parseInt(digestHex.substr(i, 2), 16);
}
return buffer;
},
},
};
} else if (typeof global.crypto.subtle === 'undefined') {
// If crypto exists but crypto.subtle is missing, add the subtle polyfill.
global.crypto.subtle = {
async digest(algorithm: string, data: BufferSource): Promise<ArrayBuffer> {
let dataBuffer: ArrayBuffer;
if (data instanceof ArrayBuffer) {
dataBuffer = data;
} else if (ArrayBuffer.isView(data)) {
dataBuffer = data.buffer;
} else {
throw new Error('Unsupported data type for digest');
}

const decoded = new TextDecoder().decode(dataBuffer);
const digestHex = await Crypto.digestStringAsync(algorithm, decoded);
const buffer = new ArrayBuffer(digestHex.length / 2);
const view = new Uint8Array(buffer);
for (let i = 0; i < digestHex.length; i += 2) {
view[i / 2] = parseInt(digestHex.substr(i, 2), 16);
}
return buffer;
},
// Only include subtle polyfill in the __DEV__ environment.
...(__DEV__ ? { subtle: subtlePolyfill } : {}),
};
} else if (__DEV__ && typeof global.crypto.subtle === 'undefined') {
// If global.crypto exists but subtle is missing and we're in __DEV__,
// add the subtle polyfill.
global.crypto.subtle = subtlePolyfill;
}
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import rules from "@wcpos/eslint-config";
import rules from "./packages/eslint/index.js";
export default rules;
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
"name": "@wcpos/monorepo",
"scripts": {
"clean": "node scripts/clean-node-modules",
"electron": "pnpm --filter @wcpos/app-electron",
"main": "pnpm --filter @wcpos/main",
"main:expo": "pnpm --filter @wcpos/main exec expo",
"components": "pnpm --filter @wcpos/components",
"core": "pnpm --filter @wcpos/core",
"database": "pnpm --filter @wcpos/database",
"eslint": "pnpm --filter @wcpos/eslint-config",
"hooks": "pnpm --filter @wcpos/hooks",
"query": "pnpm --filter @wcpos/query",
"utils": "pnpm --filter @wcpos/utils",
"main:expo": "pnpm --filter @wcpos/main exec expo",
"build:main": "turbo build --filter=\"...{./apps/main}\"",
"preinstall": "pnpm ignored-builds || true"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/components/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import rules from '../eslint/index.js';
export default rules;
4 changes: 2 additions & 2 deletions packages/components/src/accordian/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const AccordionItem = React.forwardRef<
<Animated.View className={'overflow-hidden'} layout={LinearTransition.duration(200)}>
<AccordionPrimitive.Item
ref={ref}
className={cn('border-b border-border', className)}
className={cn('border-border border-b', className)}
value={value}
{...props}
/>
Expand Down Expand Up @@ -85,7 +85,7 @@ const AccordionTrigger = React.forwardRef<
>
<>{children}</>
<Animated.View style={chevronStyle}>
<Icon name="chevronDown" className={'shrink-0 text-foreground'} />
<Icon name="chevronDown" className={'text-foreground shrink-0'} />
</Animated.View>
</Trigger>
</AccordionPrimitive.Trigger>
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/alert-dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ const AlertDialogContent = React.forwardRef<
<AlertDialogPrimitive.Content
ref={ref}
className={cn(
'z-50 max-w-lg gap-4 rounded-lg border border-border bg-background py-4',
'web:duration-200 shadow-lg shadow-foreground/10',
'border-border bg-background z-50 max-w-lg gap-4 rounded-lg border py-4',
'web:duration-200 shadow-foreground/10 shadow-lg',
open
? 'web:animate-in web:fade-in-0 web:zoom-in-95'
: 'web:animate-out web:fade-out-0 web:zoom-out-95',
Expand Down
34 changes: 17 additions & 17 deletions packages/components/src/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const ButtonText = Text;

const buttonVariants = cva(
[
'group flex flex-shrink items-center justify-center rounded-md max-w-full web:transition-colors',
'web:transition-colors group flex max-w-full flex-shrink items-center justify-center rounded-md',
'web:ring-offset-background web:focus-visible:outline-none web:focus-visible:ring-2 web:focus-visible:ring-ring web:focus-visible:ring-offset-1',
],
{
Expand All @@ -39,25 +39,25 @@ const buttonVariants = cva(
* Outline buttons
*/
outline:
'border border-input bg-background web:hover:bg-accent web:hover:text-accent-foreground active:bg-accent',
'border-input bg-background web:hover:bg-accent web:hover:text-accent-foreground active:bg-accent border',
'outline-primary':
'border border-primary bg-background web:hover:bg-primary/90 web:hover:text-primary-foreground active:bg-primary',
'border-primary bg-background web:hover:bg-primary/90 web:hover:text-primary-foreground active:bg-primary border',
'outline-secondary':
'border border-secondary bg-background web:hover:bg-secondary/90 web:hover:text-secondary-foreground active:bg-secondary',
'border-secondary bg-background web:hover:bg-secondary/90 web:hover:text-secondary-foreground active:bg-secondary border',
'outline-muted':
'border border-muted bg-background web:hover:bg-muted/90 web:hover:text-muted-foreground active:bg-muted',
'border-muted bg-background web:hover:bg-muted/90 web:hover:text-muted-foreground active:bg-muted border',
'outline-success':
'border border-success bg-background web:hover:bg-success/90 web:hover:text-success-foreground active:bg-success',
'border-success bg-background web:hover:bg-success/90 web:hover:text-success-foreground active:bg-success border',
'outline-destructive':
'border border-destructive bg-background web:hover:bg-destructive/90 web:hover:text-destructive-foreground active:bg-destructive',
'border-destructive bg-background web:hover:bg-destructive/90 web:hover:text-destructive-foreground active:bg-destructive border',
'outline-info':
'border border-info bg-background web:hover:bg-info/90 web:hover:text-info-foreground active:bg-info',
'border-info bg-background web:hover:bg-info/90 web:hover:text-info-foreground active:bg-info border',
'outline-attention':
'border border-attention bg-background web:hover:bg-attention/90 web:hover:text-attention-foreground active:bg-attention',
'border-attention bg-background web:hover:bg-attention/90 web:hover:text-attention-foreground active:bg-attention border',
'outline-warning':
'border border-warning bg-background web:hover:bg-warning/90 web:hover:text-warning-foreground active:bg-warning',
'border-warning bg-background web:hover:bg-warning/90 web:hover:text-warning-foreground active:bg-warning border',
'outline-error':
'border border-error bg-background web:hover:bg-error/90 web:hover:text-error-foreground active:bg-error',
'border-error bg-background web:hover:bg-error/90 web:hover:text-error-foreground active:bg-error border',

/**
* Ghost buttons
Expand All @@ -80,10 +80,10 @@ const buttonVariants = cva(
'ghost-error': 'bg-error/15 web:hover:bg-error active:bg-error text-error-foreground',
},
size: {
default: 'h-10 px-4 py-2 native:h-12 native:px-5 native:py-3',
default: 'native:h-12 native:px-5 native:py-3 h-10 px-4 py-2',
xs: 'h-6 rounded-md px-2',
sm: 'h-9 rounded-md px-3',
lg: 'h-11 rounded-md px-8 native:h-14',
lg: 'native:h-14 h-11 rounded-md px-8',
xl: 'h-14 rounded-md px-10',
},
},
Expand All @@ -96,7 +96,7 @@ const buttonVariants = cva(
);

const buttonTextVariants = cva(
'web:whitespace-nowrap truncate text-base native:text-base text-foreground web:transition-colors',
'web:whitespace-nowrap native:text-base text-foreground web:transition-colors truncate text-base',
{
variants: {
variant: {
Expand Down Expand Up @@ -278,13 +278,13 @@ const ButtonGroup: React.FC<ButtonGroupProps> = ({ children }) => {

if (index === 0) {
// first
classNames = cn(classNames, 'pr-2 rounded-r-none');
classNames = cn(classNames, 'rounded-r-none pr-2');
} else if (index === buttons.length - 1) {
// last
classNames = cn(classNames, 'pl-2 rounded-l-none');
classNames = cn(classNames, 'rounded-l-none pl-2');
} else {
// middle
classNames = cn(classNames, 'px-2 rounded-none');
classNames = cn(classNames, 'rounded-none px-2');
}

return (
Expand Down
6 changes: 3 additions & 3 deletions packages/components/src/card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Card = React.forwardRef<ViewRef, React.ComponentPropsWithoutRef<typeof Vie
<View
ref={ref}
className={cn(
'rounded-lg border border-border bg-card shadow-sm shadow-foreground/10',
'border-border bg-card shadow-foreground/10 rounded-lg border shadow-sm',
className
)}
{...props}
Expand All @@ -34,7 +34,7 @@ const CardTitle = React.forwardRef<TextRef, React.ComponentPropsWithoutRef<typeo
aria-level={3}
ref={ref}
className={cn(
'text-2xl font-semibold leading-none tracking-tight text-card-foreground',
'text-card-foreground text-2xl font-semibold leading-none tracking-tight',
className
)}
{...props}
Expand All @@ -45,7 +45,7 @@ CardTitle.displayName = 'CardTitle';

const CardDescription = React.forwardRef<TextRef, React.ComponentPropsWithoutRef<typeof Text>>(
({ className, ...props }, ref) => (
<Text ref={ref} className={cn('text-sm text-muted-foreground', className)} {...props} />
<Text ref={ref} className={cn('text-muted-foreground text-sm', className)} {...props} />
)
);
CardDescription.displayName = 'CardDescription';
Expand Down
10 changes: 5 additions & 5 deletions packages/components/src/chart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const ChartContainer = React.forwardRef<
data-chart={chartId}
ref={ref}
className={cn(
"flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-none [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-none [&_.recharts-surface]:outline-none",
"[&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border flex aspect-video justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-none [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-none [&_.recharts-surface]:outline-none",
className
)}
{...props}
Expand Down Expand Up @@ -160,7 +160,7 @@ const ChartTooltipContent = React.forwardRef<
<div
ref={ref}
className={cn(
'grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl',
'border-border/50 bg-background grid min-w-[8rem] items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl',
className
)}
>
Expand All @@ -175,7 +175,7 @@ const ChartTooltipContent = React.forwardRef<
<div
key={item.dataKey}
className={cn(
'flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground',
'[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5',
indicator === 'dot' && 'items-center'
)}
>
Expand Down Expand Up @@ -220,7 +220,7 @@ const ChartTooltipContent = React.forwardRef<
</span>
</div>
{item.value && (
<span className="font-mono font-medium tabular-nums text-foreground">
<span className="text-foreground font-mono font-medium tabular-nums">
{item.value.toLocaleString()}
</span>
)}
Expand Down Expand Up @@ -270,7 +270,7 @@ const ChartLegendContent = React.forwardRef<
<div
key={item.value}
className={cn(
'flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground'
'[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3'
)}
>
{itemConfig?.icon && !hideIcon ? (
Expand Down
6 changes: 3 additions & 3 deletions packages/components/src/checkbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Checkbox = React.forwardRef<React.ElementRef<typeof CheckboxPrimitive.Root
ref={ref}
className={cn(
'web:peer native:h-[20] native:w-[20] native:rounded',
'h-4 w-4 shrink-0 rounded-sm border border-border',
'border-border h-4 w-4 shrink-0 rounded-sm border',
'web:ring-offset-background web:focus-visible:outline-none web:focus-visible:ring-2 web:focus-visible:ring-ring web:focus-visible:ring-offset-1',
'disabled:cursor-not-allowed disabled:opacity-50',
props.checked && 'bg-primary',
Expand All @@ -28,11 +28,11 @@ const Checkbox = React.forwardRef<React.ElementRef<typeof CheckboxPrimitive.Root
>
{indeterminate ? (
<View className={cn('h-full w-full items-center justify-center')}>
<Icon name="minus" className="h-3 w-3 text-primary-foreground" />
<Icon name="minus" className="text-primary-foreground h-3 w-3" />
</View>
) : (
<CheckboxPrimitive.Indicator className={cn('h-full w-full items-center justify-center')}>
<Icon name="check" className="h-3 w-3 text-primary-foreground" />
<Icon name="check" className="text-primary-foreground h-3 w-3" />
</CheckboxPrimitive.Indicator>
)}
</CheckboxPrimitive.Root>
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/collapsible/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const CollapsibleTrigger = React.forwardRef<
<TextClassContext.Provider value="">
<CollapsiblePrimitive.Trigger
ref={ref}
className={cn('flex-row gap-2 items-center', className)}
className={cn('flex-row items-center gap-2', className)}
{...props}
>
{children}
Expand Down
6 changes: 3 additions & 3 deletions packages/components/src/combobox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ const ComboboxTrigger = React.forwardRef<TriggerRef, TriggerProps>(
ref={ref}
className={cn(
'native:h-12 flex h-10 flex-row items-center justify-between gap-2 px-3 py-2',
'text-sm text-muted-foreground',
'rounded-md border border-input bg-background',
'text-muted-foreground text-sm',
'border-input bg-background rounded-md border',
'web:ring-offset-background web:focus:outline-none web:focus:ring-2 web:focus:ring-ring web:focus:ring-offset-2',
'[&>span]:line-clamp-1',
props.disabled && 'web:cursor-not-allowed opacity-50',
Expand All @@ -182,7 +182,7 @@ const ComboboxValue = React.forwardRef<ValueRef, ValueProps>(
return (
<TextClassContext.Provider
value={cn(
'text-sm native:text-lg',
'native:text-lg text-sm',
value?.value ? 'text-foreground' : 'text-muted-foreground',
className
)}
Expand Down
Loading

0 comments on commit 646f4f6

Please sign in to comment.