Skip to content

Commit e648a59

Browse files
committed
feat: add lint-staged
1 parent 8340009 commit e648a59

File tree

8 files changed

+467
-61
lines changed

8 files changed

+467
-61
lines changed

.eslintrc.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"extends": "next/core-web-vitals"
2+
"extends": "next/core-web-vitals",
3+
"plugins": ["prettier"]
34
}

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx lint-staged

.lintstagedrc.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"./app/**/*.{js,ts,jsx,tsx,json,html,css,scss,md}": [
3+
"eslint --fix",
4+
"prettier --write"
5+
]
6+
}

.prettierrc.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
printWidth: 80,
3+
tabWidth: 2,
4+
useTabs: false,
5+
semi: true,
6+
singleQuote: false,
7+
trailingComma: 'all',
8+
bracketSpacing: true,
9+
arrowParens: 'always',
10+
};

app/locales/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import TW from "./tw";
55
export type { LocaleType } from "./cn";
66

77
export const AllLangs = ["en", "cn", "tw"] as const;
8-
type Lang = typeof AllLangs[number];
8+
type Lang = (typeof AllLangs)[number];
99

1010
const LANG_KEY = "lang";
1111

app/store/app.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ interface ChatStore {
194194
updateMessage: (
195195
sessionIndex: number,
196196
messageIndex: number,
197-
updater: (message?: Message) => void
197+
updater: (message?: Message) => void,
198198
) => void;
199199
getMessagesWithMemory: () => Message[];
200200
getMemoryPrompt: () => Message;
@@ -342,7 +342,7 @@ export const useChatStore = create<ChatStore>()(
342342
ControllerPool.addController(
343343
sessionIndex,
344344
messageIndex,
345-
controller
345+
controller,
346346
);
347347
},
348348
filterBot: !get().config.sendBotMessages,
@@ -365,7 +365,7 @@ export const useChatStore = create<ChatStore>()(
365365
const config = get().config;
366366
const n = session.messages.length;
367367
const recentMessages = session.messages.slice(
368-
n - config.historyMessageCount
368+
n - config.historyMessageCount,
369369
);
370370

371371
const memoryPrompt = get().getMemoryPrompt();
@@ -380,7 +380,7 @@ export const useChatStore = create<ChatStore>()(
380380
updateMessage(
381381
sessionIndex: number,
382382
messageIndex: number,
383-
updater: (message?: Message) => void
383+
updater: (message?: Message) => void,
384384
) {
385385
const sessions = get().sessions;
386386
const session = sessions.at(sessionIndex);
@@ -397,24 +397,24 @@ export const useChatStore = create<ChatStore>()(
397397
requestWithPrompt(session.messages, Locale.Store.Prompt.Topic).then(
398398
(res) => {
399399
get().updateCurrentSession(
400-
(session) => (session.topic = trimTopic(res))
400+
(session) => (session.topic = trimTopic(res)),
401401
);
402-
}
402+
},
403403
);
404404
}
405405

406406
const config = get().config;
407407
let toBeSummarizedMsgs = session.messages.slice(
408-
session.lastSummarizeIndex
408+
session.lastSummarizeIndex,
409409
);
410410
const historyMsgLength = toBeSummarizedMsgs.reduce(
411411
(pre, cur) => pre + cur.content.length,
412-
0
412+
0,
413413
);
414414

415415
if (historyMsgLength > 4000) {
416416
toBeSummarizedMsgs = toBeSummarizedMsgs.slice(
417-
-config.historyMessageCount
417+
-config.historyMessageCount,
418418
);
419419
}
420420

@@ -427,7 +427,7 @@ export const useChatStore = create<ChatStore>()(
427427
"[Chat History] ",
428428
toBeSummarizedMsgs,
429429
historyMsgLength,
430-
config.compressMessageLengthThreshold
430+
config.compressMessageLengthThreshold,
431431
);
432432

433433
if (historyMsgLength > config.compressMessageLengthThreshold) {
@@ -449,7 +449,7 @@ export const useChatStore = create<ChatStore>()(
449449
onError(error) {
450450
console.error("[Summarize] ", error);
451451
},
452-
}
452+
},
453453
);
454454
}
455455
},
@@ -478,6 +478,6 @@ export const useChatStore = create<ChatStore>()(
478478
{
479479
name: LOCAL_KEY,
480480
version: 1,
481-
}
482-
)
481+
},
482+
),
483483
);

package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"build": "yarn fetch && next build",
99
"start": "next start",
1010
"lint": "next lint",
11-
"fetch": "node ./scripts/fetch-prompts.mjs"
11+
"fetch": "node ./scripts/fetch-prompts.mjs",
12+
"prepare": "husky install"
1213
},
1314
"dependencies": {
1415
"@svgr/webpack": "^6.5.1",
@@ -20,13 +21,17 @@
2021
"@vercel/analytics": "^0.1.11",
2122
"cross-env": "^7.0.3",
2223
"emoji-picker-react": "^4.4.7",
23-
"eslint": "8.35.0",
24+
"eslint": "^8.36.0",
2425
"eslint-config-next": "13.2.3",
26+
"eslint-config-prettier": "^8.8.0",
27+
"eslint-plugin-prettier": "^4.2.1",
2528
"eventsource-parser": "^0.1.0",
2629
"fuse.js": "^6.6.2",
30+
"lint-staged": "^13.2.0",
2731
"next": "^13.2.3",
2832
"node-fetch": "^3.3.1",
2933
"openai": "^3.2.1",
34+
"prettier": "^2.8.7",
3035
"react": "^18.2.0",
3136
"react-dom": "^18.2.0",
3237
"react-markdown": "^8.0.5",
@@ -39,5 +44,8 @@
3944
"typescript": "4.9.5",
4045
"use-debounce": "^9.0.3",
4146
"zustand": "^4.3.6"
47+
},
48+
"devDependencies": {
49+
"husky": "^8.0.0"
4250
}
4351
}

0 commit comments

Comments
 (0)