Skip to content

Commit

Permalink
feat(eslint-plugin): Add unified-signature rule (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
armanio123 authored and JamesHenry committed Mar 20, 2019
1 parent 0ef07c4 commit 6ffaa0b
Show file tree
Hide file tree
Showing 7 changed files with 1,234 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/eslint-plugin/README.md
Expand Up @@ -152,5 +152,6 @@ Then you should add `airbnb` (or `airbnb-base`) to your `extends` section of `.e
| [`@typescript-eslint/promise-function-async`](./docs/rules/promise-function-async.md) | Requires any function or method that returns a Promise to be marked async. (`promise-function-async` from TSLint) | :heavy_check_mark: | |
| [`@typescript-eslint/restrict-plus-operands`](./docs/rules/restrict-plus-operands.md) | When adding two variables, operands must both be of type number or of type string. (`restrict-plus-operands` from TSLint) | | |
| [`@typescript-eslint/type-annotation-spacing`](./docs/rules/type-annotation-spacing.md) | Require consistent spacing around type annotations (`typedef-whitespace` from TSLint) | :heavy_check_mark: | :wrench: |
| [`@typescript-eslint/unified-signatures`](./docs/rules/unified-signatures.md) | Warns for any two overloads that could be unified into one. (`unified-signatures` from TSLint) | | |

<!-- end rule list -->
3 changes: 2 additions & 1 deletion packages/eslint-plugin/ROADMAP.md
Expand Up @@ -34,7 +34,7 @@
| [`promise-function-async`] || [`@typescript-eslint/promise-function-async`] |
| [`typedef`] | 🛑 | N/A |
| [`typedef-whitespace`] || [`@typescript-eslint/type-annotation-spacing`] |
| [`unified-signatures`] | 🛑 | N/A |
| [`unified-signatures`] | | [`@typescript-eslint/unified-signatures`] |

### Functionality

Expand Down Expand Up @@ -589,6 +589,7 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint-
[`@typescript-eslint/no-unnecessary-type-assertion`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md
[`@typescript-eslint/no-var-requires`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-var-requires.md
[`@typescript-eslint/type-annotation-spacing`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/type-annotation-spacing.md
[`@typescript-eslint/unified-signatures`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/unified-signatures.md
[`@typescript-eslint/no-misused-new`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-misused-new.md
[`@typescript-eslint/no-object-literal-type-assertion`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-object-literal-type-assertion.md
[`@typescript-eslint/no-this-alias`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-this-alias.md
Expand Down
33 changes: 33 additions & 0 deletions packages/eslint-plugin/docs/rules/unified-signatures.md
@@ -0,0 +1,33 @@
# Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter. (unified-signatures)

Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter.

## Rule Details

This rule aims to keep the source code as maintanable as posible by reducing the amount of overloads.

Examples of **incorrect** code for this rule:

```ts
function f(x: number): void;
function f(x: string): void;
```

```ts
f(): void;
f(...x: number[]): void;
```

Examples of **correct** code for this rule:

```ts
function f(x: number | string): void;
```

```ts
function f(x?: ...number[]): void;
```

## Related to

- TSLint: ['unified-signatures`](https://palantir.github.io/tslint/rules/unified-signatures/)

0 comments on commit 6ffaa0b

Please sign in to comment.