Skip to content

Commit b88ca0e

Browse files
authored
Merge pull request #52 from MetabobProject/style/run-prettier
Apply prettier formatting
2 parents 4c86828 + eea0be0 commit b88ca0e

Some content is hidden

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

49 files changed

+883
-827
lines changed

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ coverage
44
.history
55
out
66
node_modules
7+
package-lock.json

ext-src/__mocks__/vscode.ts

+98-88
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,130 @@
1-
21
// @ts-nocheck
32
// Mocked Uri interface
43
export interface Uri {
5-
scheme: string;
6-
path: string;
4+
scheme: string;
5+
path: string;
76
}
87

98
// Mocked Position class
109
export class Position {
11-
constructor(public line: number, public character: number) { }
10+
constructor(public line: number, public character: number) {}
1211

13-
isBefore(other: Position): boolean {
14-
return this.line < other.line || (this.line === other.line && this.character < other.character);
15-
}
12+
isBefore(other: Position): boolean {
13+
return this.line < other.line || (this.line === other.line && this.character < other.character);
14+
}
1615

17-
// Mocked methods
18-
isBeforeOrEqual = jest.fn((other: Position) => this.isBefore(other) || this.isEqual(other));
19-
isAfter = jest.fn((other: Position) => !this.isBeforeOrEqual(other));
20-
isAfterOrEqual = jest.fn((other: Position) => this.isAfter(other) || this.isEqual(other));
21-
isEqual = jest.fn((other: Position) => this.line === other.line && this.character === other.character);
22-
compareTo = jest.fn((other: Position) => {
23-
if (this.isBefore(other)) return -1;
24-
if (this.isAfter(other)) return 1;
25-
return 0;
26-
});
27-
translate = jest.fn((lineDelta?: number, characterDelta?: number) => {
28-
const line = typeof lineDelta === 'number' ? this.line + lineDelta : this.line;
29-
const character = typeof characterDelta === 'number' ? this.character + characterDelta : this.character;
30-
return new Position(line, character);
31-
});
32-
with = jest.fn((line?: number, character?: number) => new Position(line ?? this.line, character ?? this.character));
16+
// Mocked methods
17+
isBeforeOrEqual = jest.fn((other: Position) => this.isBefore(other) || this.isEqual(other));
18+
isAfter = jest.fn((other: Position) => !this.isBeforeOrEqual(other));
19+
isAfterOrEqual = jest.fn((other: Position) => this.isAfter(other) || this.isEqual(other));
20+
isEqual = jest.fn(
21+
(other: Position) => this.line === other.line && this.character === other.character,
22+
);
23+
compareTo = jest.fn((other: Position) => {
24+
if (this.isBefore(other)) return -1;
25+
if (this.isAfter(other)) return 1;
26+
return 0;
27+
});
28+
translate = jest.fn((lineDelta?: number, characterDelta?: number) => {
29+
const line = typeof lineDelta === 'number' ? this.line + lineDelta : this.line;
30+
const character =
31+
typeof characterDelta === 'number' ? this.character + characterDelta : this.character;
32+
return new Position(line, character);
33+
});
34+
with = jest.fn(
35+
(line?: number, character?: number) =>
36+
new Position(line ?? this.line, character ?? this.character),
37+
);
3338
}
3439

