Skip to content

Commit 887ce89

Browse files
committed
chore: fix linting errors
1 parent e88a979 commit 887ce89

33 files changed

+184
-153
lines changed

chat-client-ui-types/src/uiContracts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,5 @@ export type UiMessageResultParams =
150150
}
151151
export interface ErrorResult {
152152
message: string
153-
type: 'InvalidRequest' | 'InternalError' | 'UnknownError' | string
153+
type: 'InvalidRequest' | 'InternalError' | 'UnknownError'
154154
}

runtimes/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"@types/mock-fs": "^4.13.4",
6161
"@types/node": "^22.13.1",
6262
"@types/node-forge": "^1.3.11",
63+
"@types/win-ca": "^3.5.4",
6364
"assert": "^2.0.0",
6465
"copyfiles": "^2.4.1",
6566
"husky": "^9.1.7",

runtimes/protocol/notification.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ export interface NotificationContent {
1313
readonly title?: string
1414
}
1515

16-
export namespace FollowupNotificationActionType {
17-
export const Acknowledge = 'Acknowledge'
18-
}
16+
export const FollowupNotificationActionType = {
17+
Acknowledge: 'Acknowledge',
18+
} as const
1919

2020
export type FollowupNotificationActionType = typeof FollowupNotificationActionType.Acknowledge
2121

22-
export namespace NotificationActionType {
23-
export const Url = 'Url'
24-
export const Marketplace = 'Marketplace'
25-
}
22+
const NotificationActionType = {
23+
Url: 'Url',
24+
Marketplace: 'Marketplace',
25+
} as const
2626

2727
export type NotificationActionType =
2828
| typeof NotificationActionType.Url

