Skip to content

Commit

Permalink
clean up all warnings (#1221)
Browse files Browse the repository at this point in the history
  • Loading branch information
syamsudotdev authored Dec 28, 2023
1 parent 8688b32 commit 565a200
Show file tree
Hide file tree
Showing 36 changed files with 191 additions and 129 deletions.
25 changes: 0 additions & 25 deletions custom_types/pg/index.d.ts

This file was deleted.

81 changes: 81 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"@oclif/plugin-help": "5.2.20",
"@oclif/plugin-version": "1.3.10",
"@sendgrid/mail": "^7.4.2",
"@types/pg": "^8.10.9",
"ajv": "^8.11.0",
"axios": "^0.27.2",
"boxen": "^5.0.0",
Expand Down
6 changes: 5 additions & 1 deletion src/components/logger/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ export function setDatabase(

async function migrate() {
await database().migrate({
// TODO: Current vercel/pkg is dependent with CommonJS

Check warning on line 138 in src/components/logger/history.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected 'todo' comment: 'TODO: Current vercel/pkg is dependent...'
// eslint-disable-next-line unicorn/prefer-module
migrationsPath: path.join(__dirname, '../../../db/migrations'),
})
}
Expand Down Expand Up @@ -468,7 +470,9 @@ export async function saveProbeRequestLog({
JSON.stringify(probeRes.headers),
responseBody,
probeRes?.responseTime ?? 0,
probeRes.headers['content-length'],
typeof probeRes.headers === 'string'
? probeRes.headers
: probeRes.headers['content-length'],
errorResp,
probe.socket ? 'tcp' : 'http',
probe.socket?.host || '',
Expand Down
5 changes: 4 additions & 1 deletion src/components/notification/alert-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ const getExpectedMessage = (

return Handlebars.compile(alert.message)({
response: {
size: Number(headers['content-length']),
size:
typeof headers === 'string'
? undefined
: Number(headers['content-length']),
status,
time: responseTime,
body: data,
Expand Down
21 changes: 13 additions & 8 deletions src/components/probe/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ import type { MonikaFlags } from '../../flag'
import { FAILED_REQUEST_ASSERTION } from '../../looper'
import { closeLog, openLogfile } from '../logger/history'

let notificationAlert: Record<string, Record<string, any>> = {}
let notificationAlert: Record<
string,
Record<string, Record<string, never>>
> = {}
const server = setupServer(
rest.get('https://example.com', (_, res, ctx) => res(ctx.status(200))),
rest.post('https://example.com/webhook', async (req, res, ctx) => {
Expand Down Expand Up @@ -444,7 +447,7 @@ describe('Base Probe processing', () => {
async connect() {},
on: () => '',
ping: async () => 'PONG',
} as any)
} as never)
)
const probes = [
{
Expand Down Expand Up @@ -483,7 +486,7 @@ describe('Base Probe processing', () => {
async connect() {},
on: () => '',
ping: async () => 'PONG',
} as any)
} as never)
)
const probes = [
{
Expand Down Expand Up @@ -514,16 +517,18 @@ describe('Base Probe processing', () => {

it('should probe socket', async () => {
const requestStub = sinon.stub(net, 'createConnection').callsFake(() => {
let data = ''

let data: Buffer | Uint8Array
return {
write(d: any) {
write(d: Buffer | Uint8Array) {
data = d
},
setTimeout(timeoutMs: number) {
return timeoutMs
},
on(type: string, callback: (data?: any) => void) {
on(
type: string,
callback: (data?: Buffer | Uint8Array | Error) => void
) {
switch (type) {
case 'data': {
callback(data)
Expand All @@ -541,7 +546,7 @@ describe('Base Probe processing', () => {
}

case 'error': {
callback('error')
callback(new Error('Stub Error'))
break
}

Expand Down
5 changes: 4 additions & 1 deletion src/components/probe/prober/http/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ import { FAILED_REQUEST_ASSERTION } from '../../../../looper'
import { closeLog, openLogfile } from '../../../logger/history'

let urlRequestTotal = 0
let notificationAlert: Record<string, Record<string, any>> = {}
let notificationAlert: Record<
string,
Record<string, Record<string, never>>
> = {}
const server = setupServer(
rest.get('https://example.com', (_, res, ctx) => {
urlRequestTotal += 1
Expand Down
2 changes: 1 addition & 1 deletion src/components/probe/prober/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function getProbeResultMessage({
}: ProbeResultMessageParams): string {
// TODO: make this more generic not probe dependent

Check warning on line 263 in src/components/probe/prober/http/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected 'todo' comment: 'TODO: make this more generic not probe...'
if (request?.ping) {
return response?.body
return response?.body as string
}

if (getContext().flags.verbose) {
Expand Down
16 changes: 8 additions & 8 deletions src/components/probe/prober/http/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('probingHTTP', () => {
return res(ctx.status(200))
})
)
const request: any = {
const request = {
url: 'http://localhost:4000/login',
method: 'POST',
headers: { 'content-type': 'application/x-www-form-urlencoded' },
Expand Down Expand Up @@ -162,7 +162,7 @@ describe('probingHTTP', () => {
url: 'https://example.com',
method: 'POST',
headers: { 'content-type': 'multipart/form-data' },
body: { username: '[email protected]', password: 'drowssap' } as any,
body: { username: '[email protected]', password: 'drowssap' } as never,
timeout: 10_000,
}

Expand Down Expand Up @@ -200,7 +200,7 @@ describe('probingHTTP', () => {
url: 'https://example.com',
method: 'POST',
headers: { 'content-type': 'text/plain' },
body: 'multiline string\nexample' as any,
body: 'multiline string\nexample',
timeout: 10_000,
}

Expand Down Expand Up @@ -238,7 +238,7 @@ describe('probingHTTP', () => {
url: 'https://example.com',
method: 'POST',
headers: { 'content-type': 'text/yaml' },
body: { username: '[email protected]', password: 'secret' } as any,
body: { username: '[email protected]', password: 'secret' } as never,
timeout: 10_000,
}

Expand Down Expand Up @@ -276,7 +276,7 @@ describe('probingHTTP', () => {
url: 'https://example.com',
method: 'POST',
headers: { 'content-type': 'application/xml' },
body: { username: '[email protected]', password: 'secret' } as any,
body: { username: '[email protected]', password: 'secret' } as never,
timeout: 10_000,
}

Expand Down Expand Up @@ -314,7 +314,7 @@ describe('probingHTTP', () => {
url: 'https://example.com',
method: 'POST',
headers: { 'content-type': 'text/plain' },
body: 'multiline string\nexample' as any,
body: 'multiline string\nexample',
timeout: 10_000,
allowUnauthorized: true,
}
Expand All @@ -335,9 +335,9 @@ describe('probingHTTP', () => {
it('should generate request chaining body', () => {
// arrange
type TestTable = {
body: Record<string, any> | string
body: Record<string, unknown> | string
responses: ProbeRequestResponse[]
expected: Record<string, any> | string
expected: Record<string, unknown> | string
}
const testTables: TestTable[] = [
{
Expand Down
10 changes: 5 additions & 5 deletions src/components/probe/prober/http/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export async function httpRequest({

if (contentTypeKey) {
const { content, contentType } = transformContentByType(
newReq.body,
newReq?.body,
(headers || {})[contentTypeKey]
)

Expand Down Expand Up @@ -234,7 +234,7 @@ export async function httpRequest({
}

export function generateRequestChainingBody(
body: JSON | string,
body: object | string,
responses: ProbeRequestResponse[]
): JSON | string {
const isString = typeof body === 'string'
Expand All @@ -245,13 +245,13 @@ export function generateRequestChainingBody(
}

function transformContentByType(
content: any,
content: object | string,
contentType?: string | number | boolean
) {
switch (contentType) {
case 'application/x-www-form-urlencoded': {
return {
content: qs.stringify(content),
content: qs.stringify(content as never),
contentType,
}
}
Expand All @@ -260,7 +260,7 @@ function transformContentByType(
const form = new FormData()

for (const contentKey of Object.keys(content)) {
form.append(contentKey, content[contentKey])
form.append(contentKey, (content as Record<string, never>)[contentKey])
}

return { content: form, contentType: form.getHeaders()['content-type'] }
Expand Down
5 changes: 2 additions & 3 deletions src/components/probe/prober/mariadb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ export class MariaDBProber extends BaseProber {
}

private getConnectionDetails(): string {
const connectionDetails = this.probeConfig?.mariadb
? this.probeConfig?.mariadb
: this.probeConfig?.mysql
const connectionDetails =
this.probeConfig?.mariadb || this.probeConfig?.mysql

return (
connectionDetails
Expand Down
2 changes: 1 addition & 1 deletion src/components/probe/prober/mongo/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ async function sendMongoRequest(params: MongoRequest): Promise<MongoResult> {
try {
await client.connect()

client.on('error', (error: any) => {
client.on('error', (error: string | undefined) => {
result.message = error
})

Expand Down
Loading

0 comments on commit 565a200

Please sign in to comment.