Skip to content

Commit 3e59253

Browse files
feat: setup linters (#357)
Co-authored-by: Roland Bewick <[email protected]>
1 parent 369a730 commit 3e59253

File tree

13 files changed

+1097
-167
lines changed

13 files changed

+1097
-167
lines changed

frontend/.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

frontend/.eslintrc.cjs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,28 @@ module.exports = {
22
root: true,
33
env: { browser: true, es2020: true },
44
extends: [
5-
'eslint:recommended',
6-
'plugin:@typescript-eslint/recommended',
7-
'plugin:react-hooks/recommended',
5+
"eslint:recommended",
6+
"plugin:@typescript-eslint/recommended",
7+
"plugin:react-hooks/recommended",
8+
"prettier",
89
],
9-
ignorePatterns: ['dist', '.eslintrc.cjs'],
10-
parser: '@typescript-eslint/parser',
11-
plugins: ['react-refresh'],
10+
ignorePatterns: ["dist", ".eslintrc.cjs"],
11+
parser: "@typescript-eslint/parser",
12+
plugins: ["react-refresh", "@typescript-eslint"],
1213
rules: {
13-
'react-refresh/only-export-components': [
14-
'warn',
14+
"react-refresh/only-export-components": [
15+
"warn",
1516
{ allowConstantExport: true },
1617
],
18+
"@typescript-eslint/ban-ts-comment": [
19+
"error",
20+
{
21+
"ts-ignore": "allow-with-description",
22+
},
23+
],
24+
"@typescript-eslint/no-unused-vars": ["warn", { args: "none" }],
25+
"no-console": ["error", { allow: ["info", "warn", "error"] }],
26+
"no-constant-binary-expression": "error",
27+
curly: "error",
1728
},
18-
}
29+
};

frontend/.husky/commit-msg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
cd frontend && yarn commitlint --edit

frontend/.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
cd frontend && yarn lint-staged

frontend/.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Ignore artifacts:
2+
dist
3+
node_modules

frontend/.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"trailingComma": "es5"
3+
}

frontend/commitlint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default { extends: ['@commitlint/config-conventional'] };

frontend/lint-staged.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
"src/**/*.{ts,tsx,json}": ["eslint --fix --max-warnings 0","prettier --write"],
3+
"platform_specific/**/*.ts": ["prettier --write"],
4+
"package.json": ["prettier --write"],
5+
"src/**/*.ts": () => "tsc --noEmit",
6+
};

