Skip to content

Commit 48c5a4c

Browse files
authored
Eslint and Husky pre-commit hook (#307)
* Updating to eslint 9 * Fixing lint:fix script * Lint fixes * Fixing lint errors * Removing old eslint ignore file * Adding husky pre-commit hook * No longer minify injected styles so they can be diffed properly * Remove semi colon from styles.css output so it no longer triggers prettier format * Ensure pre-commit checks prettier formatting as well
1 parent a174454 commit 48c5a4c

File tree

28 files changed

+2807
-338
lines changed

28 files changed

+2807
-338
lines changed

.eslintignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.eslintrc.js

Lines changed: 0 additions & 51 deletions
This file was deleted.

.husky/pre-commit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pnpm run typecheck
2+
pnpm run lint
3+
pnpm run prettier:check

eslint.config.mjs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import eslint from '@eslint/js'
2+
import tseslint from 'typescript-eslint'
3+
4+
import reactHooksPlugin from 'eslint-plugin-react-hooks'
5+
import importPlugin from 'eslint-plugin-import'
6+
7+
export default tseslint.config(eslint.configs.recommended, tseslint.configs.recommended, {
8+
ignores: ['packages/*/dist'],
9+
files: ['**/*.{ts,tsx}'],
10+
languageOptions: {
11+
ecmaVersion: 2020
12+
},
13+
plugins: {
14+
'react-hooks': reactHooksPlugin,
15+
import: importPlugin
16+
},
17+
rules: {
18+
curly: ['warn'],
19+
'no-empty': 'off',
20+
'no-fallthrough': 'off',
21+
'no-async-promise-executor': 'off',
22+
'no-useless-catch': 'off',
23+
24+
'@typescript-eslint/no-inferrable-types': 'off',
25+
'@typescript-eslint/no-wrapper-object-types': 'off',
26+
'@typescript-eslint/no-empty-object-type': 'off',
27+
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_', varsIgnorePattern: '^_', caughtErrors: 'none' }],
28+
'@typescript-eslint/no-explicit-any': 'off',
29+
'@typescript-eslint/no-non-null-assertion': 'off',
30+
'@typescript-eslint/explicit-module-boundary-types': 'off',
31+
'@typescript-eslint/ban-types': 'off',
32+
'@typescript-eslint/ban-ts-comment': 'off',
33+
'@typescript-eslint/no-empty-function': 'off',
34+
'@typescript-eslint/no-empty-interface': 'off',
35+
36+
'import/no-unresolved': 'off',
37+
'import/no-named-as-default': 'off',
38+
'import/order': [
39+
'warn',
40+
{
41+
alphabetize: {
42+
order: 'asc',
43+
caseInsensitive: true
44+
},
45+
pathGroups: [
46+
{
47+
pattern: '~/**',
48+
group: 'external',
49+
position: 'after'
50+
}
51+
],
52+
'newlines-between': 'always'
53+
}
54+
],
55+
56+
'react/prop-types': 'off',
57+
'react/display-name': 'off',
58+
'react-hooks/exhaustive-deps': 'off',
59+
'react/no-unescaped-entities': 'off'
60+
}
61+
})

examples/next/src/app/components/Connected.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,12 @@ export const Connected = () => {
274274
{[...wallets]
275275
.sort((a, b) => {
276276
// Sort embedded wallet to the top
277-
if (a.isEmbedded && !b.isEmbedded) return -1
278-
if (!a.isEmbedded && b.isEmbedded) return 1
277+
if (a.isEmbedded && !b.isEmbedded) {
278+
return -1
279+
}
280+
if (!a.isEmbedded && b.isEmbedded) {
281+
return 1
282+
}
279283
return 0
280284
})
281285
.map(wallet => (
@@ -409,8 +413,8 @@ export const Connected = () => {
409413
}
410414
}}
411415
value={selectedFeeOptionTokenName}
412-
options={[
413-
...pendingFeeOptionConfirmation?.options?.map(option => ({
416+
options={
417+
pendingFeeOptionConfirmation?.options?.map(option => ({
414418
label: (
415419
<div className="flex items-start flex-col">
416420
<div className="flex flex-row">
@@ -429,8 +433,8 @@ export const Connected = () => {
429433
</div>
430434
),
431435
value: option.token.name
432-
}))
433-
]}
436+
})) || []
437+
}
434438
/>
435439

436440
<div className="flex my-2 items-center justify-center flex-col">

examples/react/src/components/Connected.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,12 @@ export const Connected = () => {
475475
{[...wallets]
476476
.sort((a, b) => {
477477
// Sort embedded wallet to the top
478-
if (a.isEmbedded && !b.isEmbedded) return -1
479-
if (!a.isEmbedded && b.isEmbedded) return 1
478+
if (a.isEmbedded && !b.isEmbedded) {
479+
return -1
480+
}
481+
if (!a.isEmbedded && b.isEmbedded) {
482+
return 1
483+
}
480484
return 0
481485
})
482486
.map(wallet => (

package.json

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
"dev": "turbo run dev --filter={packages/*}",
1010
"reinstall": "rimraf -g ./**/node_modules && pnpm install",
1111
"test": "turbo run test",
12-
"lint": "eslint -c .eslintrc.js '{packages,examples}/**/src/**/*.{ts,tsx}'",
13-
"lint:fix": "eslint -c .eslintrc.js --fix '{packages,examples}/**/src/**/*.{ts,tsx}' && pnpm run format",
14-
"format": "prettier --list-different --write './{packages,examples}/*/src/**/*.{ts,tsx}'",
12+
"lint": "eslint -c eslint.config.mjs '{packages,examples}/**/src/**/*.{ts,tsx}'",
13+
"lint:fix": "eslint -c eslint.config.mjs --fix '{packages,examples}/**/src/**/*.{ts,tsx}'",
14+
"prettier:check": "prettier --list-different './{packages,examples}/*/src/**/*.{ts,tsx}'",
15+
"prettier:fix": "prettier --list-different --write './{packages,examples}/*/src/**/*.{ts,tsx}'",
16+
"format": "pnpm run lint:fix && pnpm run prettier:fix",
1517
"audit:fix": "pnpm audit --fix",
1618
"typecheck": "tsc --noEmit",
1719
"deps": "pnpx taze -r",
@@ -27,36 +29,35 @@
2729
"build:react-boilerplate": "pnpm --filter example-react-boilerplate build",
2830
"dev:next": "pnpm --filter example-next dev",
2931
"serve:next": "pnpm --filter example-next start",
30-
"build:next": "pnpm --filter example-next build"
32+
"build:next": "pnpm --filter example-next build",
33+
"prepare": "husky"
3134
},
3235
"devDependencies": {
3336
"@0xsequence/react-connect": "workspace:*",
3437
"@changesets/changelog-github": "^0.5.0",
3538
"@changesets/cli": "^2.25.2",
39+
"@eslint/js": "^9.22.0",
40+
"@tailwindcss/cli": "^4.0.6",
41+
"@tailwindcss/postcss": "^4.0.6",
3642
"@types/node": "^20.12.12",
3743
"@types/react": "^18.3.2",
3844
"@types/react-dom": "^18.3.0",
39-
"@typescript-eslint/eslint-plugin": "^7.10.0",
40-
"@typescript-eslint/parser": "^7.10.0",
41-
"eslint": "^8.27.0",
42-
"eslint-config-prettier": "^8.10.0",
45+
"eslint": "^9.22.0",
4346
"eslint-plugin-import": "^2.29.1",
44-
"eslint-plugin-prettier": "^4.2.1",
47+
"eslint-plugin-react-hooks": "^5.2.0",
4548
"ethers": "^6.13.0",
49+
"husky": "^9.1.7",
50+
"postcss": "^8",
4651
"prettier": "^3.2.5",
4752
"react": "^18.3.1",
4853
"react-dom": "^18.3.1",
4954
"rimraf": "^5.0.7",
55+
"tailwindcss": "^4.0.6",
5056
"turbo": "2.0.1",
5157
"typescript": "^5.8.2",
58+
"typescript-eslint": "^8.26.1",
5259
"wagmi": "^2.14.11"
5360
},
5461
"resolutions": {},
55-
"packageManager": "pnpm@9.0.6",
56-
"dependencies": {
57-
"@tailwindcss/cli": "^4.0.6",
58-
"@tailwindcss/postcss": "^4.0.6",
59-
"postcss": "^8",
60-
"tailwindcss": "^4.0.6"
61-
}
62+
"packageManager": "pnpm@9.0.6"
6263
}

packages/react-checkout/src/hooks/useERC1155SaleContractCheckout.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ export const useSaleContractConfig = ({
222222
const getSaleConfigs = (): SaleConfig[] => {
223223
let saleInfos: SaleConfig[] = []
224224

225-
if (isLoadingERC1155 || isErrorERC1155) return saleInfos
225+
if (isLoadingERC1155 || isErrorERC1155) {
226+
return saleInfos
227+
}
226228

227229
// In the sale contract, the global sale has priority over the token sale
228230
// So we need to check if the global sale is set, and if it is, use that

packages/react-checkout/src/views/CheckoutSelection/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ export const CheckoutSelection = () => {
9090

9191
const onClickPayWithCrypto = () => {
9292
console.log('trigger transaction')
93-
const transaction = settings?.cryptoCheckout?.triggerTransaction
94-
transaction && transaction()
93+
settings?.cryptoCheckout?.triggerTransaction?.()
9594
closeCheckout()
9695
}
9796

packages/react-checkout/src/views/PendingCreditCardTransaction.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ export const PendingCreditCardTransactionTransak = ({ skipOnCloseCallback }: Pen
131131
const transakIframe = transakIframeElement.contentWindow
132132

133133
const readMessage = (message: any) => {
134-
if (message.source !== transakIframe) return
134+
if (message.source !== transakIframe) {
135+
return
136+
}
135137

136138
if (message?.data?.event_id === 'TRANSAK_ORDER_SUCCESSFUL' && message?.data?.data?.status === 'COMPLETED') {
137139
console.log('Order Data: ', message?.data?.data)
@@ -350,24 +352,22 @@ export const PendingCreditCardTransactionSardine = ({ skipOnCloseCallback }: Pen
350352
return
351353
}
352354
if (status === 'Declined' || status === 'Cancelled') {
353-
setNavigation &&
354-
setNavigation({
355-
location: 'transaction-error',
356-
params: {
357-
error: new Error('Failed to transfer collectible')
358-
}
359-
})
360-
return
361-
}
362-
} catch (e) {
363-
console.error('An error occurred while fetching the transaction status')
364-
setNavigation &&
365355
setNavigation({
366356
location: 'transaction-error',
367357
params: {
368-
error: e as Error
358+
error: new Error('Failed to transfer collectible')
369359
}
370360
})
361+
return
362+
}
363+
} catch (e) {
364+
console.error('An error occurred while fetching the transaction status')
365+
setNavigation({
366+
location: 'transaction-error',
367+
params: {
368+
error: e as Error
369+
}
370+
})
371371
}
372372
}
373373

0 commit comments

Comments
 (0)