# no-duplicate-in-composite

Rule `sonarjs/no-duplicate-in-composite`. Union and intersection types should not include duplicated constituents

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1254 by reach, #555 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/no-duplicate-in-composite` | yes | suggestion | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-4621/) |

## Code examples

### Incorrect: the rule reports this

```js
function padLeft(value: string, padding: string | number | string) { // Noncompliant; 'string' type is used twice in a union type declaration
  // ...
}

function extend(p : Person) : Person & Person & Loggable { // Noncompliant; 'Person' is used twice
 // ...
}
```

### Correct: the rule accepts this

```js
function padLeft(value: string, padding: string | number | boolean) {
  // ...
}

function extend(p : Person) : Person & Loggable {
  // ...
}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/no-duplicate-in-composite": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/no-delete-var](https://lintradar.dev/rules/sonarjs/no-delete-var.md): "delete" should be used only with object properties
- [sonarjs/no-duplicate-parameterized-test-case](https://lintradar.dev/rules/sonarjs/no-duplicate-parameterized-test-case.md): Parameterized tests should not contain duplicate test cases
- [sonarjs/no-default-utility-imports](https://lintradar.dev/rules/sonarjs/no-default-utility-imports.md): Default imports from modular utility libraries should not be used
- [sonarjs/no-duplicate-test-title](https://lintradar.dev/rules/sonarjs/no-duplicate-test-title.md): Test titles should be unique within the same suite
- [sonarjs/no-debug-commands-in-ui-tests](https://lintradar.dev/rules/sonarjs/no-debug-commands-in-ui-tests.md): UI test debug commands should not be committed to version control
- [sonarjs/no-duplicated-branches](https://lintradar.dev/rules/sonarjs/no-duplicated-branches.md): Two branches in a conditional structure should not have exactly the same implementation

---

Web page: https://lintradar.dev/rules/sonarjs/no-duplicate-in-composite. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
