Skip to content

Commit 6e05c0f

Browse files
Merge pull request #490 from snobbee/test/add-linter-to-all-packages
test: add linter to all packages and enable vitest
2 parents 2335a92 + cf06999 commit 6e05c0f

File tree

92 files changed

+781
-247
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+781
-247
lines changed

.github/workflows/ci.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ jobs:
2525
- name: Run Prettier
2626
run: pnpm run prettier --check .
2727

28+
- name: Run Linter
29+
run: pnpm run lint
30+
2831
- name: Create test env file
2932
run: |
3033
echo "TEST_DATABASE_CLIENT=sqlite" > packages/core/.env.test

.husky/pre-commit

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pnpm run prettier-check
2+
pnpm run lint

eslint.global.mjs

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import eslint from "@eslint/js";
2+
import tseslint from "@typescript-eslint/eslint-plugin";
3+
import typescript from "@typescript-eslint/parser";
4+
import prettier from "eslint-config-prettier";
5+
import vitest from "eslint-plugin-vitest"; // Add Vitest plugin
6+
7+
export default [
8+
// JavaScript and TypeScript files
9+
{
10+
files: ["src/**/*.js", "src/**/*.cjs", "src/**/*.mjs", "src/**/*.ts"],
11+
languageOptions: {
12+
parser: typescript,
13+
parserOptions: {
14+
ecmaVersion: "latest",
15+
sourceType: "module",
16+
project: "./tsconfig.json", // Make sure your tsconfig includes @types/node
17+
},
18+
globals: {
19+
// Add Node.js globals
20+
NodeJS: "readonly",
21+
console: "readonly",
22+
process: "readonly",
23+
Buffer: "readonly",
24+
__dirname: "readonly",
25+
__filename: "readonly",
26+
module: "readonly",
27+
require: "readonly",
28+
},
29+
},
30+
plugins: {
31+
"@typescript-eslint": tseslint,
32+
},
33+
rules: {
34+
...eslint.configs.recommended.rules,
35+
...tseslint.configs.recommended.rules,
36+
"prefer-const": "warn",
37+
"no-constant-binary-expression": "error",
38+
39+
// Disable no-undef as TypeScript handles this better
40+
"no-undef": "off",
41+
"@typescript-eslint/no-unsafe-function-type": "off",
42+
// Customize TypeScript rules
43+
"@typescript-eslint/no-explicit-any": "off",
44+
"@typescript-eslint/no-unused-vars": [
45+
"error",
46+
{
47+
argsIgnorePattern: "^_",
48+
varsIgnorePattern: "^_",
49+
ignoreRestSiblings: true,
50+
},
51+
],
52+
},
53+
},
54+
// Vitest configuration
55+
{
56+
files: [
57+
"src/**/*.test.js",
58+
"src/**/*.test.ts",
59+
"src/**/*.spec.js",
60+
"src/**/*.spec.ts",
61+
],
62+
plugins: {
63+
vitest, // Register Vitest plugin
64+
},
65+
rules: {
66+
...vitest.configs.recommended.rules,
67+
},
68+
},
69+
// Add prettier as the last config to override other formatting rules
70+
prettier,
71+
];

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"start": "pnpm --filter \"@ai16z/agent\" start --isRoot",
1111
"start:client": "pnpm --dir client start --isRoot",
1212
"dev": "bash ./scripts/dev.sh",
13-
"lint": "pnpm --dir packages/core lint && pnpm --dir packages/agent lint",
13+
"lint": "bash ./scripts/lint.sh",
1414
"prettier-check": "npx prettier --check .",
1515
"prettier": "npx prettier --write .",
1616
"release": "pnpm build && pnpm prettier && npx lerna publish --no-private --force-publish",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import eslintGlobalConfig from "../../eslint.global.mjs";
2+
3+
export default [...eslintGlobalConfig];

packages/adapter-postgres/package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@
1010
"pg": "^8.13.1"
1111
},
1212
"devDependencies": {
13+
"eslint": "9.13.0",
14+
"eslint-config-prettier": "9.1.0",
15+
"eslint-plugin-prettier": "5.2.1",
16+
"eslint-plugin-vitest": "0.5.4",
1317
"tsup": "^8.3.5"
1418
},
1519
"scripts": {
1620
"build": "tsup --format esm --dts",
17-
"dev": "tsup --format esm --dts --watch"
21+
"dev": "tsup --format esm --dts --watch",
22+
"lint": "eslint . --fix"
1823
}
1924
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import eslintGlobalConfig from "../../eslint.global.mjs";
2+
3+
export default [...eslintGlobalConfig];