runtimes/runtimes/auth/auth.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ describe('Auth', () => {
396396
describe('Encrypted credentials', () => {
397397
it('Rejects when encrypted flag is set wrong', async () => {
398398
const updateIamRequest: UpdateCredentialsParams = {
399-
data: iamCredentials as IamCredentials,
399+
data: iamCredentials,
400400
encrypted: true,
401401
}
402402
const auth = new Auth(serverLspConnectionMock, lspRouter)
@@ -472,8 +472,8 @@ describe('Auth', () => {
472472

473473
const jwt = await new jose.EncryptJWT(payload)
474474
.setProtectedHeader({ alg: 'dir', enc: 'A256GCM' })
475-
.setNotBefore(new Date().getTime() / 1000 + 50) //allows up to 60s clockTolerance
476-
.setExpirationTime(new Date().getTime() / 1000 - 70) //not allowed
475+
.setNotBefore(Date.now() / 1000 + 50) // allows up to 60s clockTolerance
476+
.setExpirationTime(Date.now() / 1000 - 70) // not allowed
477477
.encrypt(encryptionKey)
478478

479479
const updateBearerRequest: UpdateCredentialsParams = {

runtimes/runtimes/auth/auth.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/restrict-template-expressions */
12
import { jwtDecrypt } from 'jose'
23
import { Connection } from 'vscode-languageserver'
34
import { CredentialsEncoding } from './standalone/encryption'
@@ -97,7 +98,7 @@ export class Auth {
9798
return creds && (isIamCredentials(creds) || isBearerCredentials(creds))
9899
}
99100

100-
private async registerLspCredentialsUpdateHandlers() {
101+
private registerLspCredentialsUpdateHandlers() {
101102
this.registerIamCredentialsUpdateHandlers()
102103
this.registerBearerCredentialsUpdateHandlers()
103104
}
@@ -166,11 +167,11 @@ export class Auth {
166167
private setCredentials(creds: Credentials) {
167168
if (this.areValidCredentials(creds)) {
168169
if (isIamCredentials(creds)) {
169-
this.iamCredentials = creds as IamCredentials
170+
this.iamCredentials = creds
170171
// Prevent modifying credentials by implementors
171172
Object.freeze(this.iamCredentials)
172173
} else {
173-
this.bearerCredentials = creds as BearerCredentials
174+
this.bearerCredentials = creds
174175
Object.freeze(this.bearerCredentials)
175176
}
176177
}

runtimes/runtimes/auth/standalone/encryption.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Readable } from 'stream'
22
import { CompactEncrypt } from 'jose'
33

44
export function shouldWaitForEncryptionKey(): boolean {
5-
return process.argv.some(arg => arg === '--set-credentials-encryption-key')
5+
return process.argv.includes('--set-credentials-encryption-key')
66
}
77

88
export type CredentialsEncoding = 'JWT'
@@ -38,7 +38,7 @@ export function validateEncryptionDetails(encryptionDetails: EncryptionInitializ
3838
}
3939

4040
if (encryptionDetails.mode !== 'JWT') {
41-
throw new Error(`Unsupported encoding mode: ${encryptionDetails.mode}`)
41+
throw new Error(`Unsupported encoding mode: ${String(encryptionDetails.mode)}`)
4242
}
4343
}
4444

@@ -65,9 +65,9 @@ export function readEncryptionDetails(stream: Readable): Promise<EncryptionIniti
6565

6666
// Fires when the stream has contents that can be read
6767
const onStreamIsReadable = () => {
68-
let byteRead
68+
let byteRead: Buffer | null
6969
while ((byteRead = stream.read(1)) !== null) {
70-
if (byteRead.toString('utf-8') == '\n') {
70+
if (byteRead.toString('utf-8') === '\n') {
7171
clearTimer()
7272
// Stop reading this stream, we have read a line from it
7373
stream.removeListener('readable', onStreamIsReadable)
@@ -90,7 +90,12 @@ export function readEncryptionDetails(stream: Readable): Promise<EncryptionIniti
9090
/**
9191
* Encrypt an object with the provided key
9292
*/
93-
export function encryptObjectWithKey(request: Object, key: string, alg?: string, enc?: string): Promise<string> {
93+
export function encryptObjectWithKey(
94+
request: NonNullable<unknown>,
95+
key: string,
96+
alg?: string,
97+
enc?: string
98+
): Promise<string> {
9499
const payload = new TextEncoder().encode(JSON.stringify(request))
95100
const keyBuffer = Buffer.from(key, 'base64')
96101
return new CompactEncrypt(payload)
@@ -126,8 +131,8 @@ export function isMessageJWEEncrypted(message: string, algorithm: string, encodi
126131
if (
127132
protectedHeader.alg &&
128133
protectedHeader.enc &&
129-
protectedHeader.alg == algorithm &&
130-
protectedHeader.enc == encoding
134+
protectedHeader.alg === algorithm &&
135+
protectedHeader.enc === encoding
131136
) {
132137
return true
133138
}

runtimes/runtimes/base-runtime.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ import {
4343
createPromptNotificationType,
4444
listConversationsRequestType,
4545
conversationClickRequestType,
46-
GetSerializedChatParams,
47-
GetSerializedChatResult,
48-
RequestHandler,
49-
TabBarActionParams,
50-
TabBarActionResult,
5146
getSerializedChatRequestType,
5247
tabBarActionRequestType,
5348
} from '../protocol'
@@ -118,10 +113,11 @@ export const baseRuntime = (connections: { reader: MessageReader; writer: Messag
118113
// Set up the workspace to use the LSP Text Documents component
119114
const defaultHomeDir = '/home/user'
120115
const workspace: Workspace = {
121-
getTextDocument: async uri => documents.get(uri),
122-
getAllTextDocuments: async () => documents.all(),
123-
getWorkspaceFolder: _uri =>
124-
lspRouter.clientInitializeParams!.workspaceFolders && lspRouter.clientInitializeParams!.workspaceFolders[0],
116+
getTextDocument: uri => Promise.resolve(documents.get(uri)),
117+
getAllTextDocuments: () => Promise.resolve(documents.all()),
118+
getWorkspaceFolder: _ =>
119+
lspRouter.clientInitializeParams?.workspaceFolders &&
120+
lspRouter.clientInitializeParams.workspaceFolders?.[0],
125121
fs: {
126122
copyFile: (_src, _dest, _options?) => Promise.resolve(),
127123
exists: _path => Promise.resolve(false),
@@ -161,9 +157,10 @@ export const baseRuntime = (connections: { reader: MessageReader; writer: Messag
161157
onSourceLinkClick: handler => lspConnection.onNotification(sourceLinkClickNotificationType.method, handler),
162158
onFollowUpClicked: handler => lspConnection.onNotification(followUpClickNotificationType.method, handler),
163159
openTab: params => lspConnection.sendRequest(openTabRequestType.method, params),
164-
sendChatUpdate: params => lspConnection.sendNotification(chatUpdateNotificationType.method, params),
160+
sendChatUpdate: params => () => lspConnection.sendNotification(chatUpdateNotificationType.method, params),
165161
onFileClicked: handler => lspConnection.onNotification(fileClickNotificationType.method, handler),
166-
sendContextCommands: params => lspConnection.sendNotification(contextCommandsNotificationType.method, params),
162+
sendContextCommands: params => () =>
163+
lspConnection.sendNotification(contextCommandsNotificationType.method, params),
167164
onCreatePrompt: handler => lspConnection.onNotification(createPromptNotificationType.method, handler),
168165
onListConversations: handler => lspConnection.onRequest(listConversationsRequestType.method, handler),
169166
onConversationClick: handler => lspConnection.onRequest(conversationClickRequestType.method, handler),
@@ -176,7 +173,7 @@ export const baseRuntime = (connections: { reader: MessageReader; writer: Messag
176173
onUpdateProfile: handler => lspConnection.onRequest(updateProfileRequestType, handler),
177174
onGetSsoToken: handler => lspConnection.onRequest(getSsoTokenRequestType, handler),
178175
onInvalidateSsoToken: handler => lspConnection.onRequest(invalidateSsoTokenRequestType, handler),
179-
sendSsoTokenChanged: params => lspConnection.sendNotification(ssoTokenChangedRequestType, params),
176+
sendSsoTokenChanged: params => () => lspConnection.sendNotification(ssoTokenChangedRequestType, params),
180177
}
181178

182179
// Set up auth without encryption
@@ -188,7 +185,7 @@ export const baseRuntime = (connections: { reader: MessageReader; writer: Messag
188185
version: props.version,
189186
},
190187
platform: 'browser',
191-
getConfiguration(key: string) {
188+
getConfiguration(_key: string) {
192189
return undefined
193190
},
194191
}
@@ -229,8 +226,10 @@ export const baseRuntime = (connections: { reader: MessageReader; writer: Messag
229226
onDidDeleteFiles: params => lspConnection.workspace.onDidDeleteFiles(params),
230227
onDidRenameFiles: params => lspConnection.workspace.onDidRenameFiles(params),
231228
onUpdateConfiguration: lspServer.setUpdateConfigurationHandler,
232-
selectWorkspaceItem: params => lspConnection.sendRequest(selectWorkspaceItemRequestType.method, params),
233-
openFileDiff: params => lspConnection.sendNotification(openFileDiffNotificationType.method, params),
229+
selectWorkspaceItem: params => () =>
230+
lspConnection.sendRequest(selectWorkspaceItemRequestType.method, params),
231+
openFileDiff: params => () =>
232+
lspConnection.sendNotification(openFileDiffNotificationType.method, params),
234233
},
235234
window: {
236235
showMessage: params => lspConnection.sendNotification(ShowMessageNotification.method, params),
@@ -289,7 +288,9 @@ export const baseRuntime = (connections: { reader: MessageReader; writer: Messag
289288

290289
// Free up any resources or threads used by Servers
291290
lspConnection.onExit(() => {
292-
disposables.forEach(d => d())
291+
for (const d of disposables) {
292+
d()
293+
}
293294
})
294295

295296
// Initialize the documents listener and start the LSP connection

runtimes/runtimes/chat/baseChat.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,21 @@ export class BaseChat implements Chat {
124124
}
125125

126126
public sendChatUpdate(params: ChatUpdateParams) {
127-
this.connection.sendNotification(chatUpdateNotificationType.method, params)
127+
this.connection
128+
.sendNotification(chatUpdateNotificationType.method, params)
129+
.then(() => {})
130+
.catch(() => {})
128131
}
129132

130133
public onFileClicked(handler: NotificationHandler<FileClickParams>) {
131134
this.connection.onNotification(fileClickNotificationType.method, handler)
132135
}
133136

134137
public sendContextCommands(params: ContextCommandParams) {
135-
this.connection.sendNotification(contextCommandsNotificationType.method, params)
138+
this.connection
139+
.sendNotification(contextCommandsNotificationType.method, params)
140+
.then(() => {})
141+
.catch(() => {})
136142
}
137143

138144
public onCreatePrompt(handler: NotificationHandler<CreatePromptParams>) {

runtimes/runtimes/encoding.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ export interface Encoding {
33
encode(value: string): string
44
}
55

6-
const HEX_PAD: string = '00'
7-
const HEX_REGEX: RegExp = /%([0-9A-F]{2})/g
6+
const HEX_PAD = '00'
7+
const HEX_REGEX = /%([0-9A-F]{2})/g
88
export class WebBase64Encoding implements Encoding {
99
constructor(private window: WindowOrWorkerGlobalScope) {}
1010

@@ -22,7 +22,7 @@ export class WebBase64Encoding implements Encoding {
2222

2323
encode(value: string): string {
2424
// to support Unicode chars
25-
const converted = encodeURIComponent(value).replace(HEX_REGEX, (_, arg) => {
25+
const converted = encodeURIComponent(value).replace(HEX_REGEX, (_, arg: string) => {
2626
return String.fromCharCode(parseInt(arg, 16))
2727
})
2828
return this.window.btoa(converted)

runtimes/runtimes/lsp/router/loggingServer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ export class LoggingServer {
1212
private lspConnection: Connection,
1313
private encoding: Encoding
1414
) {
15-
this.logger = new DefaultLogger(DEFAULT_LOG_LEVEL as LogLevel, this.lspConnection)
15+
this.logger = new DefaultLogger(DEFAULT_LOG_LEVEL, this.lspConnection)
1616
this.lspServer = new LspServer(this.lspConnection, this.encoding, this.logger)
17-
this.lspServer.setInitializeHandler(async (params: InitializeParams): Promise<InitializeResult> => {
17+
this.lspServer.setInitializeHandler((params: InitializeParams): Promise<InitializeResult> => {
1818
this.updateLoggingLevel(params.initializationOptions?.logLevel ?? ('log' as LogLevel))
1919
return {
2020
capabilities: {},
2121
}
2222
})
23-
this.lspServer.setDidChangeConfigurationHandler(async params => {
23+
this.lspServer.setDidChangeConfigurationHandler(async _params => {
2424
const logLevelConfig = await lspConnection.workspace.getConfiguration({
2525
section: 'aws.logLevel',
2626
})

runtimes/runtimes/lsp/router/lspRouter.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ describe('LspRouter', () => {
267267
() => ({ serverInfo: { name: 'C' } }),
268268
]
269269

270-
handlers.forEach(h => {
270+
for (const h of handlers) {
271271
lspRouter.servers.push(newServer({ initializeHandler: h }))
272-
})
272+
}
273273

274274
const result = await initializeHandler({} as InitializeParams, {} as CancellationToken)
275275

runtimes/runtimes/lsp/router/lspRouter.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ export class LspRouter {
7272
}
7373

7474
let responsesList = await Promise.all(this.servers.map(s => s.initialize(params, token)))
75-
responsesList = responsesList.filter(r => r != undefined)
75+
responsesList = responsesList.filter(r => r !== undefined)
7676
const responseError = responsesList.find(el => el instanceof ResponseError)
7777
if (responseError) {
78-
return responseError as ResponseError<InitializeError>
78+
return responseError
7979
}
8080
const dupServerNames = findDuplicates(responsesList.map(r => (r as PartialInitializeResult).serverInfo?.name))
8181
if (dupServerNames) {
@@ -113,10 +113,7 @@ ${JSON.stringify({ ...result.capabilities, ...result.awsServerCapabilities })}`
113113
return result
114114
}
115115

116-
executeCommand = async (
117-
params: ExecuteCommandParams,
118-
token: CancellationToken
119-
): Promise<any | undefined | null> => {
116+
executeCommand = async (params: ExecuteCommandParams, token: CancellationToken): Promise<any> => {
120117
return this.routeRequestToFirstCapableServer(
121118
(server, params, token) => server.tryExecuteCommand(params, token),
122119
params,
@@ -142,11 +139,11 @@ ${JSON.stringify({ ...result.capabilities, ...result.awsServerCapabilities })}`
142139
const errors = results.filter(result => result instanceof ResponseError)
143140

144141
if (errors.length > 0) {
145-
errors.forEach(error => {
142+
for (const error of errors) {
146143
this.lspConnection.console.log(
147144
`Error updating configration section ${params.section}: ${error.message}`
148145
)
149-
})
146+
}
150147

151148
return new ResponseError(ErrorCodes.InternalError, 'Error during updating configuration', errors)
152149
}
@@ -170,7 +167,10 @@ ${JSON.stringify({ ...result.capabilities, ...result.awsServerCapabilities })}`
170167
const workspaceCapabilities = this.clientInitializeParams?.capabilities.workspace
171168
if (workspaceCapabilities?.didChangeConfiguration?.dynamicRegistration) {
172169
// Ask the client to notify the server on configuration changes
173-
this.lspConnection.client.register(DidChangeConfigurationNotification.type, undefined)
170+
this.lspConnection.client
171+
.register(DidChangeConfigurationNotification.type, undefined)
172+
.then(() => {})
173+
.catch(() => {})
174174
}
175175

176176
this.routeNotificationToAllServers((server, params) => server.sendInitializedNotification(params), params)
@@ -193,7 +193,7 @@ ${JSON.stringify({ ...result.capabilities, ...result.awsServerCapabilities })}`
193193
}
194194
}
195195

196-
private async routeNotificationToAllServers<P>(action: (server: LspServer, params: P) => void, params: P) {
196+
private routeNotificationToAllServers<P>(action: (server: LspServer, params: P) => void, params: P) {
197197
for (const server of this.servers) {
198198
action(server, params)
199199
}

0 commit comments

Comments
 (0)