Commit ebb08fc
authored
Make error checking more laxed (#184)
Only perform error checking when there's a single comparison with a
binary operator comparing an error with `nil`. Both `!=` and `==` are
candidates for cuddling.
These should be cuddled if `err` exist on the line above
```go
if err != nil {}
if err == nil {}
```
Nothing else should trigger this lint, all of these should be left
```go
// More than error checking
if err != nil || true {}
// Technically an error checking, but we only check for binary
// operators, not expressions.
if errors.Is(err, SomeErr) {}
// More than one error checking
if err != nil || err2 != nil {}
```
This also matches [`gofumpt`](https://github.com/mvdan/gofumpt) which
has this rule:
> No empty lines before a simple error check
>
> ```go
> foo, err := processFoo()
>
> if err != nil {
> return err
> }
> ```
>
> ```go
> foo, err := processFoo()
> if err != nil {
> return err
> }
> ```1 parent 628ebb7 commit ebb08fc
3 files changed
+56
-28
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
11 | 17 | | |
12 | 18 | | |
13 | 19 | | |
| |||
105 | 111 | | |
106 | 112 | | |
107 | 113 | | |
108 | | - | |
| 114 | + | |
| 115 | + | |
109 | 116 | | |
110 | | - | |
111 | | - | |
| 117 | + | |
| 118 | + | |
112 | 119 | | |
113 | 120 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
10 | 15 | | |
11 | 16 | | |
12 | 17 | | |
| |||
103 | 108 | | |
104 | 109 | | |
105 | 110 | | |
106 | | - | |
107 | | - | |
108 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
109 | 116 | | |
110 | 117 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
| |||
540 | 539 | | |
541 | 540 | | |
542 | 541 | | |
543 | | - | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
544 | 576 | | |
545 | 577 | | |
546 | 578 | | |
| |||
559 | 591 | | |
560 | 592 | | |
561 | 593 | | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | | - | |
573 | | - | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | | - | |
581 | | - | |
| 594 | + | |
| 595 | + | |
582 | 596 | | |
583 | 597 | | |
584 | 598 | | |
| |||
0 commit comments