packages/adapter-sqlite/package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@
1111
"sqlite-vec": "0.1.4-alpha.2"
1212
},
1313
"devDependencies": {
14+
"eslint": "9.13.0",
15+
"eslint-config-prettier": "9.1.0",
16+
"eslint-plugin-prettier": "5.2.1",
17+
"eslint-plugin-vitest": "0.5.4",
1418
"tsup": "^8.3.5"
1519
},
1620
"scripts": {
1721
"build": "tsup --format esm --dts",
18-
"dev": "tsup --format esm --dts --watch"
22+
"dev": "tsup --format esm --dts --watch",
23+
"lint": "eslint . --fix"
1924
},
2025
"peerDependencies": {
2126
"whatwg-url": "7.1.0"

packages/adapter-sqlite/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export class SqliteDatabaseAdapter
153153
}
154154
const placeholders = params.roomIds.map(() => "?").join(", ");
155155
let sql = `SELECT * FROM memories WHERE type = ? AND roomId IN (${placeholders})`;
156-
let queryParams = [params.tableName, ...params.roomIds];
156+
const queryParams = [params.tableName, ...params.roomIds];
157157

158158
if (params.agentId) {
159159
sql += ` AND agentId = ?`;
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import eslintGlobalConfig from "../../eslint.global.mjs";
2+
3+
export default [...eslintGlobalConfig];

packages/adapter-sqljs/package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@
1111
"uuid": "11.0.2"
1212
},
1313
"devDependencies": {
14+
"eslint": "9.13.0",
15+
"eslint-config-prettier": "9.1.0",
16+
"eslint-plugin-prettier": "5.2.1",
17+
"eslint-plugin-vitest": "0.5.4",
1418
"tsup": "^8.3.5"
1519
},
1620
"scripts": {
1721
"build": "tsup --format esm --dts",
18-
"dev": "tsup --watch"
22+
"dev": "tsup --watch",
23+
"lint": "eslint . --fix"
1924
},
2025
"peerDependencies": {
2126
"whatwg-url": "7.1.0"

packages/adapter-sqljs/src/types.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ export declare class Database {
126126

127127
close(): void;
128128

129-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
130129
create_function(name: string, func: (...args: any[]) => any): Database;
131130

132131
each(
@@ -135,7 +134,7 @@ export declare class Database {
135134
callback: ParamsCallback,
136135
done: () => void
137136
): Database;
138-
each(sql: string, callback: ParamsCallback, done: () => void): Database;
137+
each(sql: string, callback: ParamsCallback, done: () => void): Database; // eslint-disable-line
139138

140139
/**
141140
* Execute an SQL query, and returns the result.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import eslintGlobalConfig from "../../eslint.global.mjs";
2+
3+
export default [...eslintGlobalConfig];

packages/adapter-supabase/package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@
99
"@supabase/supabase-js": "2.46.1"
1010
},
1111
"devDependencies": {
12+
"eslint": "9.13.0",
13+
"eslint-config-prettier": "9.1.0",
14+
"eslint-plugin-prettier": "5.2.1",
15+
"eslint-plugin-vitest": "0.5.4",
1216
"tsup": "^8.3.5"
1317
},
1418
"scripts": {
1519
"build": "tsup --format esm --dts",
16-
"dev": "tsup --watch"
20+
"dev": "tsup --watch",
21+
"lint": "eslint . --fix"
1722
},
1823
"peerDependencies": {
1924
"whatwg-url": "7.1.0"
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import eslintGlobalConfig from "../../eslint.global.mjs";
2+
3+
export default [...eslintGlobalConfig];

packages/client-auto/package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@
1717
"multer": "1.4.5-lts.1"
1818
},
1919
"devDependencies": {
20+
"eslint": "9.13.0",
21+
"eslint-config-prettier": "9.1.0",
22+
"eslint-plugin-prettier": "5.2.1",
23+
"eslint-plugin-vitest": "0.5.4",
2024
"tsup": "^8.3.5"
2125
},
2226
"scripts": {
2327
"build": "tsup --format esm --dts",
24-
"dev": "tsup --watch"
28+
"dev": "tsup --watch",
29+
"lint": "eslint . --fix"
2530
},
2631
"peerDependencies": {
2732
"whatwg-url": "7.1.0"

packages/client-auto/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class AutoClient {
5252
);
5353

5454
// get information for all tokens which were recommended
55-
const tokenInfos = highTrustRecommendations.map(
55+
const _tokenInfos = highTrustRecommendations.map(
5656
async (highTrustRecommendation) => {
5757
const tokenProvider = new TokenProvider(
5858
highTrustRecommendation.tokenAddress,
@@ -87,7 +87,7 @@ export const AutoClientInterface: Client = {
8787
const client = new AutoClient(runtime);
8888
return client;
8989
},
90-
stop: async (runtime: IAgentRuntime) => {
90+
stop: async (_runtime: IAgentRuntime) => {
9191
console.warn("Direct client does not support stopping yet");
9292
},
9393
};
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import eslintGlobalConfig from "../../eslint.global.mjs";
2+
3+
export default [...eslintGlobalConfig];

packages/client-direct/package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@
1616
"multer": "1.4.5-lts.1"
1717
},
1818
"devDependencies": {
19+
"eslint": "9.13.0",
20+
"eslint-config-prettier": "9.1.0",
21+
"eslint-plugin-prettier": "5.2.1",
22+
"eslint-plugin-vitest": "0.5.4",
1923
"tsup": "^8.3.5"
2024
},
2125
"scripts": {
2226
"build": "tsup --format esm --dts",
23-
"dev": "tsup --watch"
27+
"dev": "tsup --watch",
28+
"lint": "eslint . --fix"
2429
},
2530
"peerDependencies": {
2631
"whatwg-url": "7.1.0"

packages/client-direct/src/index.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
Content,
1212
Memory,
1313
ModelClass,
14-
State,
1514
Client,
1615
IAgentRuntime,
1716
} from "@ai16z/eliza";
@@ -222,7 +221,7 @@ export class DirectClient {
222221

223222
await runtime.evaluate(memory, state);
224223

225-
const result = await runtime.processActions(
224+
const _result = await runtime.processActions(
226225
memory,
227226
[responseMessage],
228227
state,
@@ -285,14 +284,14 @@ export class DirectClient {
285284
}
286285

287286
export const DirectClientInterface: Client = {
288-
start: async (runtime: IAgentRuntime) => {
287+
start: async (_runtime: IAgentRuntime) => {
289288
elizaLogger.log("DirectClientInterface start");
290289
const client = new DirectClient();
291290
const serverPort = parseInt(settings.SERVER_PORT || "3000");
292291
client.start(serverPort);
293292
return client;
294293
},
295-
stop: async (runtime: IAgentRuntime) => {
294+
stop: async (_runtime: IAgentRuntime) => {
296295
elizaLogger.warn("Direct client does not support stopping yet");
297296
},
298297
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import eslintGlobalConfig from "../../eslint.global.mjs";
2+
3+
export default [...eslintGlobalConfig];

packages/client-discord/package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@
1616
"zod": "3.23.8"
1717
},
1818
"devDependencies": {
19+
"eslint": "9.13.0",
20+
"eslint-config-prettier": "9.1.0",
21+
"eslint-plugin-prettier": "5.2.1",
22+
"eslint-plugin-vitest": "0.5.4",
1923
"tsup": "^8.3.5"
2024
},
2125
"scripts": {
2226
"build": "tsup --format esm --dts",
23-
"dev": "tsup --watch"
27+
"dev": "tsup --watch",
28+
"lint": "eslint . --fix"
2429
},
2530
"trustedDependencies": {
2631
"@discordjs/opus": "github:discordjs/opus",

packages/client-discord/src/actions/chat_with_attachments.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ const summarizeAction = {
9191
],
9292
description:
9393
"Answer a user request informed by specific attachments based on their IDs. If a user asks to chat with a PDF, or wants more specific information about a link or video or anything else they've attached, this is the action to use.",
94-
validate: async (runtime: IAgentRuntime, message: Memory, state: State) => {
94+
validate: async (
95+
_runtime: IAgentRuntime,
96+
message: Memory,
97+
_state: State
98+
) => {
9599
if (message.content.source !== "discord") {
96100
return false;
97101
}

packages/client-discord/src/actions/download_media.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
IVideoService,
1111
Memory,
1212
ModelClass,
13-
Service,
1413
ServiceType,
1514
State,
1615
} from "@ai16z/eliza";
@@ -73,7 +72,11 @@ export default {
7372
],
7473
description:
7574
"Downloads a video or audio file from a URL and attaches it to the response message.",
76-
validate: async (runtime: IAgentRuntime, message: Memory, state: State) => {
75+
validate: async (
76+
runtime: IAgentRuntime,
77+
message: Memory,
78+
_state: State
79+
) => {
7780
if (message.content.source !== "discord") {
7881
return false;
7982
}

packages/client-discord/src/actions/joinvoice.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// eslint-disable-next-line
12
// @ts-nocheck
23
// src/actions/joinVoice
34
import {
@@ -167,7 +168,7 @@ You should only respond with the name of the voice channel or none, no commentar
167168
state: guessState as unknown as State,
168169
});
169170

170-
const datestr = new Date().toUTCString().replace(/:/g, "-");
171+
const _datestr = new Date().toUTCString().replace(/:/g, "-");
171172

172173
const responseContent = await generateText({
173174
runtime,

packages/client-discord/src/actions/leavevoice.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export default {
9090
(channel: Channel) => channel.type === ChannelType.GuildVoice
9191
);
9292

93-
voiceChannels?.forEach((channel: Channel) => {
93+
voiceChannels?.forEach((_channel: Channel) => {
9494
const connection = getVoiceConnection(
9595
(discordMessage as DiscordMessage).guild?.id as string
9696
);

packages/client-discord/src/actions/summarize_conversation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ const summarizeAction = {
253253

254254
const chunks = await splitChunks(formattedMemories, chunkSize, 0);
255255

256-
const datestr = new Date().toUTCString().replace(/:/g, "-");
256+
const _datestr = new Date().toUTCString().replace(/:/g, "-");
257257

258258
state.memoriesWithAttachments = formattedMemories;
259259
state.objective = objective;

0 commit comments

Comments
 (0)