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

refactor: avoid duplicated exitFunctions map (#1145)

This commit is contained in:
Oleksandr Redko
2024-11-28 09:47:10 +02:00
committed by GitHub
parent d2778f36f1
commit 777abc9c35
4 changed files with 56 additions and 34 deletions

View File

@@ -152,19 +152,6 @@ func (w *lintUnconditionalRecursionRule) updateFuncStatus(node ast.Node) {
w.currentFunc.seenConditionalExit = w.hasControlExit(node)
}
var exitFunctions = map[string]map[string]bool{
"os": {"Exit": true},
"syscall": {"Exit": true},
"log": {
"Fatal": true,
"Fatalf": true,
"Fatalln": true,
"Panic": true,
"Panicf": true,
"Panicln": true,
},
}
func (lintUnconditionalRecursionRule) hasControlExit(node ast.Node) bool {
// isExit returns true if the given node makes control exit the function
isExit := func(node ast.Node) bool {
@@ -187,8 +174,7 @@ func (lintUnconditionalRecursionRule) hasControlExit(node ast.Node) bool {
functionName := se.Sel.Name
pkgName := id.Name
isCallToExitFunction := exitFunctions[pkgName] != nil && exitFunctions[pkgName][functionName]
if isCallToExitFunction {
if isCallToExitFunction(pkgName, functionName) {
return true
}
}