Skip to content

Commit e76ee22

Browse files
authored
Remove some anys, add a rule disallowing some anys, and use a const string for swe agent (#7533)
1 parent b9ea7df commit e76ee22

26 files changed

+195
-83
lines changed

.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ module.exports = {
2424
rules: {
2525
'rulesdir/public-methods-well-defined-types': 'error'
2626
}
27+
},
28+
{
29+
files: ['**/*.ts', '**/*.tsx'],
30+
rules: {
31+
'rulesdir/no-any-except-union-method-signature': 'error'
32+
}
2733
}
2834
]
2935
};

.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
".eslintrc.json": "jsonc",
55
".eslintrc.*.json": "jsonc"
66
},
7+
"json.schemas": [
8+
{
9+
"fileMatch": [
10+
"**/.eslintrc.*.json"
11+
],
12+
"url": "https://json.schemastore.org/eslintrc"
13+
}
14+
],
715
"files.trimTrailingWhitespace": true,
816
"gitlens.advanced.blame.customArguments": ["--ignore-revs-file", ".gitignore-revs"]
917
}

build/eslint-rules/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77

88
module.exports = {
99
'public-methods-well-defined-types': require('./public-methods-well-defined-types'),
10+
'no-any-except-union-method-signature': require('./no-any-except-union-method-signature'),
1011
};
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
module.exports = {
9+
meta: {
10+
type: 'suggestion',
11+
docs: {
12+
description: 'Disallow the use of any except in union types within method signatures',
13+
category: 'Best Practices',
14+
recommended: true,
15+
},
16+
fixable: null,
17+
schema: [],
18+
messages: {
19+
unexpectedAny: 'Unexpected any. Use a more specific type instead.',
20+
},
21+
},
22+
23+
create(context) {
24+
return {
25+
// Target the 'any' type annotation
26+
TSAnyKeyword(node) {
27+
// Get the parent nodes to determine context
28+
const parent = node.parent;
29+
30+
if (parent) {
31+
// Check if this type is part of a method signature
32+
let currentNode = parent;
33+
let isMethodSignature = false;
34+
35+
while (currentNode) {
36+
// Check if we're in a method signature or function type
37+
if (
38+
currentNode.type === 'TSMethodSignature' ||
39+
currentNode.type === 'TSFunctionType' ||
40+
currentNode.type === 'FunctionDeclaration' ||
41+
currentNode.type === 'FunctionExpression' ||
42+
currentNode.type === 'ArrowFunctionExpression' ||
43+
currentNode.type === 'MethodDefinition'
44+
) {
45+
isMethodSignature = true;
46+
break;
47+
}
48+
49+
currentNode = currentNode.parent;
50+
}
51+
52+
// If it's part of a method signature, it's allowed
53+
if (isMethodSignature) {
54+
return;
55+
}
56+
}
57+
58+
// Report any other use of 'any'
59+
context.report({
60+
node,
61+
messageId: 'unexpectedAny',
62+
});
63+
}
64+
};
65+
}
66+
};

