1
0
mirror of https://github.com/mgechev/revive.git synced 2025-11-23 22:04:49 +02:00

feature(deep-exit): detect exit-triggering flag usage (#1544)

This commit is contained in:
Godsgift Uloamaka Ebite
2025-10-23 15:17:59 +01:00
committed by GitHub
parent d32d4a008f
commit 1bc57ac6f3
7 changed files with 90 additions and 29 deletions

13
testdata/deep_exit.go vendored
View File

@@ -1,6 +1,7 @@
package fixtures
import (
"flag"
"log"
"os"
"syscall"
@@ -36,3 +37,15 @@ func TestMain(m *testing.M) {
// must match because this is not a test file
os.Exit(m.Run()) // MATCH /calls to os.Exit only in main() or init() functions/
}
func flagParseOutsideMain() {
flag.Parse() // MATCH /calls to flag.Parse only in main() or init() functions/
}
func flagNewFlagSetExitOnErrorOutsideMain() {
flag.NewFlagSet("cmd", flag.ExitOnError) // MATCH /calls to flag.NewFlagSet with flag.ExitOnError only in main() or init() functions/
}
func flagNewFlagSetContinueOnErrorOK() {
flag.NewFlagSet("cmd", flag.ContinueOnError)
}