Skip to content

Commit ed61bc7

Browse files
authored
refactor: Formatting and linting (#71)
* chore: Remove .prettierc configuration file * chore: Add Prettier configuration files - Introduced .prettierignore to exclude unnecessary files from formatting. - Added .prettierrc with custom formatting rules to ensure consistent code style across the project. * style: Standardize quotes in codebase - Replaced double quotes with single quotes in various files for consistency across the codebase. - Updated configuration files, service definitions, and test cases to adhere to the new style guide. - Ensured that all instances of string literals are uniformly formatted to enhance readability and maintainability. * chore: Add ESLint configuration and ignore files - Introduced .eslintignore to exclude unnecessary files and directories from linting. - Added eslint.config.js to establish linting rules and configurations for JavaScript and TypeScript files. - Updated package.json to include ESLint as a development dependency and added linting scripts for code quality enforcement. * refactor: Reorganize import statements across multiple files - Cleaned up import statements in various files by rearranging and consolidating imports for better readability and maintainability. - Ensured consistent import order and structure, enhancing the overall organization of the codebase. - Updated test files to reflect the new import structure, ensuring all tests remain functional and organized. * chore: Remove .eslintignore and update ESLint configuration - Deleted the .eslintignore file to streamline linting processes. - Updated eslint.config.js to refine file patterns for TypeScript and JavaScript linting, ensuring only relevant files are included and unnecessary directories are ignored. * chore: Remove unused extractContentFromTags function and its tests - Deleted the extractContentFromTags function from parsers.ts as it is no longer needed. - Removed associated test cases from parsers.test.ts to maintain a clean codebase and eliminate redundancy. * refactor: Simplify stream response handling in handleStreamResponse function - Replaced nested for loop with forEach for better readability and maintainability. - Added early return for lines not starting with 'data: ' to reduce nesting and improve clarity. - Ensured that error handling remains intact while enhancing the overall structure of the code. * refactor: Enhance type safety in TimestampConverterTool methods - Updated the execute and getRawData methods to explicitly return a Promise of string or number, improving type safety and clarity. - Ensured that the method signatures align with TypeScript best practices, enhancing maintainability and reducing potential runtime errors. * refactor: Improve error handling and response fetching in ThirdWebTool - Introduced a new private method `handleNebulaError` to centralize error handling for Axios requests, enhancing code clarity and maintainability. - Refactored the `askNebula` method to utilize `fetchNebulaResponse`, separating concerns and improving readability. - Ensured that error messages are more descriptive and consistent, adhering to best practices for user feedback. * refactor: Enhance type safety and clarity in revenue-related methods - Introduced explicit return types for methods in RevenueExecutor and RevenueDataExecutor, improving type safety and maintainability. - Added inferred types for RevenueResponse and RevenueProjectResponse to ensure consistency and clarity in data handling. - Updated getRawData methods in DePINNinjaTool and DePINScanMetricsTool to reflect new type definitions, enhancing overall code quality. * refactor: Enhance type safety and clarity in DefiLlamaExecutor methods - Removed default values for optional parameters to improve clarity and enforce explicit handling. - Introduced inferred types for parameters and return values in execute methods, enhancing type safety across the DefiLlamaExecutor and its subclasses. - Simplified method signatures and improved overall code readability by ensuring consistent type definitions. * refactor: Improve type safety and clarity in LLM interface and implementations * chore: Remove stream_utils and associated tests - Deleted the stream_utils.ts file and its corresponding test file to eliminate unused code and maintain a clean codebase. - This removal aligns with ongoing efforts to streamline the code and improve maintainability. * refactor: Improve error handling and return type in processStream method - Updated the return type of processStream to Response for better type safety and clarity. - Changed the error handling to return a Response object instead of a string, enhancing consistency in response types. - This refactor aligns with ongoing efforts to improve maintainability and adhere to best practices in error handling. * refactor: Enhance PebbleTool implementation with improved structure and type safety - Refactored PebbleTool to extend APITool, improving adherence to SOLID principles and enhancing maintainability. - Introduced Zod schemas for input validation, ensuring type safety and clarity in parameter handling. - Simplified the execute method and added private methods for geolocation extraction and Pebble data fetching, improving code readability and separation of concerns. - Enhanced error handling and logging for better user feedback and debugging capabilities. * refactor: Simplify getRawData method by extracting coordinate logic - Refactored the getRawData method in MapboxTool to improve readability and maintainability by introducing a new private method, extractCoordinates, for handling origin and destination coordinate extraction. - This change adheres to the single-responsibility principle, enhancing code clarity and separation of concerns. * refactor: Simplify iCalendar parsing logic in LumaEventsTool - Refactored the parseICalendar method by extracting property handling into dedicated private methods: handleProperty, startNewProperty, continuePrevProperty, and handleCommonProperties. - This change enhances code readability and maintainability by adhering to the single-responsibility principle and improving the overall structure of the parsing logic. * refactor: Remove unused storeEventsInKnowledgeBase method from LumaEventsTool - Deleted the optional storeEventsInKnowledgeBase method to streamline the LumaEventsTool class and eliminate unnecessary code. - This change enhances maintainability by adhering to the single-responsibility principle and reducing potential confusion in the codebase. * refactor: Rename Zod schemas and streamline data fetching in L1DataTool - Renamed Zod schemas to include an underscore prefix for clarity and potential future use. - Refactored the data fetching logic by introducing a new private method, runFetchers, to enhance readability and maintainability. - Added helper methods for error logging and result handling, improving code structure and adherence to the single-responsibility principle. * refactor: Introduce metrics abstraction and streamline result handling in L1DataTool - Added a centralized metrics object to improve clarity and maintainability of metric keys. - Refactored the buildResults method to utilize a Map for results, enhancing type safety and reducing redundancy. - Updated logErrors and runFetchers methods to align with the new metrics structure, improving code organization and adherence to the single-responsibility principle. - Introduced a MetricFetcher interface to encapsulate fetching logic, further enhancing code clarity and maintainability. * refactor: Enhance IoIDTool implementation with Zod validation and improved structure - Refactored IoIDTool to extend APITool, improving adherence to SOLID principles and enhancing maintainability. - Introduced Zod schemas for input validation, ensuring type safety and clarity in parameter handling. - Simplified the execute method and added a dedicated getRawData method for better separation of concerns. - Improved error handling by utilizing Zod for input parsing, enhancing code readability and maintainability. * refactor: Enhance type safety and clarity in tool implementations - Updated method signatures across multiple tools to include explicit return types, improving type safety and code clarity. - Introduced a new type alias for AirQualityResponse to enhance readability and maintainability. - Refactored the register method in ToolRegistry to specify a return type of void, aligning with best practices for method definitions. - These changes contribute to a cleaner codebase and adherence to SOLID principles. * refactor: Streamline project filtering logic and enhance number formatting - Refactored the filterProjects function to utilize a more modular approach with dedicated filter predicates, improving readability and maintainability. - Introduced a numberOrZeroIfNanToString utility function for consistent number formatting, enhancing clarity in data presentation. - These changes adhere to the single-responsibility principle and improve the overall structure of the codebase. * refactor: Extract query parameter logic into dedicated methods - Refactored the getRawData and getMetadataV2 methods to improve readability and maintainability by extracting query parameter construction into private methods: buildSearchParams and populateQueryParams. - This change adheres to the single-responsibility principle, enhancing code clarity and separation of concerns. * chore: Add globals package for improved linting support - Included the "globals" package in package.json to enhance linting capabilities and ensure better code quality. - This addition supports the overall goal of maintaining a clean and maintainable codebase. * refactor: Enhance ESLint configuration for improved linting and code quality - Updated the ESLint configuration to include a new base ruleset for production code, improving maintainability and adherence to clean code principles. - Introduced specific configurations for test files, allowing for more flexible linting rules while still enforcing key clean code practices. - This refactor aims to streamline the linting process and ensure a consistent coding standard across the codebase. * chore: Add pnpm-lock.yaml for dependency management - Introduced a new pnpm-lock.yaml file to manage project dependencies effectively. - This addition ensures consistent dependency resolution and enhances the overall maintainability of the codebase. - The lockfile version is set to '9.0', aligning with the latest standards for package management. * chore: Update .prettierignore to include ESLint and pnpm lock files - Added .eslintrc.js and pnpm-lock.yaml to .prettierignore to prevent formatting issues with these configuration files. - This change supports better project organization and maintains a clean codebase by ensuring that essential configuration files are excluded from formatting processes. * refactor: Improve code formatting and structure in tests and llm module - Updated test files to enhance readability by removing unnecessary blank lines and simplifying mock implementations. - Refactored import statements in the llm module for better organization and clarity, adhering to clean code principles. - These changes contribute to a more maintainable and elegant codebase. * chore: Update GitHub Actions workflow for improved dependency management - Upgraded the checkout action to v4 for better performance and reliability. - Replaced Node.js setup with Bun setup to streamline the JavaScript runtime environment. - Introduced pnpm for dependency installation and added linting step to ensure code quality. - These changes enhance the CI/CD process and maintain a clean, efficient workflow.
1 parent 6cee1b3 commit ed61bc7

Some content is hidden

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

77 files changed

+9618
-4195
lines changed

.github/workflows/docker-image.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Docker Image CI
22

33
on:
44
push:
5-
branches: ["main"]
5+
branches: ['main']
66
pull_request:
7-
branches: ["main"]
7+
branches: ['main']
88

99
jobs:
1010
build-and-scan:
@@ -56,11 +56,11 @@ jobs:
5656
uses: aquasecurity/trivy-action@master
5757
with:
5858
image-ref: ghcr.io/${{ github.repository_owner }}/quicksilver:latest
59-
format: "table"
60-
exit-code: "0"
59+
format: 'table'
60+
exit-code: '0'
6161
ignore-unfixed: true
62-
vuln-type: "os,library"
63-
severity: "CRITICAL,HIGH"
62+
vuln-type: 'os,library'
63+
severity: 'CRITICAL,HIGH'
6464

6565
# Only push if this is a push to main (not a PR)
6666
- name: Push Docker Image

.github/workflows/test.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,23 @@ jobs:
1414

1515
steps:
1616
- name: Checkout code
17-
uses: actions/checkout@v2
17+
uses: actions/checkout@v4
1818

19-
- name: Set up Node.js
20-
uses: actions/setup-node@v3
19+
- name: Setup Bun
20+
uses: oven-sh/setup-bun@v1
2121
with:
22-
node-version: "22"
22+
bun-version: '1.1.43'
23+
24+
- name: Setup pnpm
25+
uses: pnpm/action-setup@v3
26+
with:
27+
version: latest
2328

2429
- name: Install dependencies
25-
run: npm install
30+
run: pnpm install
31+
32+
- name: Run lint
33+
run: pnpm lint
2634

2735
- name: Run tests
28-
run: npm test
36+
run: pnpm test

.prettierc

Lines changed: 0 additions & 5 deletions
This file was deleted.

.prettierignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
node_modules
2+
dist
3+
coverage
4+
.env
5+
.env.*
6+
configs
7+
.gitignore
8+
.git
9+
.vscode
10+
.DS_Store
11+
.idea
12+
.eslintrc.js
13+
pnpm-lock.yaml

.prettierrc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"printWidth": 120,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": true,
6+
"singleQuote": true,
7+
"trailingComma": "es5",
8+
"bracketSpacing": true,
9+
"arrowParens": "avoid",
10+
"endOfLine": "lf",
11+
"bracketSameLine": false,
12+
"quoteProps": "as-needed",
13+
"proseWrap": "preserve",
14+
"embeddedLanguageFormatting": "auto"
15+
}

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ You can configure both the fast LLM and primary LLM providers in the SentientAI
202202

