Skip to content

Commit

Permalink
one line remove assert (elastic#115127)
Browse files Browse the repository at this point in the history
## 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`
  • Loading branch information
FrankHassanabad authored and kibanamachine committed Oct 16, 2021
1 parent 5aa8e9b commit ffc691d
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,8 @@ const RuleDetailsPageComponent: React.FC<DetectionEngineComponentProps> = ({
}, [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}`;
Expand Down

0 comments on commit ffc691d

Please sign in to comment.