1
0
mirror of https://github.com/mgechev/revive.git synced 2024-11-24 08:32:22 +02:00
Commit Graph

10 Commits

Author SHA1 Message Date
Mario Valderrama
55585666b7 Prevent empty-block when looping over call expr 2023-05-01 10:44:48 +02:00
Abhinav Gupta
b03e54f617
empty-block: Fix false positive on select {} (#805)
This fixes a false positive reported by revive on the following:

    select {}

This is a way to block the program indefinitely.
It is used in cases like:

- Running a long-running server in a background thread
  and blocking `main` from exiting until the application dies.
  This is something you might do if your process has
  multiple servers/listeners in the same process.

  ```go
  go grpcListenAndServe()
  go httpListenAndServe()
  go logFlusher()

  select {}
  ```

- In programs compiled to WASM to prevent the application from exiting,
  so that the Javascript components may interact with it.

  ```go
  func main() {
    js.Global().Set("foo", foo)
    select {}
  }
  ```

  Without this, one may see an error like,
  "Error: Go program has already exited"

As a workaround, these programs can block forever
by receiving from a throwaway channel (`<-make(chan struct{})`),
but `select {}` is still a completely valid way of doing this,
so supporting it makes sense.

The issue was previously reported in #698 but was closed
because the author was satisfied with a `//nolint` comment.

Now that this rule is part of the default rule set (#799)
the case for addressing the false positive is stronger.

Resolves #804
2023-03-16 13:39:52 -07:00
chavacava
04728cf0de
Lint cleanup (#679) 2022-04-10 11:55:13 +02:00
sina safari
0bcc996acf
fixed some complex code (#580) 2021-09-26 08:28:58 +02:00
chavacava
e9bdc9ed8f removes type-checking from empty-block rule 2020-05-20 12:05:56 -07:00
SalvadorC
1da965b65f
fix issue 386: Incorrectly identifies channel draining as "empty code… (#415)
* fix issue 386: Incorrectly identifies channel draining as "empty code block"

* updates doc of empty-block rule
2020-05-10 17:43:56 -07:00
mgechev
376425d517
refactor: remove URL field from the failure struct 2018-10-30 15:37:27 -07:00
SalvadorC
388baa3eeb Fix linter warnings (recommended config) in the code (#71) 2018-09-22 15:27:22 -07:00
chavacava
c9bde6c503 empty-block: ignore checking blocks of funcs and func literals (#17)
* Adds rule superfluous-else (an extension of indent-error-flow)

* Fix superfluous-else rule struct namming.

* Adds superfuous-else rule to the rules table

* Modifies empty-block rule to ignore bodies of
func literals and funcs

* add test cases on functions with a receiver for completeness
2018-06-11 12:08:58 -07:00
chavacava
1fa5046357 Adds new rule empty-block (#14)
* Adds rule superfluous-else (an extension of indent-error-flow)

* initial (non functional) version

* empty-block working version

* adds tests for empty-block rule

* Adds empty-block to the rules table

* code clean-up
2018-06-08 12:41:49 -07:00