203203
```typescript
204204
new SentientAI({
205-
fastLLMProvider: "openai", // For quick processing
206-
llmProvider: "deepseek", // For main reasoning
205+
fastLLMProvider: 'openai', // For quick processing
206+
llmProvider: 'deepseek', // For main reasoning
207207
});
208208
```
209209

@@ -308,31 +308,31 @@ PORT=8003
308308
### Docker Compose Example
309309

310310
```yaml
311-
version: "3"
311+
version: '3'
312312

313313
services:
314314
# Weather instance
315315
weather:
316316
image: qs:main
317317
env_file: ${CONFIG_PATH:-configs/instances/weather.env}
318318
ports:
319-
- "8001:8000"
319+
- '8001:8000'
320320
restart: always
321321

322322
# News instance
323323
news:
324324
image: qs:main
325325
env_file: ${CONFIG_PATH:-configs/instances/news.env}
326326
ports:
327-
- "8002:8000"
327+
- '8002:8000'
328328
restart: always
329329

330330
# IoT instance
331331
iot:
332332
image: qs:main
333333
env_file: ${CONFIG_PATH:-configs/instances/iot.env}
334334
ports:
335-
- "8003:8000"
335+
- '8003:8000'
336336
restart: always
337337
```
338338

__tests__/server.test.ts

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
1+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
22

