Skip to content

Commit

Permalink
refactor: Switch ESLint to unicorn rules
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche committed Jun 17, 2024
1 parent b32a009 commit e18cce9
Show file tree
Hide file tree
Showing 57 changed files with 587 additions and 347 deletions.
13 changes: 13 additions & 0 deletions .changeset/mean-ants-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@joyid/ethereum-provider': patch
'@joyid/bitcoin': patch
'@joyid/miniapp': patch
'@joyid/common': patch
'@joyid/ethers': patch
'@joyid/nostr': patch
'@joyid/wagmi': patch
'@joyid/ckb': patch
'@joyid/evm': patch
---

Use unicorn rules as linter rule
64 changes: 0 additions & 64 deletions eslint.config.js

This file was deleted.

20 changes: 20 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import unjs from 'eslint-config-unjs'
import prettierConfig from 'eslint-plugin-prettier/recommended'

export default unjs(
{
ignores: ['**/.nuxt', 'dist/**', '**/dist'],
},
{
rules: {
'unicorn/no-null': 'off',
'unicorn/number-literal-case': 'off',
'unicorn/prefer-optional-catch-binding': 'off',
'unicorn/catch-error-name': 'off',
'unicorn/filename-case': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'unicorn/expiring-todo-comments': 'off',
},
},
prettierConfig
)
2 changes: 1 addition & 1 deletion examples/bitcoin-demo/src/env/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export const BTC_SERVICE_URL: string =
export const BTC_SERVER_TOKEN: string =
import.meta.env.VITE_APP_BTC_SERVER_TOKEN ?? ''

export const MIN_UTXO_AMOUNT = 10000
export const MIN_UTXO_AMOUNT = 10_000
2 changes: 0 additions & 2 deletions examples/bitcoin-demo/src/hooks/localStorage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { createEffect } from 'solid-js'
import {
createStore,
Expand Down
2 changes: 1 addition & 1 deletion examples/bitcoin-demo/src/hooks/useSendSuccessToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const useSendSuccessToast = () => {
},
{
position: 'bottom-center',
duration: 10000,
duration: 10_000,
unmountDelay: 0,
}
)
Expand Down
3 changes: 1 addition & 2 deletions examples/bitcoin-demo/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* @refresh reload */
import './global.css'

Expand All @@ -7,7 +6,7 @@ import { Router } from '@solidjs/router'

import App from './app'

const root = document.getElementById('root')
const root = document.querySelector('#root')

