Skip to content

Commit d38fb03

Browse files
[Cases] Align cases lint rules with security solution (elastic#117177)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent 4c5e59d commit d38fb03

File tree

35 files changed

+164
-74
lines changed

35 files changed

+164
-74
lines changed

.eslintrc.js

+6-11
Original file line numberDiff line numberDiff line change
@@ -902,17 +902,6 @@ module.exports = {
902902
},
903903
},
904904

905-
/**
906-
* Cases overrides
907-
*/
908-
{
909-
files: ['x-pack/plugins/cases/**/*.{js,mjs,ts,tsx}'],
910-
rules: {
911-
'no-duplicate-imports': 'off',
912-
'@typescript-eslint/no-duplicate-imports': ['error'],
913-
},
914-
},
915-
916905
/**
917906
* Security Solution overrides. These rules below are maintained and owned by
918907
* the people within the security-solution-platform team. Please see ping them
@@ -928,6 +917,8 @@ module.exports = {
928917
'x-pack/plugins/security_solution/common/**/*.{js,mjs,ts,tsx}',
929918
'x-pack/plugins/timelines/public/**/*.{js,mjs,ts,tsx}',
930919
'x-pack/plugins/timelines/common/**/*.{js,mjs,ts,tsx}',
920+
'x-pack/plugins/cases/public/**/*.{js,mjs,ts,tsx}',
921+
'x-pack/plugins/cases/common/**/*.{js,mjs,ts,tsx}',
931922
],
932923
rules: {
933924
'import/no-nodejs-modules': 'error',
@@ -949,10 +940,12 @@ module.exports = {
949940
files: [
950941
'x-pack/plugins/security_solution/**/*.{ts,tsx}',
951942
'x-pack/plugins/timelines/**/*.{ts,tsx}',
943+
'x-pack/plugins/cases/**/*.{ts,tsx}',
952944
],
953945
excludedFiles: [
954946
'x-pack/plugins/security_solution/**/*.{test,mock,test_helper}.{ts,tsx}',
955947
'x-pack/plugins/timelines/**/*.{test,mock,test_helper}.{ts,tsx}',
948+
'x-pack/plugins/cases/**/*.{test,mock,test_helper}.{ts,tsx}',
956949
],
957950
rules: {
958951
'@typescript-eslint/no-non-null-assertion': 'error',
@@ -963,6 +956,7 @@ module.exports = {
963956
files: [
964957
'x-pack/plugins/security_solution/**/*.{ts,tsx}',
965958
'x-pack/plugins/timelines/**/*.{ts,tsx}',
959+
'x-pack/plugins/cases/**/*.{ts,tsx}',
966960
],
967961
rules: {
968962
'@typescript-eslint/no-this-alias': 'error',
@@ -985,6 +979,7 @@ module.exports = {
985979
files: [
986980
'x-pack/plugins/security_solution/**/*.{js,mjs,ts,tsx}',
987981
'x-pack/plugins/timelines/**/*.{js,mjs,ts,tsx}',
982+
'x-pack/plugins/cases/**/*.{js,mjs,ts,tsx}',
988983
],
989984
plugins: ['eslint-plugin-node', 'react'],
990985
env: {

x-pack/plugins/cases/common/api/runtime_types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const decodeOrThrow =
6060
const getExcessProps = (props: rt.Props, r: Record<string, unknown>): string[] => {
6161
const ex: string[] = [];
6262
for (const k of Object.keys(r)) {
63-
if (!props.hasOwnProperty(k)) {
63+
if (!Object.prototype.hasOwnProperty.call(props, k)) {
6464
ex.push(k);
6565
}
6666
}
@@ -89,5 +89,5 @@ export function excess<C extends rt.InterfaceType<rt.Props> | rt.PartialType<rt.
8989
codec.encode,
9090
codec.props
9191
);
92-
return r as any;
92+
return r as C;
9393
}

x-pack/plugins/cases/public/common/lib/kibana/kibana_react.mock.ts

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* 2.0.
66
*/
77

8+
/* eslint-disable react/display-name */
9+
810
import React from 'react';
911

1012
import { RecursivePartial } from '@elastic/eui/src/components/common';

x-pack/plugins/cases/public/components/__mock__/form.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const mockFormHook = {
3636
__readFieldConfigFromSchema: jest.fn(),
3737
};
3838

39-
export const getFormMock = (sampleData: any) => ({
39+
export const getFormMock = (sampleData: unknown) => ({
4040
...mockFormHook,
4141
submit: () =>
4242
Promise.resolve({

x-pack/plugins/cases/public/components/all_cases/expanded_row.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
*/
77

88
import React from 'react';
9-
import { EuiBasicTable as _EuiBasicTable } from '@elastic/eui';
9+
import { EuiBasicTable } from '@elastic/eui';
1010
import styled from 'styled-components';
1111
import { Case, SubCase } from '../../containers/types';
1212
import { CasesColumns } from './columns';
1313
import { AssociationType } from '../../../common';
1414

1515
type ExpandedRowMap = Record<string, Element> | {};
1616

17-
const EuiBasicTable: any = _EuiBasicTable;
17+
// @ts-expect-error TS2769
1818
const BasicTable = styled(EuiBasicTable)`
1919
thead {
2020
display: none;

x-pack/plugins/cases/public/components/all_cases/index.test.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,10 @@ describe('AllCasesGeneric', () => {
303303

304304
await waitFor(() => {
305305
result.current.map(
306-
(i, key) => i.name != null && !i.hasOwnProperty('actions') && checkIt(`${i.name}`, key)
306+
(i, key) =>
307+
i.name != null &&
308+
!Object.prototype.hasOwnProperty.call(i, 'actions') &&
309+
checkIt(`${i.name}`, key)
307310
);
308311
});
309312
});
@@ -378,7 +381,9 @@ describe('AllCasesGeneric', () => {
378381
})
379382
);
380383
await waitFor(() => {
381-
result.current.map((i) => i.name != null && !i.hasOwnProperty('actions'));
384+
result.current.map(
385+
(i) => i.name != null && !Object.prototype.hasOwnProperty.call(i, 'actions')
386+
);
382387
expect(wrapper.find(`a[data-test-subj="case-details-link"]`).exists()).toBeFalsy();
383388
});
384389
});

x-pack/plugins/cases/public/components/all_cases/selector_modal/index.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,8 @@ export const AllCasesSelectorModal: React.FC<AllCasesSelectorModalProps> = React
8787
</OwnerProvider>
8888
);
8989
});
90+
91+
AllCasesSelectorModal.displayName = 'AllCasesSelectorModal';
92+
9093
// eslint-disable-next-line import/no-default-export
9194
export { AllCasesSelectorModal as default };

x-pack/plugins/cases/public/components/all_cases/table.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
EuiEmptyPrompt,
1111
EuiLoadingContent,
1212
EuiTableSelectionType,
13-
EuiBasicTable as _EuiBasicTable,
13+
EuiBasicTable,
1414
EuiBasicTableProps,
1515
} from '@elastic/eui';
1616
import classnames from 'classnames';
@@ -40,12 +40,12 @@ interface CasesTableProps {
4040
selection: EuiTableSelectionType<Case>;
4141
showActions: boolean;
4242
sorting: EuiBasicTableProps<Case>['sorting'];
43-
tableRef: MutableRefObject<_EuiBasicTable | undefined>;
43+
tableRef: MutableRefObject<EuiBasicTable | undefined>;
4444
tableRowProps: EuiBasicTableProps<Case>['rowProps'];
4545
userCanCrud: boolean;
4646
}
4747

48-
const EuiBasicTable: any = _EuiBasicTable;
48+
// @ts-expect-error TS2769
4949
const BasicTable = styled(EuiBasicTable)`
5050
${({ theme }) => `
5151
.euiTableRow-isExpandedRow.euiTableRow-isSelectable .euiTableCellContent {

x-pack/plugins/cases/public/components/configure_cases/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -242,5 +242,7 @@ export const ConfigureCases: React.FC<ConfigureCasesProps> = React.memo((props)
242242
);
243243
});
244244

245+
ConfigureCases.displayName = 'ConfigureCases';
246+
245247
// eslint-disable-next-line import/no-default-export
246248
export default ConfigureCases;

x-pack/plugins/cases/public/components/connectors/connectors_registry.ts

+20-11
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,25 @@ import { i18n } from '@kbn/i18n';
99
import { CaseConnector, CaseConnectorsRegistry } from './types';
1010

1111
export const createCaseConnectorsRegistry = (): CaseConnectorsRegistry => {
12+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1213
const connectors: Map<string, CaseConnector<any>> = new Map();
1314

15+
function assertConnectorExists(
16+
connector: CaseConnector | undefined | null,
17+
id: string
18+
): asserts connector {
19+
if (!connector) {
20+
throw new Error(
21+
i18n.translate('xpack.cases.connecors.get.missingCaseConnectorErrorMessage', {
22+
defaultMessage: 'Object type "{id}" is not registered.',
23+
values: {
24+
id,
25+
},
26+
})
27+
);
28+
}
29+
}
30+
1431
const registry: CaseConnectorsRegistry = {
1532
has: (id: string) => connectors.has(id),
1633
register: <UIProps>(connector: CaseConnector<UIProps>) => {
@@ -28,17 +45,9 @@ export const createCaseConnectorsRegistry = (): CaseConnectorsRegistry => {
2845
connectors.set(connector.id, connector);
2946
},
3047
get: <UIProps>(id: string): CaseConnector<UIProps> => {
31-
if (!connectors.has(id)) {
32-
throw new Error(
33-
i18n.translate('xpack.cases.connecors.get.missingCaseConnectorErrorMessage', {
34-
defaultMessage: 'Object type "{id}" is not registered.',
35-
values: {
36-
id,
37-
},
38-
})
39-
);
40-
}
41-
return connectors.get(id)!;
48+
const connector = connectors.get(id);
49+
assertConnectorExists(connector, id);
50+
return connector;
4251
},
4352
list: () => {
4453
return Array.from(connectors).map(([id, connector]) => connector);

x-pack/plugins/cases/public/components/create/description.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const DescriptionComponent: React.FC<Props> = ({ isLoading }) => {
2121
useLensDraftComment();
2222
const { setFieldValue } = useFormContext();
2323
const [{ title, tags }] = useFormData({ watch: ['title', 'tags'] });
24-
const editorRef = useRef<Record<string, any>>();
24+
const editorRef = useRef<Record<string, unknown>>();
2525

2626
useEffect(() => {
2727
if (draftComment?.commentId === fieldName && editorRef.current) {

x-pack/plugins/cases/public/components/create/index.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,8 @@ export const CreateCase: React.FC<CreateCaseProps> = React.memo((props) => (
9898
<CreateCaseComponent {...props} />
9999
</OwnerProvider>
100100
));
101+
102+
CreateCase.displayName = 'CreateCase';
103+
101104
// eslint-disable-next-line import/no-default-export
102105
export { CreateCase as default };

x-pack/plugins/cases/public/components/markdown_editor/editor.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,6 @@ const MarkdownEditorComponent = forwardRef<MarkdownEditorRef, MarkdownEditorProp
9696
}
9797
);
9898

99+
MarkdownEditorComponent.displayName = 'MarkdownEditorComponent';
100+
99101
export const MarkdownEditor = memo(MarkdownEditorComponent);

x-pack/plugins/cases/public/components/markdown_editor/eui_form.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,5 @@ export const MarkdownEditorForm = React.memo(
7575
}
7676
)
7777
);
78+
79+
MarkdownEditorForm.displayName = 'MarkdownEditorForm';

x-pack/plugins/cases/public/components/markdown_editor/plugins/lens/plugin.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ const LensEditorComponent: LensEuiMarkdownEditorUiPlugin['editor'] = ({
140140
});
141141

142142
lens?.navigateToPrefilledEditor(undefined, {
143-
originatingApp: currentAppId!,
143+
originatingApp: currentAppId,
144144
originatingPath,
145145
});
146146
}, [
@@ -174,7 +174,7 @@ const LensEditorComponent: LensEuiMarkdownEditorUiPlugin['editor'] = ({
174174
}
175175
: undefined,
176176
{
177-
originatingApp: currentAppId!,
177+
originatingApp: currentAppId,
178178
originatingPath,
179179
}
180180
);
@@ -310,7 +310,6 @@ const LensEditorComponent: LensEuiMarkdownEditorUiPlugin['editor'] = ({
310310

311311
if (draftComment) {
312312
handleAdd(incomingEmbeddablePackage?.input.attributes, newTimeRange);
313-
return;
314313
}
315314
}
316315
}, [embeddable, storage, timefilter, currentAppId, handleAdd, handleUpdate, draftComment]);

x-pack/plugins/cases/public/components/markdown_editor/plugins/lens/saved_objects_finder.tsx

+11-4
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ export class SavedObjectFinderUi extends React.Component<
201201

202202
public render() {
203203
return (
204-
<React.Fragment>
204+
<>
205205
{this.renderSearchBar()}
206206
{this.renderListing()}
207-
</React.Fragment>
207+
</>
208208
);
209209
}
210210

@@ -481,16 +481,23 @@ export class SavedObjectFinderUi extends React.Component<
481481
{items.map((item) => {
482482
const currentSavedObjectMetaData = savedObjectMetaData.find(
483483
(metaData) => metaData.type === item.type
484-
)!;
484+
);
485+
486+
if (currentSavedObjectMetaData == null) {
487+
return null;
488+
}
489+
485490
const fullName = currentSavedObjectMetaData.getTooltipForSavedObject
486491
? currentSavedObjectMetaData.getTooltipForSavedObject(item.savedObject)
487-
: `${item.title} (${currentSavedObjectMetaData!.name})`;
492+
: `${item.title} (${currentSavedObjectMetaData.name})`;
493+
488494
const iconType = (
489495
currentSavedObjectMetaData ||
490496
({
491497
getIconForSavedObject: () => 'document',
492498
} as Pick<SavedObjectMetaData<{ title: string }>, 'getIconForSavedObject'>)
493499
).getIconForSavedObject(item.savedObject);
500+
494501
return (
495502
<EuiListGroupItem
496503
key={item.id}

x-pack/plugins/cases/public/components/markdown_editor/plugins/lens/use_lens_button_toggle.ts

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* 2.0.
66
*/
77

8+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
9+
810
import { some } from 'lodash';
911
import useDebounce from 'react-use/lib/useDebounce';
1012
import { ContextShape } from '@elastic/eui/src/components/markdown_editor/markdown_context';
@@ -112,6 +114,7 @@ export const useLensButtonToggle = ({
112114
) {
113115
if (child.type === 'text') break outer; // don't dive into `text` nodes
114116
node = child;
117+
// eslint-disable-next-line no-continue
115118
continue outer;
116119
}
117120
}

x-pack/plugins/cases/public/components/markdown_editor/renderer.tsx

+14-5
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,25 @@ interface Props {
1616
disableLinks?: boolean;
1717
}
1818

19+
const withDisabledLinks = (disableLinks?: boolean): React.FC<EuiLinkAnchorProps> => {
20+
const MarkdownLinkProcessingComponent: React.FC<EuiLinkAnchorProps> = memo((props) => (
21+
<MarkdownLink {...props} disableLinks={disableLinks} />
22+
));
23+
24+
MarkdownLinkProcessingComponent.displayName = 'MarkdownLinkProcessingComponent';
25+
26+
return MarkdownLinkProcessingComponent;
27+
};
28+
1929
const MarkdownRendererComponent: React.FC<Props> = ({ children, disableLinks }) => {
2030
const { processingPlugins, parsingPlugins } = usePlugins();
21-
const MarkdownLinkProcessingComponent: React.FC<EuiLinkAnchorProps> = useMemo(
22-
() => (props) => <MarkdownLink {...props} disableLinks={disableLinks} />,
23-
[disableLinks]
24-
);
2531
// Deep clone of the processing plugins to prevent affecting the markdown editor.
2632
const processingPluginList = cloneDeep(processingPlugins);
2733
// This line of code is TS-compatible and it will break if [1][1] change in the future.
28-
processingPluginList[1][1].components.a = MarkdownLinkProcessingComponent;
34+
processingPluginList[1][1].components.a = useMemo(
35+
() => withDisabledLinks(disableLinks),
36+
[disableLinks]
37+
);
2938

3039
return (
3140
<EuiMarkdownFormat

x-pack/plugins/cases/public/components/recent_cases/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,7 @@ export const RecentCases: React.FC<RecentCasesProps> = React.memo((props) => {
100100
);
101101
});
102102

103+
RecentCases.displayName = 'RecentCases';
104+
103105
// eslint-disable-next-line import/no-default-export
104106
export { RecentCases as default };

x-pack/plugins/cases/public/components/user_action_tree/helpers.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ const ActionIcon = React.memo<{
396396
);
397397
});
398398

399+
ActionIcon.displayName = 'ActionIcon';
400+
399401
export const getActionAttachment = ({
400402
comment,
401403
userCanCrud,

0 commit comments

Comments
 (0)