Skip to content

Commit 8ade088

Browse files
authored
Enable code formatting in CI pipeline (#60)
* Add formatting configuration and format codebase * remove vendor from biome
1 parent ed0fe81 commit 8ade088

30 files changed

+202
-176
lines changed

.github/workflows/main.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,29 @@ jobs:
2929
- name: Lint
3030
run: yarn lint
3131

32+
format:
33+
name: Format Check
34+
runs-on: ubuntu-latest
35+
defaults:
36+
run:
37+
working-directory: ./
38+
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v4
42+
43+
- name: Checkout node action
44+
uses: actions/setup-node@v4
45+
with:
46+
node-version-file: '.nvmrc'
47+
cache-dependency-path: 'yarn.lock'
48+
49+
- name: 'Setup'
50+
uses: ./.github/actions/setup
51+
52+
- name: Format Check
53+
run: yarn format:check
54+
3255
typecheck:
3356
name: Type Check
3457
runs-on: ubuntu-latest

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ Use `yarn dev` to start the example app and build the package with hot reloading
7474

7575
This project uses [Biome](https://github.com/biomejs/biome) for linting and formatting. See the [Biome docs](https://biomejs.dev/guides/editors/first-party-extensions/) for more information on how to configure your editor to use Biome.
7676

77+
Available commands:
78+
- `yarn lint` - Run linting checks on all workspaces
79+
- `yarn format` - Format all files in all workspaces
80+
- `yarn format:check` - Check if all files are properly formatted without making changes
81+
82+
It's recommended to run `yarn format` before committing your changes to ensure consistent code formatting across the project.
83+
7784
### Signing Commits
7885

7986
All commits need to be signed with a GPG key. This adds a second factor of authentication that proves that it came from

biome.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"**/build",
2828
"**/dist",
2929
"**/node_modules",
30-
"**/src/vendor-js",
30+
"**/vendor-js/**",
3131
"**/*-css.ts",
3232
"**/*-svg.ts"
3333
]
@@ -163,7 +163,6 @@
163163
"**/dist",
164164
"**/node_modules",
165165
"**/vendor-js/**",
166-
"**/src/vendor-js/**",
167166
"**/*.json"
168167
]
169168
},

examples/testapp/config/headers.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
function getCrossOriginOpenerPolicyHeaders() {
2-
return {
3-
source: "/",
4-
headers: [
5-
{
6-
key: "Cross-Origin-Opener-Policy",
7-
value: "same-origin",
8-
},
9-
]
10-
}
2+
return {
3+
source: '/',
4+
headers: [
5+
{
6+
key: 'Cross-Origin-Opener-Policy',
7+
value: 'same-origin',
8+
},
9+
],
10+
};
1111
}
1212

13-
// To test these headers in your local environment,
13+
// To test these headers in your local environment,
1414
// create a next.config and add the following rules to the next.config.js headers property.
1515
module.exports = {
16-
getCrossOriginOpenerPolicyHeaders
17-
}
16+
getCrossOriginOpenerPolicyHeaders,
17+
};

examples/testapp/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"dev": "next dev --port 3001",
88
"export": "yarn build && touch ./out/.nojekyll",
99
"lint": "biome lint .",
10+
"format": "biome format . --write",
11+
"format:check": "biome check . --formatter-enabled=true --linter-enabled=false --organize-imports-enabled=false",
1012
"start": "next start",
1113
"test": "vitest",
1214
"typecheck": "tsc --noEmit"

examples/testapp/src/components/EventListeners/EventListenersCard.tsx

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@ import { ProviderConnectInfo } from 'viem';
55
import { useEIP1193Provider } from '../../context/EIP1193ProviderContextProvider';
66

77
export function EventListenersCard() {
8-
const [connect, setConnect] = React.useState<ProviderConnectInfo | null>(
9-
null
10-
);
8+
const [connect, setConnect] = React.useState<ProviderConnectInfo | null>(null);
119
const [disconnect, setDisconnect] = React.useState<{
1210
code: number;
1311
message: string;
1412
} | null>(null);
15-
const [accountsChanged, setAccountsChanged] = React.useState<string[] | null>(
16-
null
17-
);
13+
const [accountsChanged, setAccountsChanged] = React.useState<string[] | null>(null);
1814
const [chainChanged, setChainChanged] = React.useState<string | null>(null);
1915

2016
const { provider } = useEIP1193Provider();
@@ -23,12 +19,9 @@ export function EventListenersCard() {
2319
setConnect(info);
2420
}, []);
2521

26-
const handleDisconnect = useCallback(
27-
(error: { code: number; message: string }) => {
28-
setDisconnect({ code: error.code, message: error.message });
29-
},
30-
[]
31-
);
22+
const handleDisconnect = useCallback((error: { code: number; message: string }) => {
23+
setDisconnect({ code: error.code, message: error.message });
24+
}, []);
3225

