Skip to content

Commit

Permalink
chore: migrate biome (#87)
Browse files Browse the repository at this point in the history
* fix: multiple linkBridge

* fix: by id

* fix: space

* fix: indent

* chore: migrate biome

* fix: integration
  • Loading branch information
gronxb authored Dec 7, 2024
1 parent c11d382 commit ff6eec9
Show file tree
Hide file tree
Showing 25 changed files with 181 additions and 564 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

31 changes: 0 additions & 31 deletions .eslintrc.cjs

This file was deleted.

4 changes: 3 additions & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ jobs:
- name: Build
run: pnpm build
- name: TypeScript type check
run: pnpm test:type
run: pnpm test:type
- name: Lint
run: pnpm lint
9 changes: 0 additions & 9 deletions .prettierrc

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"biome.enabled": false
"editor.defaultFormatter": "biomejs.biome",
}
37 changes: 37 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
"useIgnoreFile": false
},
"files": {
"ignoreUnknown": false,
"ignore": ["dist"]
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 80,
"formatWithErrors": false
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"suspicious": {
"noExplicitAny": "off"
},
"recommended": true
}
},
"javascript": {
"formatter": {
"quoteStyle": "double",
"arrowParentheses": "always"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1930,4 +1930,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: b7e7ae708ca8909a3d4daa7855fda2822c325bc2

COCOAPODS: 1.15.2
COCOAPODS: 1.16.2
12 changes: 3 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"build": "nx run-many --target=build --projects=packages/*",
"build:dev": "nx run-many --target=build --projects=packages/* --watch",
"test:type": "nx run-many --target=test:type --all",
"lint": "nx run-many --target=lint --projects=packages/*",
"docs:build": "nx docs:build @webview-bridge/docs",
"clear": "rimraf --glob **/dist",
"release:test": "nx release --dry-run",
Expand All @@ -19,23 +20,16 @@
"license": "MIT",
"devDependencies": {
"@babel/runtime": "^7.25.0",
"@biomejs/biome": "^1.9.4",
"@nx/js": "^20.0.6",
"@swc-node/register": "^1.10.9",
"@swc/core": "^1.7.40",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"eslint": "^8.51.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-simple-import-sort": "^10.0.0",
"nx": "20.0.5",
"prettier": "^3.0.3",
"rimraf": "^5.0.5",
"tsup": "^8.3.0",
"typescript": "^5.6.2"
},
"packageManager": "pnpm@9.12.2",
"packageManager": "pnpm@9.15.0",
"pnpm": {
"overrides": {
"@webview-bridge/types": "workspace:*",
Expand Down
9 changes: 3 additions & 6 deletions packages/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@
"url": "https://github.com/gronxb/webview-bridge.git"
},
"license": "MIT",
"files": [
"dist",
"src",
"package.json"
],
"files": ["dist", "src", "package.json"],
"scripts": {
"build": "tsup src/index.ts --format cjs,esm --dts --target es5",
"test:type": "tsc --noEmit"
"test:type": "tsc --noEmit",
"lint": "biome check"
},
"devDependencies": {
"@types/react": "^18.2.25",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Bridge } from "@webview-bridge/types";
import {
type EventEmitter,
createRandomId,
createResolver,
type EventEmitter,
timeout,
} from "@webview-bridge/utils";
import WebView from "react-native-webview";
import type WebView from "react-native-webview";

import { WebMethodError } from "../error";

Expand Down
5 changes: 3 additions & 2 deletions packages/react-native/src/types/webview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component } from "react";
import WebView, { WebViewProps } from "react-native-webview";
import type { Component } from "react";
import type WebView from "react-native-webview";
import type { WebViewProps } from "react-native-webview";

export type BridgeWebView = Pick<
WebView,
Expand Down
8 changes: 3 additions & 5 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
"url": "https://github.com/gronxb/webview-bridge.git"
},
"license": "MIT",
"files": [
"dist",
"package.json"
],
"files": ["dist", "package.json"],
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -27,7 +24,8 @@
},
"scripts": {
"build": "tsup src/index.ts --format cjs,esm --dts --target es5",
"test:type": "tsc --noEmit"
"test:type": "tsc --noEmit",
"lint": "biome check"
},
"devDependencies": {
"@types/react": "^18.2.69",
Expand Down
11 changes: 6 additions & 5 deletions packages/react/src/createLinkBridgeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import type {
import type { LinkBridgeOptions } from "@webview-bridge/web";
import { linkBridge } from "@webview-bridge/web";
import {
createContext,
type ReactNode,
createContext,
useContext,
useEffect,
useRef,
Expand Down Expand Up @@ -52,7 +52,7 @@ export const createLinkBridgeProvider = <
const bridgeStoreContext = useContext(BridgeContext);

if (!bridgeStoreContext) {
throw new Error(`useBridgeStore must be used within a BridgeProvider`);
throw new Error("useBridgeStore must be used within a BridgeProvider");
}

return useBridge(bridgeStoreContext.store, selector as (state: T) => U);
Expand All @@ -62,7 +62,7 @@ export const createLinkBridgeProvider = <
const bridgeStoreContext = useContext(BridgeContext);

if (!bridgeStoreContext) {
throw new Error(`useBridgeStatus must be used within a BridgeProvider`);
throw new Error("useBridgeStatus must be used within a BridgeProvider");
}

return {
Expand All @@ -77,7 +77,7 @@ export const createLinkBridgeProvider = <
const bridgeStoreContext = useContext(BridgeContext);

if (!bridgeStoreContext) {
throw new Error(`useBridgeLoose must be used within a BridgeProvider`);
throw new Error("useBridgeLoose must be used within a BridgeProvider");
}

return { loose: bridgeStoreContext.loose };
Expand All @@ -91,9 +91,10 @@ export const createLinkBridgeProvider = <

if (!bridgeStoreContext) {
throw new Error(
`useBridgeEventListener must be used within a BridgeProvider`,
"useBridgeEventListener must be used within a BridgeProvider",
);
}
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
useEffect(() => {
return bridgeStoreContext.addEventListener(eventName, listener);
}, []);
Expand Down
2 changes: 1 addition & 1 deletion packages/react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"include": ["src"]
}
8 changes: 3 additions & 5 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"name": "@webview-bridge/types",
"type": "module",
"version": "1.7.2",
"files": [
"src",
"package.json"
],
"files": ["src", "package.json"],
"main": "src/index.ts",
"module": "src/index.ts",
"types": "src/index.ts",
Expand All @@ -26,7 +23,8 @@
"license": "MIT",
"scripts": {
"build": "tsup src/index.ts --dts",
"test:type": "tsc --noEmit"
"test:type": "tsc --noEmit",
"lint": "biome check"
},
"devDependencies": {
"@types/node": "^22.7.9"
Expand Down
8 changes: 4 additions & 4 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export type Parser<
> = Input extends undefined
? Record<string, Primitive> | Primitive
: EventName extends keyof Input
? Input[EventName]["validate"] extends (data: unknown) => unknown
? ReturnType<Input[EventName]["validate"]>
: Record<string, Primitive> | Primitive
: never;
? Input[EventName]["validate"] extends (data: unknown) => unknown
? ReturnType<Input[EventName]["validate"]>
: Record<string, Primitive> | Primitive
: never;
9 changes: 3 additions & 6 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
"name": "@webview-bridge/utils",
"type": "module",
"version": "1.7.2",
"files": [
"dist",
"src",
"package.json"
],
"files": ["dist", "src", "package.json"],
"react-native": "src/index.ts",
"main": "dist/index.cjs",
"module": "dist/index.js",
Expand All @@ -28,7 +24,8 @@
"license": "MIT",
"scripts": {
"build": "tsup src/index.ts --format cjs,esm --dts --target es5",
"test:type": "tsc --noEmit"
"test:type": "tsc --noEmit",
"lint": "biome check"
},
"devDependencies": {
"@types/node": "^22.7.9"
Expand Down
6 changes: 5 additions & 1 deletion packages/utils/src/createEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export const createEvents = <
}
},
on(event, cb) {
this.events[event]?.push(cb) || (this.events[event] = [cb]);
if (!this.events[event]) {
this.events[event] = [cb];
} else {
this.events[event]?.push(cb);
}
return () => {
this.events[event] = this.events[event]?.filter((i) => cb !== i);
};
Expand Down
7 changes: 4 additions & 3 deletions packages/utils/src/equals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export const equals = (a: any, b: any) => {
if (a && b && typeof a === "object" && typeof b === "object") {
const arrA = Array.isArray(a);
const arrB = Array.isArray(b);
let i;
let length;
let key;
let i: number;
let length: number;
let key: string;

if (arrA && arrB) {
length = a.length;
Expand Down Expand Up @@ -49,5 +49,6 @@ export const equals = (a: any, b: any) => {
return true;
}

// biome-ignore lint/suspicious/noSelfCompare: <explanation>
return a !== a && b !== b;
};
4 changes: 2 additions & 2 deletions packages/utils/src/removeUndefinedKeys.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const removeUndefinedKeys = (obj: Record<string, any>) => {
Object.keys(obj).forEach((key) => {
for (const key of Object.keys(obj)) {
if (obj[key] === undefined) {
delete obj[key];
}
});
}
return obj;
};
2 changes: 1 addition & 1 deletion packages/utils/src/timeout.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const timeout = (ms: number, throwOnError: boolean = true) => {
export const timeout = (ms: number, throwOnError = true) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (throwOnError) {
Expand Down
8 changes: 3 additions & 5 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
"url": "https://github.com/gronxb/webview-bridge.git"
},
"license": "MIT",
"files": [
"dist",
"package.json"
],
"files": ["dist", "package.json"],
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -27,7 +24,8 @@
},
"scripts": {
"build": "tsup src/index.ts --format cjs,esm --dts --target es5",
"test:type": "tsc --noEmit"
"test:type": "tsc --noEmit",
"lint": "biome check"
},
"dependencies": {
"@webview-bridge/utils": "1.7.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/internal/linkBridgeStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Bridge, BridgeStore, OnlyJSON } from "@webview-bridge/types";
import {
DefaultEmitter,
type DefaultEmitter,
equals,
removeUndefinedKeys,
} from "@webview-bridge/utils";
Expand Down
Loading

0 comments on commit ff6eec9

Please sign in to comment.