# branches-sharing-code

Extract identical branch prefixes or suffixes

The same checked statements occur at the corresponding prefix or suffix of every branch.
Instead, you SHOULD extract the repetition while preserving condition evaluation, branch scope, and drop order.

- Category: style
- Level: warning
- Fix: none
- Scope: module

## Reported

```ds title="main.ds"
declare function record(value: string): void;
declare function flush(): void;
function finish(condition: boolean): void {
    if (condition) {
        record("left");
        flush();
    } else {
        record("right");
        flush();
    }
}
```

## Accepted

```ds title="main.ds"
declare function record(value: string): void;
declare function flush(): void;
function finish(condition: boolean): void {
    if (condition) {
        record("left");
    } else {
        record("right");
    }
    flush();
}
```

## Prior art

- [Clippy · branches_sharing_code](https://rust-lang.github.io/rust-clippy/master/index.html#branches_sharing_code)

[language/linter/src/rules/style/branches_sharing_code.rs:8](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/style/branches_sharing_code.rs#L8)
