From f29c872baa01e9dff1678880720434c83d02005c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Kopycin=CC=81ski?= Date: Wed, 30 Oct 2019 22:31:27 +0100 Subject: [PATCH] Fix lint issues --- .eslintrc.js | 9 ++----- .../embeddables/embedded_map.test.tsx | 9 +++++++ .../components/link_to/redirect_wrapper.tsx | 4 +-- .../components/resize_handle/is_resizing.tsx | 2 +- .../components/scroll_to_top/index.test.tsx | 6 ++--- .../public/components/scroll_to_top/index.tsx | 2 +- .../body/column_headers/index.test.tsx | 2 +- .../timeline/body/column_headers/index.tsx | 4 +-- .../endgame_security_event_details_line.tsx | 6 ++--- .../body/renderers/endgame/helpers.test.tsx | 16 +++++------ .../body/renderers/endgame/helpers.ts | 6 ++--- .../public/components/toasters/index.test.tsx | 27 +++++-------------- .../lib/settings/use_kibana_ui_setting.ts | 15 ++++++----- .../settings/use_kibana_ui_settings.test.tsx | 4 +-- 14 files changed, 52 insertions(+), 60 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 8ed89d47d43ebb..adbf3398f105cc 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -214,13 +214,6 @@ module.exports = { 'jsx-a11y/click-events-have-key-events': 'off', }, }, - { - files: ['x-pack/legacy/plugins/siem/**/*.{js,ts,tsx}'], - rules: { - 'react-hooks/exhaustive-deps': 'off', - 'react-hooks/rules-of-hooks': 'off', - }, - }, { files: ['x-pack/legacy/plugins/snapshot_restore/**/*.{js,ts,tsx}'], rules: { @@ -838,6 +831,8 @@ module.exports = { // might be introduced after the other warns are fixed // 'react/jsx-sort-props': 'error', 'react/jsx-tag-spacing': 'error', + // might be introduced after the other warns are fixed + 'react-hooks/exhaustive-deps': 'off', 'require-atomic-updates': 'error', 'rest-spread-spacing': ['error', 'never'], 'symbol-description': 'error', diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.test.tsx b/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.test.tsx index de3e27d7646b90..3c06cf8c7cf35a 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.test.tsx @@ -10,6 +10,7 @@ import * as React from 'react'; import { EmbeddedMap } from './embedded_map'; import { SetQuery } from './types'; import { useKibanaCore } from '../../lib/compose/kibana_core'; +import { useIndexPatterns } from '../../hooks/use_index_patterns'; jest.mock('../search_bar', () => ({ siemFilterManager: { @@ -17,6 +18,10 @@ jest.mock('../search_bar', () => ({ }, })); +const mockUseIndexPatterns = useIndexPatterns as jest.Mock; +jest.mock('../../hooks/use_index_patterns'); +mockUseIndexPatterns.mockImplementation(() => [true, []]); + const mockUseKibanaCore = useKibanaCore as jest.Mock; jest.mock('../../lib/compose/kibana_core'); mockUseKibanaCore.mockImplementation(() => ({ @@ -30,6 +35,10 @@ mockUseKibanaCore.mockImplementation(() => ({ jest.mock('../../lib/compose/kibana_plugins'); +jest.mock('ui/vis/lib/timezone', () => ({ + timezoneProvider: () => () => 'America/New_York', +})); + describe('EmbeddedMap', () => { let setQuery: SetQuery; diff --git a/x-pack/legacy/plugins/siem/public/components/link_to/redirect_wrapper.tsx b/x-pack/legacy/plugins/siem/public/components/link_to/redirect_wrapper.tsx index 2b56dd44c970a9..39f24e8351f63d 100644 --- a/x-pack/legacy/plugins/siem/public/components/link_to/redirect_wrapper.tsx +++ b/x-pack/legacy/plugins/siem/public/components/link_to/redirect_wrapper.tsx @@ -6,13 +6,13 @@ import React from 'react'; import { Redirect } from 'react-router-dom'; -import { scrollToTop } from '../scroll_to_top'; +import { useScrollToTop } from '../scroll_to_top'; export interface RedirectWrapperProps { to: string; } export const RedirectWrapper = ({ to }: RedirectWrapperProps) => { - scrollToTop(); + useScrollToTop(); return ; }; diff --git a/x-pack/legacy/plugins/siem/public/components/resize_handle/is_resizing.tsx b/x-pack/legacy/plugins/siem/public/components/resize_handle/is_resizing.tsx index 409c7cb85e1d1b..5eb2d397b4c989 100644 --- a/x-pack/legacy/plugins/siem/public/components/resize_handle/is_resizing.tsx +++ b/x-pack/legacy/plugins/siem/public/components/resize_handle/is_resizing.tsx @@ -6,7 +6,7 @@ import { useState } from 'react'; -export const isContainerResizing = () => { +export const useIsContainerResizing = () => { const [isResizing, setIsResizing] = useState(false); return { diff --git a/x-pack/legacy/plugins/siem/public/components/scroll_to_top/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/scroll_to_top/index.test.tsx index 66d7d2764511fe..1bd30bad818d19 100644 --- a/x-pack/legacy/plugins/siem/public/components/scroll_to_top/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/scroll_to_top/index.test.tsx @@ -8,7 +8,7 @@ import { mount } from 'enzyme'; import * as React from 'react'; import { globalNode, HookWrapper } from '../../mock'; -import { scrollToTop } from '.'; +import { useScrollToTop } from '.'; const spyScroll = jest.fn(); const spyScrollTo = jest.fn(); @@ -21,7 +21,7 @@ describe('Scroll to top', () => { test('scroll have been called', () => { Object.defineProperty(globalNode.window, 'scroll', { value: spyScroll }); - mount( scrollToTop()} />); + mount( useScrollToTop()} />); expect(spyScroll).toHaveBeenCalledWith({ top: 0, @@ -32,7 +32,7 @@ describe('Scroll to top', () => { test('scrollTo have been called', () => { Object.defineProperty(globalNode.window, 'scroll', { value: null }); Object.defineProperty(globalNode.window, 'scrollTo', { value: spyScrollTo }); - mount( scrollToTop()} />); + mount( useScrollToTop()} />); expect(spyScrollTo).toHaveBeenCalled(); }); }); diff --git a/x-pack/legacy/plugins/siem/public/components/scroll_to_top/index.tsx b/x-pack/legacy/plugins/siem/public/components/scroll_to_top/index.tsx index 37df779c23fcb4..59f9c99d6ab8ef 100644 --- a/x-pack/legacy/plugins/siem/public/components/scroll_to_top/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/scroll_to_top/index.tsx @@ -6,7 +6,7 @@ import { useEffect } from 'react'; -export const scrollToTop = () => { +export const useScrollToTop = () => { useEffect(() => { // trying to use new API - https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo if (window.scroll) { diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/column_headers/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/body/column_headers/index.test.tsx index aec534dd8fc856..851d48a19c2e4c 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/column_headers/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/column_headers/index.test.tsx @@ -19,7 +19,7 @@ import { ColumnHeaders } from '.'; jest.mock('../../../resize_handle/is_resizing', () => ({ ...jest.requireActual('../../../resize_handle/is_resizing'), - isContainerResizing: () => ({ + useIsContainerResizing: () => ({ isResizing: true, setIsResizing: jest.fn(), }), diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/column_headers/index.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/body/column_headers/index.tsx index 4bd2bce0152520..c4239c0eb7f384 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/column_headers/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/column_headers/index.tsx @@ -18,7 +18,7 @@ import { import { DraggableFieldBadge } from '../../../draggables/field_badge'; import { StatefulFieldsBrowser } from '../../../fields_browser'; import { FIELD_BROWSER_HEIGHT, FIELD_BROWSER_WIDTH } from '../../../fields_browser/helpers'; -import { isContainerResizing } from '../../../resize_handle/is_resizing'; +import { useIsContainerResizing } from '../../../resize_handle/is_resizing'; import { OnColumnRemoved, OnColumnResized, @@ -72,7 +72,7 @@ export const ColumnHeaders = React.memo( timelineId, toggleColumn, }) => { - const { isResizing, setIsResizing } = isContainerResizing(); + const { isResizing, setIsResizing } = useIsContainerResizing(); return ( diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/endgame_security_event_details_line.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/endgame_security_event_details_line.tsx index 97138580618ba2..185e9c9a8287a2 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/endgame_security_event_details_line.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/endgame_security_event_details_line.tsx @@ -18,7 +18,7 @@ import { getHumanReadableLogonType, getUserDomainField, getUserNameField, - useTargetUserAndTargetDomain, + getTargetUserAndTargetDomain, } from './helpers'; import * as i18n from './translations'; @@ -65,10 +65,10 @@ export const EndgameSecurityEventDetailsLine = React.memo( userName, winlogEventId, }) => { - const domain = useTargetUserAndTargetDomain(eventAction) ? endgameTargetDomainName : userDomain; + const domain = getTargetUserAndTargetDomain(eventAction) ? endgameTargetDomainName : userDomain; const eventDetails = getEventDetails(eventAction); const hostNameSeparator = getHostNameSeparator(eventAction); - const user = useTargetUserAndTargetDomain(eventAction) ? endgameTargetUserName : userName; + const user = getTargetUserAndTargetDomain(eventAction) ? endgameTargetUserName : userName; const userDomainField = getUserDomainField(eventAction); const userNameField = getUserNameField(eventAction); diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/helpers.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/helpers.test.tsx index 06a24730242a8d..dd57239adc94e3 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/helpers.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/helpers.test.tsx @@ -7,7 +7,7 @@ import { getHostNameSeparator, getHumanReadableLogonType, - useTargetUserAndTargetDomain, + getTargetUserAndTargetDomain, getUserDomainField, getUserNameField, getEventDetails, @@ -102,29 +102,29 @@ describe('helpers', () => { }); }); - describe('#useTargetUserAndTargetDomain', () => { + describe('#getTargetUserAndTargetDomain', () => { test('it returns false when eventAction is undefined', () => { - expect(useTargetUserAndTargetDomain(undefined)).toEqual(false); + expect(getTargetUserAndTargetDomain(undefined)).toEqual(false); }); test('it returns false when eventAction is null', () => { - expect(useTargetUserAndTargetDomain(null)).toEqual(false); + expect(getTargetUserAndTargetDomain(null)).toEqual(false); }); test('it returns false when eventAction is an empty string', () => { - expect(useTargetUserAndTargetDomain('')).toEqual(false); + expect(getTargetUserAndTargetDomain('')).toEqual(false); }); test('it returns false when eventAction is a random value', () => { - expect(useTargetUserAndTargetDomain('a random value')).toEqual(false); + expect(getTargetUserAndTargetDomain('a random value')).toEqual(false); }); test('it returns true when eventAction is "explicit_user_logon"', () => { - expect(useTargetUserAndTargetDomain('explicit_user_logon')).toEqual(true); + expect(getTargetUserAndTargetDomain('explicit_user_logon')).toEqual(true); }); test('it returns true when eventAction is "user_logoff"', () => { - expect(useTargetUserAndTargetDomain('user_logoff')).toEqual(true); + expect(getTargetUserAndTargetDomain('user_logoff')).toEqual(true); }); }); diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/helpers.ts b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/helpers.ts index 7470c3618fe5c3..0912238004d5a4 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/helpers.ts +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/endgame/helpers.ts @@ -40,14 +40,14 @@ export const getHumanReadableLogonType = (endgameLogonType: number | null | unde export const getHostNameSeparator = (eventAction: string | null | undefined): string => eventAction === 'explicit_user_logon' ? i18n.TO : '@'; -export const useTargetUserAndTargetDomain = (eventAction: string | null | undefined): boolean => +export const getTargetUserAndTargetDomain = (eventAction: string | null | undefined): boolean => eventAction === 'explicit_user_logon' || eventAction === 'user_logoff'; export const getUserDomainField = (eventAction: string | null | undefined): string => - useTargetUserAndTargetDomain(eventAction) ? 'endgame.target_domain_name' : 'user.domain'; + getTargetUserAndTargetDomain(eventAction) ? 'endgame.target_domain_name' : 'user.domain'; export const getUserNameField = (eventAction: string | null | undefined): string => - useTargetUserAndTargetDomain(eventAction) ? 'endgame.target_user_name' : 'user.name'; + getTargetUserAndTargetDomain(eventAction) ? 'endgame.target_user_name' : 'user.name'; export const getEventDetails = (eventAction: string | null | undefined): string => { switch (eventAction) { diff --git a/x-pack/legacy/plugins/siem/public/components/toasters/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/toasters/index.test.tsx index bf98412c2a6394..7579d6207a8e53 100644 --- a/x-pack/legacy/plugins/siem/public/components/toasters/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/toasters/index.test.tsx @@ -47,7 +47,6 @@ describe('Toaster', () => { ); wrapper.find('[data-test-subj="add-toast"]').simulate('click'); - wrapper.update(); expect(wrapper.find('[data-test-subj="add-toaster-id-super-id"]').exists()).toBe(true); }); test('we can delete a toast in the reducer', () => { @@ -61,7 +60,7 @@ describe('Toaster', () => { return ( <>