frontend/package.json

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@
1010
"build:wails": "yarn prepare:wails && tsc && vite build",
1111
"prepare:wails": "shx cp ./platform_specific/wails/src/utils/*.ts src/utils/",
1212
"prepare:http": "shx cp ./platform_specific/http/src/utils/*.ts src/utils/",
13-
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
14-
"preview": "vite preview"
13+
"lint": "yarn lint:js && yarn tsc:compile && yarn format:fix --report-unused-disable-directives --max-warnings 0",
14+
"lint:js": "eslint src --ext .js,.ts,.tsx --max-warnings 0",
15+
"lint:js:fix": "eslint src --ext .js,.ts,.tsx --fix",
16+
"tsc:compile": "tsc --noEmit",
17+
"format": "prettier --check '**/*.(md|json)' 'src/**/*.(js|ts)' 'example/**/*.(js|jsx)'",
18+
"format:fix": "prettier --loglevel silent --write '**/*.(md|json)' 'src/**/*.(js|ts)' 'example/**/*.(js|jsx)'",
19+
"preview": "vite preview",
20+
"prepare": "cd .. && husky frontend/.husky"
1521
},
1622
"dependencies": {
1723
"@getalby/bitcoin-connect-react": "^3.4.1",
@@ -51,6 +57,8 @@
5157
"zustand": "^4.5.0"
5258
},
5359
"devDependencies": {
60+
"@commitlint/cli": "^19.3.0",
61+
"@commitlint/config-conventional": "^19.2.2",
5462
"@tailwindcss/aspect-ratio": "^0.4.2",
5563
"@tailwindcss/forms": "^0.5.7",
5664
"@tailwindcss/typography": "^0.5.10",
@@ -59,14 +67,18 @@
5967
"@types/react": "^18.2.15",
6068
"@types/react-dom": "^18.2.7",
6169
"@types/react-lottie": "^1.2.10",
62-
"@typescript-eslint/eslint-plugin": "^6.0.0",
63-
"@typescript-eslint/parser": "^6.0.0",
70+
"@typescript-eslint/eslint-plugin": "^7.11.0",
71+
"@typescript-eslint/parser": "^7.11.0",
6472
"@vitejs/plugin-react-swc": "^3.3.2",
6573
"autoprefixer": "^10.4.16",
6674
"eslint": "^8.45.0",
75+
"eslint-config-prettier": "^9.1.0",
6776
"eslint-plugin-react-hooks": "^4.6.0",
6877
"eslint-plugin-react-refresh": "^0.4.3",
78+
"husky": "^9.0.11",
79+
"lint-staged": "^15.2.5",
6980
"postcss": "^8.4.32",
81+
"prettier": "3.2.5",
7082
"shx": "^0.3.4",
7183
"tailwindcss": "^3.4.1",
7284
"typescript": "^5.0.2",

frontend/src/screens/appstore/AppConnect.tsx

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
import { CopyIcon } from "lucide-react";
22
import { useEffect, useState } from "react";
3-
import { Link, Navigate, useLocation, useNavigate, useParams } from "react-router-dom";
3+
import {
4+
Link,
5+
Navigate,
6+
useLocation,
7+
useNavigate,
8+
useParams,
9+
} from "react-router-dom";
410
import AppHeader from "src/components/AppHeader";
511
import ExternalLink from "src/components/ExternalLink";
612
import Loading from "src/components/Loading";
713

814
import QRCode from "src/components/QRCode";
915
import { suggestedApps } from "src/components/SuggestedAppData";
1016
import { Button } from "src/components/ui/button";
11-
import { Card, CardContent, CardHeader, CardTitle } from "src/components/ui/card";
17+
import {
18+
Card,
19+
CardContent,
20+
CardHeader,
21+
CardTitle,
22+
} from "src/components/ui/card";
1223
import { useToast } from "src/components/ui/use-toast";
1324
import { useApp } from "src/hooks/useApp";
1425
import { copyToClipboard } from "src/lib/clipboard";
@@ -21,21 +32,16 @@ export default function AppConnect() {
2132
const params = useParams();
2233
const [timeout, setTimeout] = useState(false);
2334
const createAppResponse = state as CreateAppResponse;
24-
const appstoreApp = suggestedApps.find(x => x.id == params.id);
35+
const appstoreApp = suggestedApps.find((x) => x.id == params.id);
2536
const { data: app } = useApp(createAppResponse.pairingPublicKey, true);
2637
const pairingUri = createAppResponse.pairingUri;
2738

28-
if (!createAppResponse || !appstoreApp) {
29-
return <Navigate to="/apps/new" />;
30-
}
31-
3239
const copy = () => {
3340
copyToClipboard(pairingUri);
3441
toast({ title: "Copied to clipboard." });
3542
};
3643

3744
useEffect(() => {
38-
3945
const timeoutId = window.setTimeout(() => {
4046
setTimeout(true);
4147
}, 10000);
@@ -47,11 +53,15 @@ export default function AppConnect() {
4753
if (app?.lastEventAt) {
4854
toast({
4955
title: "Connection established!",
50-
description: "You can now use the app with your Alby Hub."
56+
description: "You can now use the app with your Alby Hub.",
5157
});
5258
navigate("/apps");
5359
}
54-
}, [app?.lastEventAt])
60+
}, [app?.lastEventAt, navigate, toast]);
61+
62+
if (!createAppResponse || !appstoreApp) {
63+
return <Navigate to="/apps/new" />;
64+
}
5565

5666
return (
5767
<>
@@ -63,15 +73,16 @@ export default function AppConnect() {
6373
<div>
6474
<p>
6575
1. Open{" "}
66-
<ExternalLink className="font-semibold underline" to={appstoreApp.to}>
76+
<ExternalLink
77+
className="font-semibold underline"
78+
to={appstoreApp.to}
79+
>
6780
{appstoreApp.title}
68-
</ExternalLink>
69-
{" "}
70-
and look for a way to attach a wallet (most apps provide this option in settings)
71-
</p>
72-
<p>
73-
2. Scan or paste the connection secret
81+
</ExternalLink>{" "}
82+
and look for a way to attach a wallet (most apps provide this option
83+
in settings)
7484
</p>
85+
<p>2. Scan or paste the connection secret</p>
7586
</div>
7687
<Card className="max-w-sm">
7788
<CardHeader>
@@ -82,19 +93,18 @@ export default function AppConnect() {
8293
<Loading className="w-4 h-4" />
8394
<p>Waiting for app to connect</p>
8495
</div>
85-
{timeout && <div className="text-sm flex flex-col gap-2 items-center text-center">
86-
Connecting is taking longer than usual.
87-
<Link to={`/apps/${app?.nostrPubkey}`}>
88-
<Button variant="secondary">Continue anyway</Button>
89-
</Link>
90-
</div>}
91-
<a
92-
href={pairingUri}
93-
target="_blank"
94-
className="relative"
95-
>
96+
{timeout && (
97+
<div className="text-sm flex flex-col gap-2 items-center text-center">
98+
Connecting is taking longer than usual.
99+
<Link to={`/apps/${app?.nostrPubkey}`}>
100+
<Button variant="secondary">Continue anyway</Button>
101+
</Link>
102+
</div>
103+
)}
104+
<a href={pairingUri} target="_blank" className="relative">
96105
<QRCode value={pairingUri} className="w-full" />
97-
<img src={appstoreApp.logo}
106+
<img
107+
src={appstoreApp.logo}
98108
className="absolute w-12 h-12 top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 bg-muted p-1 rounded-xl"
99109
/>
100110
</a>

0 commit comments

Comments
 (0)