From bf17898753cc05b778870e09d075a2bd1be95109 Mon Sep 17 00:00:00 2001 From: Frank Hassanabad Date: Fri, 15 Oct 2021 18:38:00 -0600 Subject: [PATCH] one line remove assert (#115127) ## Summary Removes one liner non-null-assert. Instead of this line: ```ts if (rule != null && spacesApi && outcome === 'conflict') { ``` We just check using the `?` operator and type narrowing to remove the possibility of an error ```ts if (rule?.alias_target_id != null && spacesApi && rule.outcome === 'conflict') { ``` The `rule?.alias_target_id != null` ensures that both `rule` and `alias_target_id` are not `null/undefined` --- .../pages/detection_engine/rules/details/index.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/details/index.tsx b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/details/index.tsx index 7167b07c7da5d..774b9463bed69 100644 --- a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/details/index.tsx +++ b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/details/index.tsx @@ -300,10 +300,8 @@ const RuleDetailsPageComponent: React.FC = ({ }, [rule, spacesApi]); const getLegacyUrlConflictCallout = useMemo(() => { - const outcome = rule?.outcome; - if (rule != null && spacesApi && outcome === 'conflict') { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const aliasTargetId = rule?.alias_target_id!; // This is always defined if outcome === 'conflict' + if (rule?.alias_target_id != null && spacesApi && rule.outcome === 'conflict') { + const aliasTargetId = rule.alias_target_id; // We have resolved to one rule, but there is another one with a legacy URL associated with this page. Display a // callout with a warning for the user, and provide a way for them to navigate to the other rule. const otherRulePath = `rules/id/${aliasTargetId}${window.location.search}${window.location.hash}`;