3540
// Mocked Range class
3641
export class Range {
37-
constructor(public start: Position, public end: Position) { }
42+
constructor(public start: Position, public end: Position) {}
3843

39-
isEmpty = jest.fn(() => this.start.isEqual(this.end));
40-
isSingleLine = jest.fn(() => this.start.line === this.end.line);
41-
contains = jest.fn((positionOrRange: Position | Range) => {
42-
if (positionOrRange instanceof Position) {
43-
return (
44-
(positionOrRange.isAfterOrEqual(this.start) && positionOrRange.isBefore(this.end)) ||
45-
positionOrRange.isEqual(this.start) ||
46-
positionOrRange.isEqual(this.end)
47-
);
48-
}
49-
return (
50-
this.contains(positionOrRange.start) ||
51-
this.contains(positionOrRange.end) ||
52-
(positionOrRange.start.isBeforeOrEqual(this.start) && positionOrRange.end.isAfterOrEqual(this.end))
53-
);
54-
});
55-
isEqual = jest.fn((other: Range) => this.start.isEqual(other.start) && this.end.isEqual(other.end));
56-
intersection = jest.fn((range: Range) => {
57-
const start = this.start.isBefore(range.start) ? range.start : this.start;
58-
const end = this.end.isAfter(range.end) ? range.end : this.end;
59-
return start.isBefore(end) ? new Range(start, end) : undefined;
60-
});
61-
union = jest.fn((other: Range) => {
62-
const start = this.start.isBefore(other.start) ? this.start : other.start;
63-
const end = this.end.isAfter(other.end) ? this.end : other.end;
64-
return new Range(start, end);
65-
});
66-
with = jest.fn((start?: Position, end?: Position) => new Range(start ?? this.start, end ?? this.end));
44+
isEmpty = jest.fn(() => this.start.isEqual(this.end));
45+
isSingleLine = jest.fn(() => this.start.line === this.end.line);
46+
contains = jest.fn((positionOrRange: Position | Range) => {
47+
if (positionOrRange instanceof Position) {
48+
return (
49+
(positionOrRange.isAfterOrEqual(this.start) && positionOrRange.isBefore(this.end)) ||
50+
positionOrRange.isEqual(this.start) ||
51+
positionOrRange.isEqual(this.end)
52+
);
53+
}
54+
return (
55+
this.contains(positionOrRange.start) ||
56+
this.contains(positionOrRange.end) ||
57+
(positionOrRange.start.isBeforeOrEqual(this.start) &&
58+
positionOrRange.end.isAfterOrEqual(this.end))
59+
);
60+
});
61+
isEqual = jest.fn(
62+
(other: Range) => this.start.isEqual(other.start) && this.end.isEqual(other.end),
63+
);
64+
intersection = jest.fn((range: Range) => {
65+
const start = this.start.isBefore(range.start) ? range.start : this.start;
66+
const end = this.end.isAfter(range.end) ? range.end : this.end;
67+
return start.isBefore(end) ? new Range(start, end) : undefined;
68+
});
69+
union = jest.fn((other: Range) => {
70+
const start = this.start.isBefore(other.start) ? this.start : other.start;
71+
const end = this.end.isAfter(other.end) ? this.end : other.end;
72+
return new Range(start, end);
73+
});
74+
with = jest.fn(
75+
(start?: Position, end?: Position) => new Range(start ?? this.start, end ?? this.end),
76+
);
6777
}
6878

6979
// Mocked TextDocument interface
7080
export interface TextDocument {
71-
uri: Uri;
72-
fileName: string;
73-
languageId: string;
74-
version: number;
75-
isDirty: boolean;
76-
isClosed: boolean;
81+
uri: Uri;
82+
fileName: string;
83+
languageId: string;
84+
version: number;
85+
isDirty: boolean;
86+
isClosed: boolean;
7787

78-
// Implement other properties and methods
88+
// Implement other properties and methods
7989
}
8090

8191
export class ExtensionContextMock {
82-
// Add any necessary properties and methods here for your tests
83-
subscriptions: { dispose: jest.Mock }[] = [];
92+
// Add any necessary properties and methods here for your tests
93+
subscriptions: { dispose: jest.Mock }[] = [];
8494

85-
// Mock method to subscribe to events
86-
subscribe(subscription: { dispose: jest.Mock }): void {
87-
this.subscriptions.push(subscription);
88-
}
95+
// Mock method to subscribe to events
96+
subscribe(subscription: { dispose: jest.Mock }): void {
97+
this.subscriptions.push(subscription);
98+
}
8999

90-
// Mock method to trigger disposal of subscriptions
91-
dispose(): void {
92-
this.subscriptions.forEach(sub => sub.dispose());
93-
this.subscriptions = [];
94-
}
100+
// Mock method to trigger disposal of subscriptions
101+
dispose(): void {
102+
this.subscriptions.forEach(sub => sub.dispose());
103+
this.subscriptions = [];
104+
}
95105
}
96106

