Skip to content

Commit 78f1ff9

Browse files
authored
Adopt no-cast-to-any rule (#7956)
1 parent 35a3849 commit 78f1ff9

26 files changed

+142
-76
lines changed

build/eslint-rules/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ exports.rules = {
99
'public-methods-well-defined-types': require('./public-methods-well-defined-types'),
1010
'no-any-except-union-method-signature': require('./no-any-except-union-method-signature'),
1111
'no-pr-in-user-strings': require('./no-pr-in-user-strings'),
12+
'no-cast-to-any': require('./no-cast-to-any')
1213
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
module.exports = {
7+
8+
create(context) {
9+
return {
10+
'TSTypeAssertion[typeAnnotation.type="TSAnyKeyword"], TSAsExpression[typeAnnotation.type="TSAnyKeyword"]': (node) => {
11+
context.report({
12+
node,
13+
message: `Avoid casting to 'any' type. Consider using a more specific type or type guards for better type safety.`
14+
});
15+
}
16+
};
17+
}
18+
};

eslint.config.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export default defineConfig([
9595
'no-sequences': 'error',
9696
'no-template-curly-in-string': 'warn',
9797
'no-throw-literal': 'error',
98+
'no-undef': 'off',
9899
'no-unneeded-ternary': 'error',
99100
'no-use-before-define': 'off',
100101
'no-useless-call': 'error',
@@ -218,7 +219,8 @@ export default defineConfig([
218219

219220
// Custom rules
220221
'rulesdir/no-any-except-union-method-signature': 'error',
221-
'rulesdir/no-pr-in-user-strings': 'error'
222+
'rulesdir/no-pr-in-user-strings': 'error',
223+
'rulesdir/no-cast-to-any': 'error',
222224
}
223225
},
224226

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ declare module 'vscode' {
103103
isConfirmed?: boolean;
104104
isComplete?: boolean;
105105
toolSpecificData?: ChatTerminalToolInvocationData;
106+
fromSubAgent?: boolean;
106107

107108
constructor(toolName: string, toolCallId: string, isError?: boolean);
108109
}
@@ -646,7 +647,13 @@ declare module 'vscode' {
646647
}
647648

648649
export interface ChatRequest {
649-
modeInstructions?: string;
650-
modeInstructionsToolReferences?: readonly ChatLanguageModelToolReference[];
650+
readonly modeInstructions?: string;
651+
readonly modeInstructions2?: ChatRequestModeInstructions;
652+
}
653+
654+
export interface ChatRequestModeInstructions {
655+
readonly content: string;
656+
readonly toolReferences?: readonly ChatLanguageModelToolReference[];
657+
readonly metadata?: Record<string, boolean | string | number>;
651658
}
652659
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ declare module 'vscode' {
187187

188188
isQuotaExceeded?: boolean;
189189

190+
isRateLimited?: boolean;
191+
190192
level?: ChatErrorLevel;
191193

192194
code?: string;
@@ -219,6 +221,10 @@ declare module 'vscode' {
219221
chatSessionId?: string;
220222
chatInteractionId?: string;
221223
terminalCommand?: string;
224+
/**
225+
* Lets us add some nicer UI to toolcalls that came from a sub-agent, but in the long run, this should probably just be rendered in a similar way to thinking text + tool call groups
226+
*/
227+
fromSubAgent?: boolean;
222228
}
223229

224230
export interface LanguageModelToolInvocationPrepareOptions<T> {
@@ -233,12 +239,13 @@ declare module 'vscode' {
233239

234240
export interface PreparedToolInvocation {
235241
pastTenseMessage?: string | MarkdownString;
236-
presentation?: 'hidden' | undefined;
242+
presentation?: 'hidden' | 'hiddenAfterComplete' | undefined;
237243
}
238244

239245
export class ExtendedLanguageModelToolResult extends LanguageModelToolResult {
240246
toolResultMessage?: string | MarkdownString;
241247
toolResultDetails?: Array<Uri | Location>;
248+
toolMetadata?: unknown;
242249
}
243250

244251
// #region Chat participant detection

src/common/diffHunk.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,16 @@ export enum DiffChangeType {
1818
}
1919

2020
export class DiffLine {
21-
public get raw(): string {
22-
return this._raw;
23-
}
24-
2521
public get text(): string {
26-
return this._raw.substr(1);
22+
return this.raw.substr(1);
2723
}
2824

2925
constructor(
3026
public type: DiffChangeType,
3127
public oldLineNumber: number /* 1 based */,
3228
public newLineNumber: number /* 1 based */,
3329
public positionInHunk: number,
34-
private _raw: string,
30+
public readonly raw: string,
3531
public endwithLineBreak: boolean = true,
3632
) { }
3733
}

src/common/emoji.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function ensureEmojis(context: ExtensionContext) {
2323
}
2424

2525
async function loadEmojiMap(context: ExtensionContext) {
26-
const uri = (Uri as any).joinPath(context.extensionUri, 'resources', 'emojis.json');
26+
const uri = Uri.joinPath(context.extensionUri, 'resources', 'emojis.json');
2727
emojiMap = JSON.parse(new TextDecoder('utf8').decode(await workspace.fs.readFile(uri)));
2828
}
2929

src/common/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ export interface Predicate<T> {
366366
(input: T): boolean;
367367
}
368368

369+
export interface AsyncPredicate<T> {
370+
(input: T): Promise<boolean>;
371+
}
372+
369373
export const enum CharCode {
370374
Period = 46,
371375
/**

src/gitProviders/builtinGit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export class BuiltinGitProvider extends Disposable implements IGit {
4141
throw e;
4242
}
4343

44-
this._register(this._gitAPI.onDidCloseRepository(e => this._onDidCloseRepository.fire(e as any)));
45-
this._register(this._gitAPI.onDidOpenRepository(e => this._onDidOpenRepository.fire(e as any)));
44+
this._register(this._gitAPI.onDidCloseRepository(e => this._onDidCloseRepository.fire(e)));
45+
this._register(this._gitAPI.onDidOpenRepository(e => this._onDidOpenRepository.fire(e)));
4646
this._register(this._gitAPI.onDidChangeState(e => this._onDidChangeState.fire(e)));
4747
this._register(this._gitAPI.onDidPublish(e => this._onDidPublish.fire(e)));
4848
}

src/gitProviders/vslsguest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export class VSLSGuest extends Disposable implements IGit {
115115
}
116116

117117
public getRepository(folder: vscode.WorkspaceFolder): Repository {
118-
return this._openRepositories.filter(repository => (repository as any).workspaceFolder === folder)[0];
118+
return this._openRepositories.filter(repository => (repository as (Repository & { workspaceFolder: vscode.WorkspaceFolder })).workspaceFolder === folder)[0];
119119
}
120120
}
121121

0 commit comments

Comments
 (0)