# no-duplicate-code

Disallow repeated nontrivial code regions

Multiple nontrivial callables or statement sequences perform the same operations.
Instead, you SHOULD extract the repeated statements into one callable.

- Category: suspicious
- Level: warning
- Fix: none
- Scope: program

## Reported

```ds title="main.ds"
function incrementLeft(value: int32): int32 {
    const next = value + 1;
    return next * 2;
}

function incrementRight(input: int32): int32 {
    const result = input + 1;
    return result * 2;
}
```

## Accepted

```ds title="main.ds"
function increment(value: int32): int32 {
    const next = value + 1;
    return next * 2;
}
```

## Prior art

- [eslint-plugin-sonarjs · no-identical-functions](https://github.com/SonarSource/SonarJS/search?q=no-identical-functions&type=code)

[language/linter/src/rules/suspicious/no_duplicate_code.rs:14](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/suspicious/no_duplicate_code.rs#L14)
