8000 Make error checking more laxed by bombsimon · Pull Request #184 · bombsimon/wsl · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Make error check 8000 ing more laxed #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2025
Merged

Make error checking more laxed #184

merged 1 commit into from
Jul 2, 2025

Conversation

bombsimon
Copy link
Owner
@bombsimon bombsimon commented Jul 1, 2025

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

if err != nil {}

if err == nil {}

Nothing else should trigger this lint, all of these should be left

// 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 which has this rule:

No empty lines before a simple error check

foo, err := processFoo()

if err != nil {
	return err
}
foo, err := processFoo()
if err != nil {
	return err
}

Solves #183

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
> }
> ```
@coveralls
Copy link

Coverage Status

coverage: 93.837% (-0.6%) from 94.44%
when pulling 0535abb on lax-error-checking
into 628ebb7 on main.

@bombsimon bombsimon merged commit ebb08fc into main Jul 2, 2025
4 checks passed
@bombsimon bombsimon deleted the lax-error-checking branch July 2, 2025 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0