if (import.meta.env.DEV && !(root instanceof HTMLElement)) {
throw new Error(
Expand Down
1 change: 0 additions & 1 deletion examples/bitcoin-demo/src/pages/home.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { type Component, Match, Show, Switch, onMount } from 'solid-js'
import { writeClipboard } from '@solid-primitives/clipboard'
import { A, Navigate, useLocation } from '@solidjs/router'
Expand Down
1 change: 0 additions & 1 deletion examples/bitcoin-demo/src/pages/root.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { type Component, Show, createSignal } from 'solid-js'
import { Navigate, useNavigate } from '@solidjs/router'
import { useAuthData } from '../hooks/localStorage'
Expand Down
2 changes: 1 addition & 1 deletion examples/bitcoin-demo/src/pages/send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const SendBtc: Component = () => {
tos: [
{
address: toAddress(),
value: parseInt((Number(toAmount()) * 1e8).toString(), 10),
value: Number.parseInt((Number(toAmount()) * 1e8).toString(), 10),
},
],
feeRate: 1,
Expand Down
8 changes: 1 addition & 7 deletions examples/bitcoin-demo/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { defineConfig } from 'vite'
import solidPlugin from 'vite-plugin-solid'
import wasm from 'vite-plugin-wasm'
Expand All @@ -7,12 +6,7 @@ import topLevelAwait from 'vite-plugin-top-level-await'
import { nodePolyfills } from 'vite-plugin-node-polyfills'

export default defineConfig({
plugins: [
wasm(),
topLevelAwait(),
solidPlugin(),
nodePolyfills()
],
plugins: [wasm(), topLevelAwait(), solidPlugin(), nodePolyfills()],
server: {
port: 3000,
},
Expand Down
2 changes: 1 addition & 1 deletion examples/ckb-demo/src/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ i18n.use(initReactI18next).init({
cache: localStorage,
})

export default i18n
export { default } from 'i18next'
2 changes: 1 addition & 1 deletion examples/ckb-demo/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const App: React.FC = () => {
)
}

createRoot(document.getElementById('root')!).render(
createRoot(document.querySelector('#root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
Expand Down
3 changes: 1 addition & 2 deletions examples/ckb-demo/src/pages/SignCkbRawTx/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { useState } from 'react'
import { Button, VStack, Input, Text, Link, useToast } from '@chakra-ui/react'
import { Navigate, useNavigate } from 'react-router-dom'
Expand Down Expand Up @@ -26,7 +25,7 @@ import { RoutePath } from '../../route/path'
import { CKB_INDEXER_URL, CKB_RPC_URL, COTA_AGGREGATOR_URL } from '../../env'

const info: InscriptionInfo = {
maxSupply: BigInt(2100_0000),
maxSupply: BigInt(21_000_000),
mintLimit: BigInt(1000),
xudtHash: '',
mintStatus: 0,
Expand Down
1 change: 0 additions & 1 deletion examples/ckb-demo/src/pages/SignMessage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { useState } from 'react'
import { Button, Textarea, VStack, useToast, Box } from '@chakra-ui/react'
import {
Expand Down
1 change: 1 addition & 0 deletions examples/evm-demo/src/chains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface Chain {

export const EthSepolia: Chain = chainList[0]

// eslint-disable-next-line unicorn/no-array-reduce
export const Chains = chainList.reduce<Record<string, Chain>>((prev, acc) => {
prev[acc.name] = acc
return prev
Expand Down
2 changes: 0 additions & 2 deletions examples/evm-demo/src/hooks/localStorage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { createEffect } from 'solid-js'
import {
createStore,
Expand Down
3 changes: 1 addition & 2 deletions examples/evm-demo/src/hooks/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import { createMemo } from 'solid-js'

export const SepoliaNetwork = {
name: 'Ethereum Sepolia',
chainId: 11155111,
chainId: 11_155_111,
}

export const useProvider = () => {
const { authData } = useAuthData()
// eslint-disable-next-line solid/reactivity
return createMemo(() =>
authData.name
? new providers.JsonRpcBatchProvider(authData.rpcURL, {
Expand Down
2 changes: 1 addition & 1 deletion examples/evm-demo/src/hooks/useSendSuccessToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const useSendSuccessToast = () => {
},
{
position: 'bottom-center',
duration: 10000,
duration: 10_000,
unmountDelay: 0,
}
)
Expand Down
4 changes: 2 additions & 2 deletions examples/evm-demo/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Router } from '@solidjs/router'

import App from './app'

const root = document.getElementById('root')
const root = document.querySelector('#root')

if (import.meta.env.DEV && !(root instanceof HTMLElement)) {
throw new Error(
Expand All @@ -20,6 +20,6 @@ render(
<App />
</Router>
),
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion

root!
)
1 change: 0 additions & 1 deletion examples/evm-demo/src/pages/home.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import {
type Component,
For,
Expand Down
1 change: 0 additions & 1 deletion examples/evm-demo/src/pages/send-erc20.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { Navigate, useLocation, useNavigate } from '@solidjs/router'
import toast from 'solid-toast'
import { type Component, Show, createSignal, onMount } from 'solid-js'
Expand Down
1 change: 0 additions & 1 deletion examples/evm-demo/src/pages/send.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { Navigate, useLocation, useNavigate } from '@solidjs/router'
import toast from 'solid-toast'
import { type Component, Show, createSignal, onMount } from 'solid-js'
Expand Down
1 change: 0 additions & 1 deletion examples/evm-demo/src/pages/sign-typed-data.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-unsafe-argument */
import { Navigate, useLocation, useNavigate } from '@solidjs/router'
import { type Component, Show, createSignal } from 'solid-js'
import toast from 'solid-toast'
Expand Down
1 change: 1 addition & 0 deletions examples/rainbowkit-demo/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable unicorn/prefer-query-selector */
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
Expand Down
1 change: 1 addition & 0 deletions examples/wagmi-demo/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable unicorn/prefer-query-selector */
import React from 'react'
import ReactDOM from 'react-dom/client'
import { App } from './App.tsx'
Expand Down
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,15 @@
"devDependencies": {
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.5",
"@eslint/js": "^9.4.0",
"@types/eslint__js": "^8.42.3",
"eslint": "9.4.0",
"eslint-config-love": "52.0.0",
"eslint-config-prettier": "9.1.0",
"eslint-config-unjs": "0.3.2",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-prettier": "5.1.3",
"eslint-plugin-promise": "6.2.0",
"prettier": "3.3.1",
"simple-git-hooks": "^2.11.1",
"tsup": "^7.2.0",
"typescript": "^5.2.2",
"typescript-eslint": "^7.12.0",
"vite": "5.2.12",
"vitest": "1.6.0"
},
Expand Down
18 changes: 8 additions & 10 deletions packages/bitcoin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/strict-boolean-expressions */

import {
createBlockDialog,
openPopup as p,
Expand All @@ -25,8 +23,6 @@ import {

export const openPopup = p

export type { BtcConfig }

const JOYID_STORAGE_KEY = 'joyid:bitcoin::account'

export const buildSignPsbtURL = (
Expand Down Expand Up @@ -58,9 +54,9 @@ export const buildSignPsbtsURL = (
const getRequestNetwork = (
requestAddressType: BtcConfig['requestAddressType']
): RequestNetwork =>
requestAddressType !== null
? (`btc-${requestAddressType}` as RequestNetwork)
: 'btc-auto'
requestAddressType == null
? 'btc-auto'
: (`btc-${requestAddressType}` as RequestNetwork)

export const buildConnectUrl = (
{ requestAddressType, ...config }: BtcConfig & { redirectURL: string },
Expand Down Expand Up @@ -136,9 +132,8 @@ export const requestAccounts = async (): Promise<string[]> => {
}

export const getAccounts = (): string[] =>
connectedAccount.address != null
? [connectedAccount.address]
: safeExec(() => {
connectedAccount.address == null
? safeExec(() => {
const json = localStorage.getItem(JOYID_STORAGE_KEY)
if (json) {
const account = JSON.parse(json)
Expand All @@ -148,6 +143,7 @@ export const getAccounts = (): string[] =>
}
return []
}) ?? []
: [connectedAccount.address]

export const getPublicKey = (): string | null => {
if (connectedAccount.pubkey) {
Expand Down Expand Up @@ -341,3 +337,5 @@ export const signPsbtCallback = (uri?: string): WithState & { tx: string } => {
tx,
}
}

export { type BtcConfig } from '@joyid/common'
2 changes: 1 addition & 1 deletion packages/bitcoin/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import config from '../../tsup-base.config'
export default defineConfig({
...config,
name,
external: [...Object.keys(dependencies)],
external: Object.keys(dependencies),
platform: 'browser',
})
1 change: 0 additions & 1 deletion packages/ckb/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/consistent-type-assertions */
import { type CellDep, type Script } from '@joyid/common'

const TestnetInfo = {
Expand Down
Loading

0 comments on commit e18cce9

Please sign in to comment.