-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Cases] Align cases lint rules with security solution #117177
Conversation
Pinging @elastic/security-threat-hunting-cases (Team:Threat Hunting:Cases) |
@elasticmachine merge upstream |
@@ -5,6 +5,8 @@ | |||
* 2.0. | |||
*/ | |||
|
|||
/* eslint-disable react/display-name */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disabling as it is a mock file
import styled from 'styled-components'; | ||
import { Case, SubCase } from '../../containers/types'; | ||
import { CasesColumns } from './columns'; | ||
import { AssociationType } from '../../../common'; | ||
|
||
type ExpandedRowMap = Record<string, Element> | {}; | ||
|
||
const EuiBasicTable: any = _EuiBasicTable; | ||
// @ts-expect-error TS2769 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could disable the linting rule about any
but I found it better to use @ts-expect-error
because we will be warned if it will be fixed and we do not have to declare _EuiBasicTable
(better readability)
(i, key) => i.name != null && !i.hasOwnProperty('actions') && checkIt(`${i.name}`, key) | ||
(i, key) => | ||
i.name != null && | ||
!Object.prototype.hasOwnProperty.call(i, 'actions') && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace hasOwnProperty
with Object.prototype.hasOwnProperty.call
@@ -378,7 +381,9 @@ describe('AllCasesGeneric', () => { | |||
}) | |||
); | |||
await waitFor(() => { | |||
result.current.map((i) => i.name != null && !i.hasOwnProperty('actions')); | |||
result.current.map( | |||
(i) => i.name != null && !Object.prototype.hasOwnProperty.call(i, 'actions') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace hasOwnProperty
with Object.prototype.hasOwnProperty.call
@@ -60,7 +60,7 @@ export const decodeOrThrow = | |||
const getExcessProps = (props: rt.Props, r: Record<string, unknown>): string[] => { | |||
const ex: string[] = []; | |||
for (const k of Object.keys(r)) { | |||
if (!props.hasOwnProperty(k)) { | |||
if (!Object.prototype.hasOwnProperty.call(props, k)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace hasOwnProperty
with Object.prototype.hasOwnProperty.call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this check really needed? I believe Object.keys()
does not return inherited properties.
EDIT: now I see we are checking props
, not r
. 👍
@@ -9,8 +9,25 @@ import { i18n } from '@kbn/i18n'; | |||
import { CaseConnector, CaseConnectorsRegistry } from './types'; | |||
|
|||
export const createCaseConnectorsRegistry = (): CaseConnectorsRegistry => { | |||
// eslint-disable-next-line @typescript-eslint/no-explicit-any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TS won this battle
} | ||
return connectors.get(id)!; | ||
const connector = connectors.get(id); | ||
assertConnectorExists(connector, id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the logic to an assertion so I can return the connector without having to put !
at the end of the return statement.
const fullName = currentSavedObjectMetaData.getTooltipForSavedObject | ||
? currentSavedObjectMetaData.getTooltipForSavedObject(item.savedObject) | ||
: `${item.title} (${currentSavedObjectMetaData!.name})`; | ||
: `${item.title} (${currentSavedObjectMetaData.name})`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the !
non-null assertion operator. The non-null check is done above
@@ -112,6 +114,7 @@ export const useLensButtonToggle = ({ | |||
) { | |||
if (child.type === 'text') break outer; // don't dive into `text` nodes | |||
node = child; | |||
// eslint-disable-next-line no-continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to fix it may introduce bugs.
@@ -5,6 +5,8 @@ | |||
* 2.0. | |||
*/ | |||
|
|||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to fix it may introduce bugs.
@@ -16,16 +16,25 @@ interface Props { | |||
disableLinks?: boolean; | |||
} | |||
|
|||
const withDisabledLinks = (disableLinks?: boolean): React.FC<EuiLinkAnchorProps> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a HOC that returns a MarkdownLink
component with disableLinks
so we can declare a displayName
.
@@ -165,7 +176,9 @@ export const UserActionTree = React.memo( | |||
const { isLoadingIds, patchComment } = useUpdateComment(); | |||
const currentUser = useCurrentUser(); | |||
const [manageMarkdownEditIds, setManageMarkdownEditIds] = useState<string[]>([]); | |||
const commentRefs = useRef<Record<string, any>>({}); | |||
const commentRefs = useRef< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typed refs
@@ -129,6 +129,17 @@ const MyEuiCommentList = styled(EuiCommentList)` | |||
const DESCRIPTION_ID = 'description'; | |||
const NEW_ID = 'newComment'; | |||
|
|||
const isAddCommentRef = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checks if the ref is of type AddCommentRefObject
commentRefs.current && | ||
commentRefs.current[draftComment.commentId] && | ||
commentRefs.current[draftComment.commentId].editor?.textarea && | ||
commentRefs.current[draftComment.commentId].editor?.toolbar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toolbar
is not part of the editor
object. Nevertheless, openLensModal
function checks for its existence.
const owner = requiredPrivileges.get(privilege)!; | ||
authorizedOwners.push(owner); | ||
const owner = requiredPrivileges.get(privilege); | ||
if (owner) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the !
non-null assertion operation and check if is empty before pushing.
@@ -83,6 +83,7 @@ const SwimlaneFieldsSchema = schema.object({ | |||
|
|||
const NoneFieldsSchema = schema.nullable(schema.object({})); | |||
|
|||
// eslint-disable-next-line @typescript-eslint/no-explicit-any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lost this battle with TS again
if (field && !manageDuplicate[alertFieldMapping[alertField].sirFieldKey].has(field)) { | ||
manageDuplicate[alertFieldMapping[alertField].sirFieldKey].add(field); | ||
acc = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix for the linting rule prohibiting the direct assignment of function arguments
@@ -8,10 +8,14 @@ | |||
import { Boom, isBoom } from '@hapi/boom'; | |||
import { Logger } from 'src/core/server'; | |||
|
|||
export interface HTTPError extends Error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used in x-pack/plugins/cases/server/routes/api/utils.ts
export function wrapError(error: any): CustomHttpResponseOptions<ResponseError> { | ||
|
||
export function wrapError( | ||
error: CaseError | Boom | HTTPError | Error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type error instead of any
@@ -4,7 +4,11 @@ | |||
* 2.0; you may not use this file except in compliance with the Elastic License | |||
* 2.0. | |||
*/ | |||
|
|||
/* eslint-disable @typescript-eslint/no-explicit-any */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it is a script we do not care about TS errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! despite a couple of lost battles against TS (LOL), it is a big improvement.
Thanks Christos, this will help us all.
💚 Build Succeeded
Metrics [docs]Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: cc @cnasikas |
💔 Backport failedThe backport operation could not be completed due to the following error: The backport PRs will be merged automatically after passing CI. To backport manually run: |
Friendly reminder: Looks like this PR hasn’t been backported yet. |
Friendly reminder: Looks like this PR hasn’t been backported yet. |
4 similar comments
Friendly reminder: Looks like this PR hasn’t been backported yet. |
Friendly reminder: Looks like this PR hasn’t been backported yet. |
Friendly reminder: Looks like this PR hasn’t been backported yet. |
Friendly reminder: Looks like this PR hasn’t been backported yet. |
Summary
This PR aligns cases eslint rules with security solution eslint rules.
For maintainers