Skip to content

Commit

Permalink
feat: add lint-staged
Browse files Browse the repository at this point in the history
  • Loading branch information
Yidadaa committed Mar 28, 2023
1 parent 8340009 commit e648a59
Show file tree
Hide file tree
Showing 8 changed files with 467 additions and 61 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": "next/core-web-vitals"
"extends": "next/core-web-vitals",
"plugins": ["prettier"]
}
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
6 changes: 6 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"./app/**/*.{js,ts,jsx,tsx,json,html,css,scss,md}": [
"eslint --fix",
"prettier --write"
]
}
10 changes: 10 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
printWidth: 80,
tabWidth: 2,
useTabs: false,
semi: true,
singleQuote: false,
trailingComma: 'all',
bracketSpacing: true,
arrowParens: 'always',
};
2 changes: 1 addition & 1 deletion app/locales/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import TW from "./tw";
export type { LocaleType } from "./cn";

export const AllLangs = ["en", "cn", "tw"] as const;
type Lang = typeof AllLangs[number];
type Lang = (typeof AllLangs)[number];

const LANG_KEY = "lang";

Expand Down
26 changes: 13 additions & 13 deletions app/store/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ interface ChatStore {
updateMessage: (
sessionIndex: number,
messageIndex: number,
updater: (message?: Message) => void
updater: (message?: Message) => void,
) => void;
getMessagesWithMemory: () => Message[];
getMemoryPrompt: () => Message;
Expand Down Expand Up @@ -342,7 +342,7 @@ export const useChatStore = create<ChatStore>()(
ControllerPool.addController(
sessionIndex,
messageIndex,
controller
controller,
);
},
filterBot: !get().config.sendBotMessages,
Expand All @@ -365,7 +365,7 @@ export const useChatStore = create<ChatStore>()(
const config = get().config;
const n = session.messages.length;
const recentMessages = session.messages.slice(
n - config.historyMessageCount
n - config.historyMessageCount,
);

const memoryPrompt = get().getMemoryPrompt();
Expand All @@ -380,7 +380,7 @@ export const useChatStore = create<ChatStore>()(
updateMessage(
sessionIndex: number,
messageIndex: number,
updater: (message?: Message) => void
updater: (message?: Message) => void,
) {
const sessions = get().sessions;
const session = sessions.at(sessionIndex);
Expand All @@ -397,24 +397,24 @@ export const useChatStore = create<ChatStore>()(
requestWithPrompt(session.messages, Locale.Store.Prompt.Topic).then(
(res) => {
get().updateCurrentSession(
(session) => (session.topic = trimTopic(res))
(session) => (session.topic = trimTopic(res)),
);
}
},
);
}

const config = get().config;
let toBeSummarizedMsgs = session.messages.slice(
session.lastSummarizeIndex
session.lastSummarizeIndex,
);
const historyMsgLength = toBeSummarizedMsgs.reduce(
(pre, cur) => pre + cur.content.length,
0
0,
);

if (historyMsgLength > 4000) {
toBeSummarizedMsgs = toBeSummarizedMsgs.slice(
-config.historyMessageCount
-config.historyMessageCount,
);
}

Expand All @@ -427,7 +427,7 @@ export const useChatStore = create<ChatStore>()(
"[Chat History] ",
toBeSummarizedMsgs,
historyMsgLength,
config.compressMessageLengthThreshold
config.compressMessageLengthThreshold,
);

if (historyMsgLength > config.compressMessageLengthThreshold) {
Expand All @@ -449,7 +449,7 @@ export const useChatStore = create<ChatStore>()(
onError(error) {
console.error("[Summarize] ", error);
},
}
},
);
}
},
Expand Down Expand Up @@ -478,6 +478,6 @@ export const useChatStore = create<ChatStore>()(
{
name: LOCAL_KEY,
version: 1,
}
)
},
),
);
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"build": "yarn fetch && next build",
"start": "next start",
"lint": "next lint",
"fetch": "node ./scripts/fetch-prompts.mjs"
"fetch": "node ./scripts/fetch-prompts.mjs",
"prepare": "husky install"
},
"dependencies": {
"@svgr/webpack": "^6.5.1",
Expand All @@ -20,13 +21,17 @@
"@vercel/analytics": "^0.1.11",
"cross-env": "^7.0.3",
"emoji-picker-react": "^4.4.7",
"eslint": "8.35.0",
"eslint": "^8.36.0",
"eslint-config-next": "13.2.3",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"eventsource-parser": "^0.1.0",
"fuse.js": "^6.6.2",
"lint-staged": "^13.2.0",
"next": "^13.2.3",
"node-fetch": "^3.3.1",
"openai": "^3.2.1",
"prettier": "^2.8.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-markdown": "^8.0.5",
Expand All @@ -39,5 +44,8 @@
"typescript": "4.9.5",
"use-debounce": "^9.0.3",
"zustand": "^4.3.6"
},
"devDependencies": {
"husky": "^8.0.0"
}
}
Loading

0 comments on commit e648a59

Please sign in to comment.