97107
// Mocked vscode module
98108
const vscode = {
99-
version: '1.0.0',
100-
Position,
101-
Range,
102-
Uri: { scheme: '', path: '' },
103-
window: {
104-
activeTextEditor: {
105-
document: null as TextDocument | null,
106-
},
107-
},
108-
commands: {
109-
executeCommand: jest.fn(),
110-
},
111-
languages: {
112-
getTextDocument: jest.fn(),
113-
},
114-
env: {
115-
isTelemetryEnabled: true,
116-
machineId: '123456789',
109+
version: '1.0.0',
110+
Position,
111+
Range,
112+
Uri: { scheme: '', path: '' },
113+
window: {
114+
activeTextEditor: {
115+
document: null as TextDocument | null,
117116
},
117+
},
118+
commands: {
119+
executeCommand: jest.fn(),
120+
},
121+
languages: {
122+
getTextDocument: jest.fn(),
123+
},
124+
env: {
125+
isTelemetryEnabled: true,
126+
machineId: '123456789',
127+
},
118128
};
119129

120130
vscode.ExtensionContext = ExtensionContextMock;

ext-src/commands/FixSuggestion.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function activateFixSuggestionCommand(context: vscode.ExtensionContext):
3535
isReset: false,
3636
},
3737
});
38-
} catch (error) { }
38+
} catch (error) {}
3939

4040
vscode.commands.executeCommand('recommendation-panel-webview.focus');
4141
};

ext-src/config/index.spec.ts

+62-63
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,84 @@
11
//@ts-nocheck
22
jest.mock('vscode', () => ({
3-
...jest.requireActual<Record<string, unknown>>('vscode'),
4-
workspace: {
5-
getConfiguration: jest.fn(),
6-
},
7-
env: {
8-
isTelemetryEnabled: true,
9-
machineId: '123456789',
10-
},
3+
...jest.requireActual<Record<string, unknown>>('vscode'),
4+
workspace: {
5+
getConfiguration: jest.fn(),
6+
},
7+
env: {
8+
isTelemetryEnabled: true,
9+
machineId: '123456789',
10+
},
1111
}));
1212

1313
import * as vscode from 'vscode';
1414
import {
15-
GetAPIConfig,
16-
GetAPIBaseURLConfig,
17-
AnalyzeDocumentOnSaveConfig,
18-
GetChatGPTToken,
19-
BackendService,
20-
GetRequestParamId,
15+
GetAPIConfig,
16+
GetAPIBaseURLConfig,
17+
AnalyzeDocumentOnSaveConfig,
18+
GetChatGPTToken,
19+
BackendService,
20+
GetRequestParamId,
2121
} from './index';
2222