common/sessionParsing.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
export interface SessionResponseLogChunk {
77
choices: Array<{
8-
finish_reason: string;
8+
finish_reason?: 'tool_calls' | 'null' | (string & {});
99
delta: {
1010
content?: string;
11-
role: string;
11+
role: 'assistant' | (string & {});
1212
tool_calls?: Array<{
1313
function: {
1414
arguments: string;
@@ -37,7 +37,7 @@ export interface SessionResponseLogChunk {
3737
export interface ParsedToolCall {
3838
type: 'str_replace_editor' | 'think' | 'bash' | 'report_progress' | 'unknown';
3939
name: string;
40-
args: any;
40+
// args: any;
4141
content: string;
4242
command?: string; // For str_replace_editor
4343
}
@@ -127,7 +127,7 @@ export function parseToolCallDetails(
127127
},
128128
content: string
129129
): ParsedToolCallDetails {
130-
let args: any = {};
130+
let args: { command?: string, path?: string, prDescription?: string, commitMessage?: string } = {};
131131
try {
132132
args = toolCall.function.arguments ? JSON.parse(toolCall.function.arguments) : {};
133133
} catch {

src/@types/vscode.proposed.chatParticipantAdditions.d.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ declare module 'vscode' {
149149
constructor(value: ChatResponseDiffEntry[], title: string);
150150
}
151151

152-
export type ExtendedChatResponsePart = ChatResponsePart | ChatResponseTextEditPart | ChatResponseNotebookEditPart | ChatResponseConfirmationPart | ChatResponseCodeCitationPart | ChatResponseReferencePart2 | ChatResponseMovePart | ChatResponseExtensionsPart | ChatResponsePullRequestPart | ChatPrepareToolInvocationPart | ChatToolInvocationPart | ChatResponseMultiDiffPart;
152+
export type ExtendedChatResponsePart = ChatResponsePart | ChatResponseTextEditPart | ChatResponseNotebookEditPart | ChatResponseConfirmationPart | ChatResponseCodeCitationPart | ChatResponseReferencePart2 | ChatResponseMovePart | ChatResponseExtensionsPart | ChatResponsePullRequestPart | ChatPrepareToolInvocationPart | ChatToolInvocationPart | ChatResponseMultiDiffPart | ChatResponseThinkingProgressPart;
153153
export class ChatResponseWarningPart {
154154
value: MarkdownString;
155155
constructor(value: string | MarkdownString);
@@ -161,6 +161,23 @@ declare module 'vscode' {
161161
constructor(value: string, task?: (progress: Progress<ChatResponseWarningPart | ChatResponseReferencePart>) => Thenable<string | void>);
162162
}
163163

164+
/**
165+
* A specialized progress part for displaying thinking/reasoning steps.
166+
*/
167+
export class ChatResponseThinkingProgressPart extends ChatResponseProgressPart {
168+
value: string;
169+
id?: string;
170+
metadata?: string;
171+
task?: (progress: Progress<LanguageModelThinkingPart>) => Thenable<string | void>;
172+
173+
/**
174+
* Creates a new thinking progress part.
175+
* @param value An initial progress message
176+
* @param task A task that will emit thinking parts during its execution
177+
*/
178+
constructor(value: string, id?: string, metadata?: string, task?: (progress: Progress<LanguageModelThinkingPart>) => Thenable<string | void>);
179+
}
180+
164181
export class ChatResponseReferencePart2 {
165182
/**
166183
* The reference target.
@@ -256,6 +273,8 @@ declare module 'vscode' {
256273
*/
257274
progress(value: string, task?: (progress: Progress<ChatResponseWarningPart | ChatResponseReferencePart>) => Thenable<string | void>): void;
258275

276+
thinkingProgress(value: string, id?: string, metadata?: string): void;
277+
259278
textEdit(target: Uri, edits: TextEdit | TextEdit[]): void;
260279

261280
textEdit(target: Uri, isDone: true): void;

src/common/copilot.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
import { EventType, TimelineEvent } from './timelineEvent';
77

8+
export const COPILOT_SWE_AGENT = 'copilot-swe-agent';
9+
810
export const COPILOT_LOGINS = [
911
'copilot-pull-request-reviewer',
10-
'copilot-swe-agent',
12+
COPILOT_SWE_AGENT,
1113
'Copilot'
1214
];
1315

src/common/resources.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,18 @@ import * as path from 'path';
77
import * as vscode from 'vscode';
88

99
export class Resource {
10-
static icons: any;
10+
static icons: {
11+
reactions: {
12+
THUMBS_UP: string;
13+
THUMBS_DOWN: string;
14+
CONFUSED: string;
15+
EYES: string;
16+
HEART: string;
17+
HOORAY: string;
18+
LAUGH: string;
19+
ROCKET: string;
20+
};
21+
};
1122

1223
static initialize(context: vscode.ExtensionContext) {
1324
Resource.icons = {

src/common/utils.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ export class UnreachableCaseError extends Error {
135135
}
136136

137137
interface HookError extends Error {
138-
errors: any;
138+
errors: (string | { message: string })[];
139139
}
140140

141141
function isHookError(e: Error): e is HookError {
142-
return !!(e as any).errors;
142+
return !!(e as Partial<HookError>).errors;
143143
}
144144

145145
function hasFieldErrors(e: any): e is Error & { errors: { value: string; field: string; status: string }[] } {
@@ -184,7 +184,7 @@ export function formatError(e: HookError | any): string {
184184
return e.message;
185185
} else if (isHookError(e) && e.errors) {
186186
return e.errors
187-
.map((error: any) => {
187+
.map((error) => {
188188
if (typeof error === 'string') {
189189
return error;
190190
} else {
@@ -200,10 +200,6 @@ export function formatError(e: HookError | any): string {
200200
return errorMessage;
201201
}
202202

203-
export interface PromiseAdapter<T, U> {
204-
(value: T, resolve: (value?: U | PromiseLike<U>) => void, reject: (reason: any) => void): any;
205-
}
206-
207203
// Copied from https://github.com/microsoft/vscode/blob/cfd9d25826b5b5bc3b06677521660b4f1ba6639a/extensions/vscode-api-tests/src/utils.ts#L135-L136
208204
export async function asPromise<T>(event: Event<T>): Promise<T> {
209205
return new Promise<T>((resolve) => {

src/common/webview.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export interface IRequestMessage<T> {
1717

1818
export interface IReplyMessage {
1919
seq?: string;
20-
err?: any;
20+
err?: string;
21+
// eslint-disable-next-line rulesdir/no-any-except-union-method-signature
2122
res?: any;
2223
}
2324

@@ -85,7 +86,7 @@ export class WebviewBase extends Disposable {
8586
this._webview?.postMessage(reply);
8687
}
8788

88-
protected async _throwError(originalMessage: IRequestMessage<any> | undefined, error: any) {
89+
protected async _throwError(originalMessage: IRequestMessage<any> | undefined, error: string) {
8990
const reply: IReplyMessage = {
9091
seq: originalMessage?.req,
9192
err: error,

0 commit comments

Comments
 (0)