Skip to content

Commit efc841a

Browse files
biilmannclaude
andcommitted
fix: resolve lint errors in logs commands and tests
Add proper type assertions to eliminate unsafe-any and non-null assertion lint errors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d6ead88 commit efc841a

4 files changed

Lines changed: 26 additions & 26 deletions

File tree

src/commands/logs/edge-functions.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { CLI_LOG_LEVEL_CHOICES_STRING, LOG_LEVELS_LIST } from './log-levels.js'
1010
import { getName } from './build.js'
1111

1212
export const logsEdgeFunction = async (options: OptionValues, command: BaseCommand) => {
13-
let deployId: string | undefined = options.deployId
13+
let deployId = options.deployId as string | undefined
1414
await command.authenticate()
1515

1616
const client = command.netlify.api
@@ -22,23 +22,24 @@ export const logsEdgeFunction = async (options: OptionValues, command: BaseComma
2222
return
2323
}
2424

25-
if (options.level && !options.level.every((level: string) => LOG_LEVELS_LIST.includes(level))) {
26-
log(`Invalid log level. Choices are:${CLI_LOG_LEVEL_CHOICES_STRING}`)
25+
const levels = options.level as string[] | undefined
26+
if (levels && !levels.every((level) => LOG_LEVELS_LIST.includes(level))) {
27+
log(`Invalid log level. Choices are:${CLI_LOG_LEVEL_CHOICES_STRING.toString()}`)
2728
}
2829

29-
const levelsToPrint = options.level || LOG_LEVELS_LIST
30+
const levelsToPrint: string[] = levels || LOG_LEVELS_LIST
3031

3132
if (options.from) {
32-
const fromMs = parseDateToMs(options.from)
33-
const toMs = options.to ? parseDateToMs(options.to) : Date.now()
33+
const fromMs = parseDateToMs(options.from as string)
34+
const toMs = options.to ? parseDateToMs(options.to as string) : Date.now()
3435

3536
const url = `https://analytics.services.netlify.com/v2/sites/${siteId}/edge_function_logs?from=${fromMs.toString()}&to=${toMs.toString()}`
3637
const data = await fetchHistoricalLogs({ url, accessToken: client.accessToken ?? '' })
3738
printHistoricalLogs(data, levelsToPrint)
3839
return
3940
}
4041

41-
const userId = command.netlify.globalConfig.get('userId')
42+
const userId = command.netlify.globalConfig.get('userId') as string
4243

4344
if (!deployId) {
4445
const deploys = await client.listSiteDeploys({ siteId })
@@ -51,15 +52,15 @@ export const logsEdgeFunction = async (options: OptionValues, command: BaseComma
5152
if (deploys.length === 1) {
5253
deployId = deploys[0].id
5354
} else {
54-
const { result } = await inquirer.prompt({
55+
const { result } = (await inquirer.prompt({
5556
name: 'result',
5657
type: 'list',
5758
message: `Select a deploy\n\n${chalk.yellow('*')} indicates a deploy created by you`,
58-
choices: deploys.map((deploy: any) => ({
59+
choices: deploys.map((deploy) => ({
5960
name: getName({ deploy, userId }),
6061
value: deploy.id,
6162
})),
62-
})
63+
})) as { result: string }
6364

6465
deployId = result
6566
}
@@ -79,7 +80,7 @@ export const logsEdgeFunction = async (options: OptionValues, command: BaseComma
7980
})
8081

8182
ws.on('message', (data: string) => {
82-
const logData = JSON.parse(data)
83+
const logData = JSON.parse(data) as { level: string; message: string; timestamp?: string }
8384
if (!levelsToPrint.includes(logData.level.toLowerCase())) {
8485
return
8586
}
@@ -90,7 +91,7 @@ export const logsEdgeFunction = async (options: OptionValues, command: BaseComma
9091
log('Connection closed')
9192
})
9293

93-
ws.on('error', (err: any) => {
94+
ws.on('error', (err: Error) => {
9495
log('Connection error')
9596
log(err)
9697
})

src/commands/logs/log-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export function formatLogEntry(entry: { timestamp?: string; level?: string; mess
5454
}
5555

5656
export function printHistoricalLogs(data: unknown, levelsToPrint: string[]): void {
57-
const entries = Array.isArray(data) ? data : []
57+
const entries = Array.isArray(data) ? (data as { timestamp?: string; level?: string; message?: string }[]) : []
5858

5959
if (entries.length === 0) {
6060
log('No logs found for the specified time range')

tests/integration/commands/logs/edge-functions.test.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,12 @@ describe('logs:edge-functions command', () => {
124124
const setupCall = spyOn.mock.calls.find((args) => args[0] === 'open')
125125
expect(setupCall).toBeDefined()
126126

127-
const openCallback = setupCall?.[1]
127+
const openCallback = setupCall?.[1] as (() => void) | undefined
128128
openCallback?.()
129129

130130
expect(spySend).toHaveBeenCalledOnce()
131-
const call = spySend.mock.calls[0]
132-
const [message] = call
133-
const body = JSON.parse(message)
131+
const call = spySend.mock.calls[0] as string[]
132+
const body = JSON.parse(call[0]) as Record<string, unknown>
134133

135134
expect(body.deploy_id).toEqual('deploy-id-1')
136135
expect(body.site_id).toEqual('site_id')
@@ -154,11 +153,11 @@ describe('logs:edge-functions command', () => {
154153
await program.parseAsync(['', '', 'logs:edge-functions', '--deploy-id', 'my-deploy-id'])
155154

156155
const setupCall = spyOn.mock.calls.find((args) => args[0] === 'open')
157-
const openCallback = setupCall?.[1]
156+
const openCallback = setupCall?.[1] as (() => void) | undefined
158157
openCallback?.()
159158

160-
const call = spySend.mock.calls[0]
161-
const body = JSON.parse(call[0])
159+
const call = spySend.mock.calls[0] as string[]
160+
const body = JSON.parse(call[0]) as Record<string, unknown>
162161

163162
expect(body.deploy_id).toEqual('my-deploy-id')
164163
})
@@ -179,7 +178,7 @@ describe('logs:edge-functions command', () => {
179178

180179
await program.parseAsync(['', '', 'logs:edge-functions', '--level', 'info'])
181180
const messageCallback = spyOn.mock.calls.find((args) => args[0] === 'message')
182-
const messageCallbackFunc = messageCallback?.[1]
181+
const messageCallbackFunc = messageCallback?.[1] as ((data: string) => void) | undefined
183182

184183
messageCallbackFunc?.(JSON.stringify({ level: LOG_LEVELS.INFO, message: 'Hello World' }))
185184
messageCallbackFunc?.(JSON.stringify({ level: LOG_LEVELS.WARN, message: 'There was a warning' }))
@@ -216,8 +215,8 @@ describe('logs:edge-functions command', () => {
216215
args[0].includes('analytics.services.netlify.com'),
217216
)
218217
expect(analyticsCall).toBeDefined()
219-
expect(analyticsCall![0]).toContain('edge_function_logs')
220-
expect(analyticsCall![0]).toContain('site_id')
218+
expect((analyticsCall as string[])[0]).toContain('edge_function_logs')
219+
expect((analyticsCall as string[])[0]).toContain('site_id')
221220
} finally {
222221
global.fetch = originalFetch
223222
}

tests/integration/commands/logs/functions.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ describe('logs:function command', () => {
296296
return parsedUrl.hostname === 'analytics.services.netlify.com'
297297
})
298298
expect(analyticsCall).toBeDefined()
299-
expect(analyticsCall![0]).toContain('function_logs')
300-
expect(analyticsCall![0]).toContain('cool-function')
301-
expect(analyticsCall![0]).toContain('site_id')
299+
expect((analyticsCall as string[])[0]).toContain('function_logs')
300+
expect((analyticsCall as string[])[0]).toContain('cool-function')
301+
expect((analyticsCall as string[])[0]).toContain('site_id')
302302
} finally {
303303
global.fetch = originalFetch
304304
}

0 commit comments

Comments
 (0)