3326
const handleAccountsChanged = useCallback((accounts: string[]) => {
3427
setAccountsChanged(accounts);
@@ -53,13 +46,7 @@ export function EventListenersCard() {
5346
provider?.removeListener('accountsChanged', handleAccountsChanged);
5447
provider?.removeListener('chainChanged', handleChainChanged);
5548
};
56-
}, [
57-
provider,
58-
handleConnect,
59-
handleDisconnect,
60-
handleAccountsChanged,
61-
handleChainChanged,
62-
]);
49+
}, [provider, handleConnect, handleDisconnect, handleAccountsChanged, handleChainChanged]);
6350

6451
return (
6552
<Card shadow="lg">
@@ -71,14 +58,7 @@ export function EventListenersCard() {
7158
</Heading>
7259
</Flex>
7360
{accountsChanged && (
74-
<Code
75-
mt={2}
76-
as="pre"
77-
p={4}
78-
wordBreak="break-word"
79-
whiteSpace="pre-wrap"
80-
w="100%"
81-
>
61+
<Code mt={2} as="pre" p={4} wordBreak="break-word" whiteSpace="pre-wrap" w="100%">
8262
{JSON.stringify(accountsChanged, null, 2)}
8363
</Code>
8464
)}
@@ -90,14 +70,7 @@ export function EventListenersCard() {
9070
</Heading>
9171
</Flex>
9272
{chainChanged && (
93-
<Code
94-
mt={2}
95-
as="pre"
96-
p={4}
97-
wordBreak="break-word"
98-
whiteSpace="pre-wrap"
99-
w="100%"
100-
>
73+
<Code mt={2} as="pre" p={4} wordBreak="break-word" whiteSpace="pre-wrap" w="100%">
10174
{JSON.stringify(chainChanged, null, 2)}
10275
</Code>
10376
)}
@@ -109,14 +82,7 @@ export function EventListenersCard() {
10982
</Heading>
11083
</Flex>
11184
{connect && (
112-
<Code
113-
mt={2}
114-
as="pre"
115-
p={4}
116-
wordBreak="break-word"
117-
whiteSpace="pre-wrap"
118-
w="100%"
119-
>
85+
<Code mt={2} as="pre" p={4} wordBreak="break-word" whiteSpace="pre-wrap" w="100%">
12086
{JSON.stringify(connect, null, 2)}
12187
</Code>
12288
)}
@@ -128,14 +94,7 @@ export function EventListenersCard() {
12894
</Heading>
12995
</Flex>
13096
{disconnect && (
131-
<Code
132-
mt={2}
133-
as="pre"
134-
p={4}
135-
wordBreak="break-word"
136-
whiteSpace="pre-wrap"
137-
w="100%"
138-
>
97+
<Code mt={2} as="pre" p={4} wordBreak="break-word" whiteSpace="pre-wrap" w="100%">
13998
{JSON.stringify(disconnect, null, 2)}
14099
</Code>
141100
)}

examples/testapp/src/hooks/useEventListeners.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ describe('useEventListeners', () => {
4848

4949
expect(mockProvider.removeListener).toHaveBeenCalledTimes(4);
5050
expect(mockProvider.removeListener).toHaveBeenCalledWith('connect', expect.any(Function));
51-
expect(mockProvider.removeListener).toHaveBeenCalledWith('accountsChanged', expect.any(Function));
51+
expect(mockProvider.removeListener).toHaveBeenCalledWith(
52+
'accountsChanged',
53+
expect.any(Function)
54+
);
5255
expect(mockProvider.removeListener).toHaveBeenCalledWith('chainChanged', expect.any(Function));
5356
expect(mockProvider.removeListener).toHaveBeenCalledWith('disconnect', expect.any(Function));
5457
});

examples/testapp/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
1818
"exclude": ["node_modules"],
1919
"references": [],
20-
"types": ["node", "vitest/globals", "@testing-library/jest-dom"],
20+
"types": ["node", "vitest/globals", "@testing-library/jest-dom"]
2121
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
"deploy": "yarn build:packages && yarn workspace sdk-playground export",
1717
"dev": "yarn workspaces foreach -A -ipv run dev",
1818
"lint": "yarn workspaces foreach -A -pt run lint",
19+
"format": "yarn workspaces foreach -A -pt run format",
20+
"format:check": "yarn workspaces foreach -A -pt run format:check",
1921
"test": "yarn workspaces foreach -A -ipv run test",
2022
"typecheck": "yarn workspaces foreach -A -pt run typecheck"
2123
},

packages/account-sdk/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
"dev": "yarn build && tsc --watch & nodemon --watch dist --delay 1 --exec tsc-alias",
4646
"typecheck": "tsc --noEmit",
4747
"lint": "biome lint .",
48+
"format": "biome format . --write",
49+
"format:check": "biome check . --formatter-enabled=true --linter-enabled=false --organize-imports-enabled=false",
4850
"size": "size-limit"
4951
},
5052
"dependencies": {

0 commit comments

Comments
 (0)