facebook / facebook/flow

Feature request: No contradicting checks

Open
#5,299 1 comment 1 reaction 0 assignees View on GitHub
feature request
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

I reported this already to [eslint-plugin-flow ](https://github.com/gajus/eslint-plugin-flowtype/issues/286), but I started to think that Flow core would be correct home for this feature, especially as it's so similar to what 0.58.0 introduced for switch case statements

Some times, especially when defining flow types afterwards the code gets dirty and unnecessary checks are left in place. For example:

```
function myFunc(num?: number): number {
if (num === undefined) {
return 1;
}
return num;
}
```

let's say we modify the code so that the function parameters are required and checked elsewehere:

```
function myFunc(num: number): number {
if (num === undefined) {
return 1;
}
return num;
}
```

Now we are left with unnecessary check. What we really want is to get rid of the check too:

```
function myFunc(num: number): number {
return num;
}
```

However, the check is easily forgotten there as no linter or Flow nags about it.

Having unnecessary checks makes code more error prone, harder to understand and is against the purpose of static typing. Would be good to have a rule against this.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.