Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SIEM] [Detection Engine] Remove unnecessary ts-ignores #58689

Merged
merged 2 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export const createFindRulesStatusRoute = (getClients: GetScopedClients): Hapi.S
searchFields: ['alertId'],
});
const accumulated = await acc;

// Array accessors can result in undefined but
// this is not represented in typescript for some reason,
// https://github.com/Microsoft/TypeScript/issues/11122
const currentStatus = convertToSnakeCase<IRuleStatusAttributes>(
lastFiveErrorsForId.saved_objects[0]?.attributes
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import Boom from 'boom';

import { SavedObjectsFindResponse } from 'kibana/server';
import { IRuleSavedAttributesSavedObjectAttributes, IRuleStatusAttributes } from '../rules/types';
import {
transformError,
transformBulkError,
Expand Down Expand Up @@ -323,5 +325,19 @@ describe('utils', () => {
const values = {};
expect(convertToSnakeCase(values)).toEqual({});
});
it('returns null when passed in undefined', () => {
// Array accessors can result in undefined but
// this is not represented in typescript for some reason,
// https://github.com/Microsoft/TypeScript/issues/11122
const values: SavedObjectsFindResponse<IRuleSavedAttributesSavedObjectAttributes> = {
page: 0,
per_page: 5,
total: 0,
saved_objects: [],
};
expect(
convertToSnakeCase<IRuleStatusAttributes>(values.saved_objects[0]?.attributes) // this is undefined, but it says it's not
).toEqual(null);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ export const getIndex = (getSpaceId: () => string, config: LegacyServices['confi
return `${signalsIndex}-${spaceId}`;
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const convertToSnakeCase = <T extends Record<string, any>>(obj: T): Partial<T> | null => {
export const convertToSnakeCase = <T extends Record<string, unknown>>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed explicit any and replaced with unknown.

obj: T
): Partial<T> | null => {
if (!obj) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ describe('read_rules', () => {
});
test('should return null if saved object found by alerts client given id is not alert type', async () => {
const alertsClient = alertsClientMock.create();
const { alertTypeId, ...rest } = getResult();
// @ts-ignore
alertsClient.get.mockImplementation(() => rest);
const result = getResult();
delete result.alertTypeId;
alertsClient.get.mockResolvedValue(result);

const rule = await readRules({
alertsClient,
Expand Down Expand Up @@ -109,8 +109,7 @@ describe('read_rules', () => {
test('should return null if the output from alertsClient with ruleId set is empty', async () => {
const alertsClient = alertsClientMock.create();
alertsClient.get.mockResolvedValue(getResult());
// @ts-ignore
alertsClient.find.mockResolvedValue({ data: [] });
alertsClient.find.mockResolvedValue({ data: [], page: 0, perPage: 1, total: 0 });

const rule = await readRules({
alertsClient,
Expand Down