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

## Summary

* Removes ts-ignore where it is not being used
* Replaces ts-ignore with the better alternative which is the ts-expect-error
This commit is contained in:
Frank Hassanabad 2020-08-04 14:04:45 -06:00 committed by GitHub
parent 54e13ad6f6
commit f506279a55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 25 additions and 41 deletions

View file

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

View file

@ -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();

View file

@ -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 });
}
@ -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 });
}

View file

@ -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}

View file

@ -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) &&

View file

@ -8,7 +8,6 @@ import {
EuiButton,
EuiButtonEmpty,
EuiCheckbox,
// @ts-ignore no-exported-member
EuiFilePicker,
EuiModal,
EuiModalBody,

View file

@ -8,7 +8,7 @@ import {
EuiFlexGroup,
EuiFlexItem,
EuiLoadingSpinner,
// @ts-ignore
// @ts-expect-error
EuiLoadingSpinnerSize,
EuiText,
} from '@elastic/eui';

View file

@ -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;

View file

@ -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}

View file

@ -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}

View file

@ -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';

View file

@ -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 = {

View file

@ -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', () => {

View file

@ -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');
@ -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');

View file

@ -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' },
},
]),

View file

@ -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;
});
}

View file

@ -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,

View file

@ -114,7 +114,7 @@ export const createEmbeddable = async (
if (!isErrorEmbeddable(embeddableObject)) {
embeddableObject.setRenderTooltipContent(renderTooltipContent);
// @ts-ignore
// @ts-expect-error
await embeddableObject.setLayerList(getLayerList(indexPatterns));
}

View file

@ -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,

View file

@ -9,7 +9,6 @@ import {
EuiFilterButton,
EuiFlexGroup,
EuiFlexItem,
// @ts-ignore
EuiSearchBar,
} from '@elastic/eui';
import React, { useMemo } from 'react';

View file

@ -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]

View file

@ -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);
});
@ -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);
});
@ -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);
@ -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',
@ -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',

View file

@ -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);
});

View file

@ -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,

View file

@ -34,7 +34,6 @@ export const updateTimelinesRoute = (
tags: ['access:securitySolution'],
},
},
// eslint-disable-next-line complexity
async (context, request, response) => {
const siemResponse = buildSiemResponse(response);

View file

@ -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'],
},