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

[Security Solution][Tech Debt] cleans up ts-ignore issues and some smaller linter issues #74268

Merged
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 @@ -6,7 +6,7 @@

import { resolve } from 'path';

// @ts-ignore
// @ts-expect-error
import madge from 'madge';
import { createFailError, run } from '@kbn/dev-utils';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

Cypress.Commands.add('stubSecurityApi', function (dataFileName) {
cy.on('window:before:load', (win) => {
// @ts-ignore no null, this is a temp hack see issue above
win.fetch = null;
});
cy.server();
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/security_solution/cypress/tasks/date_picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const setTimelineEndDate = (date: string) => {

cy.get(DATE_PICKER_ABSOLUTE_INPUT).click({ force: true });
cy.get(DATE_PICKER_ABSOLUTE_INPUT).then(($el) => {
// @ts-ignore
if (Cypress.dom.isAttached($el)) {
cy.wrap($el).click({ force: true });
}
Expand All @@ -55,7 +54,6 @@ export const setTimelineStartDate = (date: string) => {

cy.get(DATE_PICKER_ABSOLUTE_INPUT).click({ force: true });
cy.get(DATE_PICKER_ABSOLUTE_INPUT).then(($el) => {
// @ts-ignore
if (Cypress.dom.isAttached($el)) {
cy.wrap($el).click({ force: true });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const EventFieldsBrowser = React.memo<Props>(
return (
<div className="euiTable--compressed">
<EuiInMemoryTable
// @ts-ignore items going in match Partial<BrowserField>, column `render` callbacks expect complete BrowserField
// @ts-expect-error items going in match Partial<BrowserField>, column `render` callbacks expect complete BrowserField
items={items}
columns={columns}
pagination={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ type PropsFromRedux = ConnectedProps<typeof connector>;
export const StatefulEventsViewer = connector(
React.memo(
StatefulEventsViewerComponent,
// eslint-disable-next-line complexity
(prevProps, nextProps) =>
prevProps.id === nextProps.id &&
deepEqual(prevProps.columns, nextProps.columns) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
EuiButton,
EuiButtonEmpty,
EuiCheckbox,
// @ts-ignore no-exported-member
EuiFilePicker,
EuiModal,
EuiModalBody,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
EuiFlexGroup,
EuiFlexItem,
EuiLoadingSpinner,
// @ts-ignore
// @ts-expect-error
EuiLoadingSpinnerSize,
EuiText,
} from '@elastic/eui';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const HeaderChildrenFlexItem = styled(EuiFlexItem)`
margin-left: 24px;
`;

// @ts-ignore - the EUI type definitions for Panel do no play nice with styled-components
const HistogramPanel = styled(Panel)<{ height?: number }>`
display: flex;
flex-direction: column;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ const AnomaliesHostTableComponent: React.FC<AnomaliesHostTableProps> = ({
/>

<BasicTable
// @ts-ignore the Columns<T, U> type is not as specific as EUI's...
// @ts-expect-error the Columns<T, U> type is not as specific as EUI's...
columns={columns}
// @ts-ignore ...which leads to `networks` not "matching" the columns
// @ts-expect-error ...which leads to `networks` not "matching" the columns
items={hosts}
pagination={pagination}
sorting={sorting}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ const AnomaliesNetworkTableComponent: React.FC<AnomaliesNetworkTableProps> = ({
/>

<BasicTable
// @ts-ignore the Columns<T, U> type is not as specific as EUI's...
// @ts-expect-error the Columns<T, U> type is not as specific as EUI's...
columns={columns}
// @ts-ignore ...which leads to `networks` not "matching" the columns
// @ts-expect-error ...which leads to `networks` not "matching" the columns
items={networks}
pagination={pagination}
sorting={sorting}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
EuiFilterGroup,
EuiFlexGroup,
EuiFlexItem,
// @ts-ignore no-exported-member
EuiSearchBar,
} from '@elastic/eui';
import { EuiSearchBarQuery } from '../../../../../timelines/components/open_timeline/types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import { onError } from 'apollo-link-error';
const mockDispatch = jest.fn();
jest.mock('apollo-link-error');
jest.mock('../../store');
// @ts-ignore
store.getStore.mockReturnValue({ dispatch: mockDispatch });
(store.getStore as jest.Mock).mockReturnValue({ dispatch: mockDispatch });

describe('errorLinkHandler', () => {
const mockGraphQLErrors: GraphQLError = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ jest.mock('../../containers/errors');
const mockWithClientState = 'mockWithClientState';
const mockHttpLink = { mockHttpLink: 'mockHttpLink' };

// @ts-ignore
withClientState.mockReturnValue(mockWithClientState);
// @ts-ignore
apolloLinkHttp.createHttpLink.mockImplementation(() => mockHttpLink);
(withClientState as jest.Mock).mockReturnValue(mockWithClientState);
(apolloLinkHttp.createHttpLink as jest.Mock).mockImplementation(() => mockHttpLink);

describe('getLinks helper', () => {
test('It should return links in correct order', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,7 @@ describe('alert actions', () => {
nonEcsData: [],
updateTimelineIsLoading,
});
// @ts-ignore
const createTimelineArg = createTimeline.mock.calls[0][0];
const createTimelineArg = (createTimeline as jest.Mock).mock.calls[0][0];

expect(createTimeline).toHaveBeenCalledTimes(1);
expect(createTimelineArg.timeline.kqlQuery.filterQuery.kuery.kind).toEqual('kuery');
Expand Down Expand Up @@ -285,8 +284,7 @@ describe('alert actions', () => {
nonEcsData: [],
updateTimelineIsLoading,
});
// @ts-ignore
const createTimelineArg = createTimeline.mock.calls[0][0];
const createTimelineArg = (createTimeline as jest.Mock).mock.calls[0][0];

expect(createTimeline).toHaveBeenCalledTimes(1);
expect(createTimelineArg.timeline.kqlQuery.filterQueryDraft.kind).toEqual('kuery');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const buildShowBuildingBlockFilter = (showBuildingBlockAlerts: boolean):
key: 'signal.rule.building_block_type',
value: 'exists',
},
// @ts-ignore TODO: Rework parent typings to support ExistsFilter[]
// @ts-expect-error TODO: Rework parent typings to support ExistsFilter[]
exists: { field: 'signal.rule.building_block_type' },
},
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const hostListApiPathHandlerMocks = ({
// Build a GET route handler for each host details based on the list of Hosts passed on input
if (hostsResults) {
hostsResults.forEach((host) => {
// @ts-ignore
// @ts-expect-error
apiHandlers[`/api/endpoint/metadata/${host.metadata.host.id}`] = () => host;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ export const policyDetailsReducer: ImmutableReducer<PolicyDetailsState, AppActio
/**
* This is directly changing redux state because `policyItem.inputs` was copied over and not cloned.
*/
// @ts-ignore
// @ts-expect-error
newState.policyItem.inputs[0].config.policy.value = newPolicy;

Object.entries(action.payload.policyConfig).forEach(([section, newSettings]) => {
/**
* this is not safe because `action.payload.policyConfig` may have excess keys
*/
// @ts-ignore
// @ts-expect-error
newPolicy[section as keyof UIPolicyConfig] = {
...newPolicy[section as keyof UIPolicyConfig],
...newSettings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const createEmbeddable = async (

if (!isErrorEmbeddable(embeddableObject)) {
embeddableObject.setRenderTooltipContent(renderTooltipContent);
// @ts-ignore
// @ts-expect-error
await embeddableObject.setLayerList(getLayerList(indexPatterns));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ export const getTimelineStatus = (
return duplicate ? TimelineStatus.active : timeline.status;
};

// eslint-disable-next-line complexity
export const defaultTimelineToTimelineModel = (
timeline: TimelineResult,
duplicate: boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
EuiFilterButton,
EuiFlexGroup,
EuiFlexItem,
// @ts-ignore
EuiSearchBar,
} from '@elastic/eui';
import React, { useMemo } from 'react';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const RowRenderersBrowserComponent = React.forwardRef(
const handleNameClick = useCallback(
(item: RowRendererOption) => () => {
const newSelection = xor([item], notExcludedRowRenderers);
// @ts-ignore
// @ts-expect-error
ref?.current?.setSelection(newSelection); // eslint-disable-line no-unused-expressions
},
[notExcludedRowRenderers, ref]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe('filterEventsAgainstList', () => {
);
expect(res.hits.hits.length).toEqual(2);

// @ts-ignore
// @ts-expect-error
const ipVals = res.hits.hits.map((item) => item._source.source.ip);
expect(['3.3.3.3', '7.7.7.7']).toEqual(ipVals);
});
Expand Down Expand Up @@ -188,7 +188,7 @@ describe('filterEventsAgainstList', () => {
expect(listClient.getListItemByValues as jest.Mock).toHaveBeenCalledTimes(2);
expect(res.hits.hits.length).toEqual(6);

// @ts-ignore
// @ts-expect-error
const ipVals = res.hits.hits.map((item) => item._source.source.ip);
expect(['1.1.1.1', '3.3.3.3', '5.5.5.5', '7.7.7.7', '8.8.8.8', '9.9.9.9']).toEqual(ipVals);
});
Expand Down Expand Up @@ -247,7 +247,7 @@ describe('filterEventsAgainstList', () => {
buildRuleMessage,
});
expect(listClient.getListItemByValues as jest.Mock).toHaveBeenCalledTimes(2);
// @ts-ignore
// @ts-expect-error
const ipVals = res.hits.hits.map((item) => item._source.source.ip);
expect(res.hits.hits.length).toEqual(7);

Expand Down Expand Up @@ -324,7 +324,7 @@ describe('filterEventsAgainstList', () => {
expect(listClient.getListItemByValues as jest.Mock).toHaveBeenCalledTimes(2);
expect(res.hits.hits.length).toEqual(8);

// @ts-ignore
// @ts-expect-error
const ipVals = res.hits.hits.map((item) => item._source.source.ip);
expect([
'1.1.1.1',
Expand Down Expand Up @@ -386,7 +386,7 @@ describe('filterEventsAgainstList', () => {
expect(listClient.getListItemByValues as jest.Mock).toHaveBeenCalledTimes(2);
expect(res.hits.hits.length).toEqual(9);

// @ts-ignore
// @ts-expect-error
const ipVals = res.hits.hits.map((item) => item._source.source.ip);
expect([
'1.1.1.1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('elasticsearch_adapter', () => {

describe('#getUsers', () => {
test('will format edges correctly', () => {
// @ts-ignore Re-work `DatabaseSearchResponse` types as mock ES Response won't match
// @ts-expect-error Re-work `DatabaseSearchResponse` types as mock ES Response won't match
const edges = getUsersEdges(mockUsersData);
expect(edges).toEqual(mockFormattedUsersEdges);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const getTimelineTypeAndStatus = (
status: TimelineStatus | null = TimelineStatus.active
) => {
// TODO: Added to support legacy TimelineType.draft, can be removed in 7.10
// @ts-ignore
if (timelineType === 'draft') {
return {
timelineType: TimelineType.default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const updateTimelinesRoute = (
tags: ['access:securitySolution'],
},
},
// eslint-disable-next-line complexity
async (context, request, response) => {
const siemResponse = buildSiemResponse(response);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe('elasticsearch_adapter', () => {
_id: 'id-9',
_score: 0,
_source: {
// @ts-ignore ts doesn't like seeing the object written this way, but sometimes this is the data we get!
// @ts-expect-error ts doesn't like seeing the object written this way, but sometimes this is the data we get!
'host.id': ['host-id-9'],
'host.name': ['host-9'],
},
Expand Down