Skip to content

Commit

Permalink
chore(eslint-plugin): add more comments to example code
Browse files Browse the repository at this point in the history
  • Loading branch information
Retsam committed Sep 6, 2019
1 parent 2d6e759 commit 36d5f5c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/eslint-plugin/docs/rules/no-unnecessary-condition.md
Expand Up @@ -11,28 +11,33 @@ Examples of **incorrect** code for this rule:

```ts
function head<T>(items: T[]) {
// items can never be nullable, so this is unnecessary
if (items) {
return items[0].toUpperCase();
}
}

const foo = 'foo';
if (foo) {
function foo(arg: 'bar' | 'baz') {
// arg is never nullable or empty string, so this is unnecessary
if (arg) {
}
}
```

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

```ts
function head<T>(items: T[]) {
// Necessary, since items.length might be 0
if (items.length) {
return items[0].toUpperCase();
}
}

declare const foo: string;
// Necessary, since foo might be ''. (If undesired, consider using `strict-boolean-expressions` rule)
if (foo) {
function foo(arg: 'bar' | 'baz') {
// Necessary, since foo might be ''.
if (arg) {
}
}
```

Expand Down

0 comments on commit 36d5f5c

Please sign in to comment.