23-
2423
describe('Configuration Functions', () => {
25-
afterEach(() => {
26-
jest.clearAllMocks();
27-
});
24+
afterEach(() => {
25+
jest.clearAllMocks();
26+
});
2827

29-
describe('GetAPIConfig', () => {
30-
it('should return the API key configuration', () => {
31-
(vscode.workspace.getConfiguration as jest.Mock).mockReturnValue({
32-
get: jest.fn().mockReturnValue('api-key'),
33-
});
34-
const apiKey = GetAPIConfig();
35-
expect(apiKey).toBe('api-key');
36-
});
28+
describe('GetAPIConfig', () => {
29+
it('should return the API key configuration', () => {
30+
(vscode.workspace.getConfiguration as jest.Mock).mockReturnValue({
31+
get: jest.fn().mockReturnValue('api-key'),
32+
});
33+
const apiKey = GetAPIConfig();
34+
expect(apiKey).toBe('api-key');
3735
});
36+
});
3837

39-
describe('GetAPIBaseURLConfig', () => {
40-
it('should return the API base URL configuration', () => {
41-
(vscode.workspace.getConfiguration as jest.Mock).mockReturnValue({
42-
get: jest.fn().mockReturnValue('https://example.com'),
43-
});
44-
const baseURL = GetAPIBaseURLConfig();
45-
expect(baseURL).toBe('https://example.com');
46-
});
38+
describe('GetAPIBaseURLConfig', () => {
39+
it('should return the API base URL configuration', () => {
40+
(vscode.workspace.getConfiguration as jest.Mock).mockReturnValue({
41+
get: jest.fn().mockReturnValue('https://example.com'),
42+
});
43+
const baseURL = GetAPIBaseURLConfig();
44+
expect(baseURL).toBe('https://example.com');
4745
});
46+
});
4847

49-
describe('AnalyzeDocumentOnSaveConfig', () => {
50-
it('should return the AnalyzeDocumentOnSave configuration', () => {
51-
(vscode.workspace.getConfiguration as jest.Mock).mockReturnValue({
52-
get: jest.fn().mockReturnValue(true),
53-
});
54-
const analyzeOnSave = AnalyzeDocumentOnSaveConfig();
55-
expect(analyzeOnSave).toBe(true);
56-
});
48+
describe('AnalyzeDocumentOnSaveConfig', () => {
49+
it('should return the AnalyzeDocumentOnSave configuration', () => {
50+
(vscode.workspace.getConfiguration as jest.Mock).mockReturnValue({
51+
get: jest.fn().mockReturnValue(true),
52+
});
53+
const analyzeOnSave = AnalyzeDocumentOnSaveConfig();
54+
expect(analyzeOnSave).toBe(true);
5755
});
56+
});
5857

59-
describe('GetChatGPTToken', () => {
60-
it('should return the ChatGPT token configuration', () => {
61-
(vscode.workspace.getConfiguration as jest.Mock).mockReturnValue({
62-
get: jest.fn().mockReturnValue('chatgpt-token'),
63-
});
64-
const chatGPTToken = GetChatGPTToken();
65-
expect(chatGPTToken).toBe('chatgpt-token');
66-
});
58+
describe('GetChatGPTToken', () => {
59+
it('should return the ChatGPT token configuration', () => {
60+
(vscode.workspace.getConfiguration as jest.Mock).mockReturnValue({
61+
get: jest.fn().mockReturnValue('chatgpt-token'),
62+
});
63+
const chatGPTToken = GetChatGPTToken();
64+
expect(chatGPTToken).toBe('chatgpt-token');
6765
});
66+
});
6867

69-
describe('BackendService', () => {
70-
it('should return the backend service configuration', () => {
71-
(vscode.workspace.getConfiguration as jest.Mock).mockReturnValue({
72-
get: jest.fn().mockReturnValue('backend-service'),
73-
});
74-
const backendService = BackendService();
75-
expect(backendService).toBe('backend-service');
76-
});
68+
describe('BackendService', () => {
69+
it('should return the backend service configuration', () => {
70+
(vscode.workspace.getConfiguration as jest.Mock).mockReturnValue({
71+
get: jest.fn().mockReturnValue('backend-service'),
72+
});
73+
const backendService = BackendService();
74+
expect(backendService).toBe('backend-service');
7775
});
76+
});
7877

79-
describe('GetRequestParamId', () => {
80-
it('should return the machine ID if telemetry is enabled', () => {
81-
const requestId = GetRequestParamId();
82-
expect(requestId).toBe('123456789');
83-
});
78+
describe('GetRequestParamId', () => {
79+
it('should return the machine ID if telemetry is enabled', () => {
80+
const requestId = GetRequestParamId();
81+
expect(requestId).toBe('123456789');
8482
});
83+
});
8584
});

0 commit comments

Comments
 (0)