3-
import app from "../server";
4-
import { logger } from "../src/logger/winston";
3+
import app from '../server';
4+
import { logger } from '../src/logger/winston';
55

6-
describe("Server", () => {
6+
describe('Server', () => {
77
let testApp = app.fetch;
88

99
beforeEach(() => {
10-
vi.mock("../src/sentientAI", () => ({
10+
vi.mock('../src/sentientAI', () => ({
1111
SentientAI: vi.fn().mockImplementation(() => ({
1212
async execute(_: string): Promise<string> {
13-
return "mocked response";
13+
return 'mocked response';
1414
},
1515
})),
1616
}));
@@ -20,97 +20,97 @@ describe("Server", () => {
2020
vi.clearAllMocks();
2121
});
2222

23-
it("should return hello world on GET /", async () => {
24-
const req = new Request("http://localhost");
23+
it('should return hello world on GET /', async () => {
24+
const req = new Request('http://localhost');
2525
const res = await testApp(req);
2626
expect(res.status).toBe(200);
2727
const text = await res.text();
28-
expect(text).toBe("hello world, Sentient AI!");
28+
expect(text).toBe('hello world, Sentient AI!');
2929
});
3030

31-
it("should accept content via query param q in POST /ask", async () => {
32-
const req = new Request("http://localhost/ask?q=test question", {
33-
method: "POST",
31+
it('should accept content via query param q in POST /ask', async () => {
32+
const req = new Request('http://localhost/ask?q=test question', {
33+
method: 'POST',
3434
});
3535
const res = await testApp(req);
3636
expect(res.status).toBe(200);
3737
const json = await res.json();
38-
expect(json.data).toBe("mocked response");
38+
expect(json.data).toBe('mocked response');
3939
}, 10000);
4040

41-
it("should accept content via query param content in POST /ask", async () => {
42-
const req = new Request("http://localhost/ask?content=test question", {
43-
method: "POST",
41+
it('should accept content via query param content in POST /ask', async () => {
42+
const req = new Request('http://localhost/ask?content=test question', {
43+
method: 'POST',
4444
});
4545
const res = await testApp(req);
4646
expect(res.status).toBe(200);
4747
const json = await res.json();
48-
expect(json.data).toBe("mocked response");
48+
expect(json.data).toBe('mocked response');
4949
}, 10000);
5050

51-
it("should accept content via JSON body.content in POST /ask", async () => {
52-
const req = new Request("http://localhost/ask", {
53-
method: "POST",
51+
it('should accept content via JSON body.content in POST /ask', async () => {
52+
const req = new Request('http://localhost/ask', {
53+
method: 'POST',
5454
headers: {
55-
"Content-Type": "application/json",
55+
'Content-Type': 'application/json',
5656
},
5757
body: JSON.stringify({
58-
content: "test question",
58+
content: 'test question',
5959
}),
6060
});
6161
const res = await testApp(req);
6262
expect(res.status).toBe(200);
6363
const json = await res.json();
64-
expect(json.data).toBe("mocked response");
64+
expect(json.data).toBe('mocked response');
6565
}, 10000);
6666

67-
it("should accept content via JSON body.q in POST /ask", async () => {
68-
const req = new Request("http://localhost/ask", {
69-
method: "POST",
67+
it('should accept content via JSON body.q in POST /ask', async () => {
68+
const req = new Request('http://localhost/ask', {
69+
method: 'POST',
7070
headers: {
71-
"Content-Type": "application/json",
71+
'Content-Type': 'application/json',
7272
},
7373
body: JSON.stringify({
74-
q: "test question",
74+
q: 'test question',
7575
}),
7676
});
7777
const res = await testApp(req);
7878
expect(res.status).toBe(200);
7979
const json = await res.json();
80-
expect(json.data).toBe("mocked response");
80+
expect(json.data).toBe('mocked response');
8181
}, 10000);
8282

83-
it("should log warning when no API key provided", async () => {
84-
const consoleSpy = vi.spyOn(logger, "warn");
85-
const req = new Request("http://localhost/ask?q=test", {
86-
method: "POST",
83+
it('should log warning when no API key provided', async () => {
84+
const consoleSpy = vi.spyOn(logger, 'warn');
85+
const req = new Request('http://localhost/ask?q=test', {
86+
method: 'POST',
8787
});
8888
await testApp(req);
89-
expect(consoleSpy).toHaveBeenCalledWith("no SENTAI API-KEY provided");
89+
expect(consoleSpy).toHaveBeenCalledWith('no SENTAI API-KEY provided');
9090
consoleSpy.mockRestore();
9191
});
9292

93-
it("should fail when no json body in POST /ask", async () => {
94-
const req = new Request("http://localhost/ask", {
95-
method: "POST",
93+
it('should fail when no json body in POST /ask', async () => {
94+
const req = new Request('http://localhost/ask', {
95+
method: 'POST',
9696
});
9797
const res = await testApp(req);
9898
expect(res.status).toBe(400);
9999
const json = await res.json();
100-
expect(json.error).toBe("Internal server error.");
100+
expect(json.error).toBe('Internal server error.');
101101
});
102102

103-
it("should fail when no content in POST /ask", async () => {
104-
const req = new Request("http://localhost/ask", {
105-
method: "POST",
103+
it('should fail when no content in POST /ask', async () => {
104+
const req = new Request('http://localhost/ask', {
105+
method: 'POST',
106106
headers: {
107-
"Content-Type": "application/json",
107+
'Content-Type': 'application/json',
108108
},
109109
body: JSON.stringify({}),
110110
});
111111
const res = await testApp(req);
112112
expect(res.status).toBe(400);
113113
const json = await res.json();
114-
expect(json.error).toBe("question is required.");
114+
expect(json.error).toBe('question is required.');
115115
});
116116
});

docker-compose.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ services:
33
image: ghcr.io/iotexproject/quicksilver:latest
44
env_file: configs/.env.latest
55
ports:
6-
- "33333:3000"
7-
- "8000:8000"
6+
- '33333:3000'
7+
- '8000:8000'
88
restart: always
99

1010
dimo:
1111
image: ghcr.io/iotexproject/quicksilver:latest
1212
env_file: configs/.env.dimo
1313
ports:
14-
- "33334:3000"
15-
- "8001:8000"
14+
- '33334:3000'
15+
- '8001:8000'
1616
restart: always

0 commit comments

Comments
 (0)