lint: disallow naked returns (#2771)

This commit is contained in:
mmetc 2024-01-24 17:31:34 +01:00 committed by GitHub
parent f75cdeb239
commit 8c75efdb2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 12 deletions

View file

@ -306,11 +306,6 @@ issues:
- nonamedreturns - nonamedreturns
text: "named return .* with type .* found" text: "named return .* with type .* found"
# https://github.com/alexkohler/nakedret#purpose
- linters:
- nakedret
text: "naked return in func .* with .* lines of code"
# #
# Will fix, might be trickier # Will fix, might be trickier
# #

View file

@ -41,7 +41,7 @@ func copyFileContents(src, dst string) (err error) {
} }
/*copy the file, ioutile doesn't offer the feature*/ /*copy the file, ioutile doesn't offer the feature*/
func CopyFile(sourceSymLink, destinationFile string) (err error) { func CopyFile(sourceSymLink, destinationFile string) error {
sourceFile, err := filepath.EvalSymlinks(sourceSymLink) sourceFile, err := filepath.EvalSymlinks(sourceSymLink)
if err != nil { if err != nil {
log.Infof("Not a symlink : %s", err) log.Infof("Not a symlink : %s", err)
@ -51,7 +51,7 @@ func CopyFile(sourceSymLink, destinationFile string) (err error) {
sourceFileStat, err := os.Stat(sourceFile) sourceFileStat, err := os.Stat(sourceFile)
if err != nil { if err != nil {
return return err
} }
if !sourceFileStat.Mode().IsRegular() { if !sourceFileStat.Mode().IsRegular() {
@ -63,14 +63,14 @@ func CopyFile(sourceSymLink, destinationFile string) (err error) {
destinationFileStat, err := os.Stat(destinationFile) destinationFileStat, err := os.Stat(destinationFile)
if err != nil { if err != nil {
if !os.IsNotExist(err) { if !os.IsNotExist(err) {
return return err
} }
} else { } else {
if !(destinationFileStat.Mode().IsRegular()) { if !(destinationFileStat.Mode().IsRegular()) {
return fmt.Errorf("copyFile: non-regular destination file %s (%q)", destinationFileStat.Name(), destinationFileStat.Mode().String()) return fmt.Errorf("copyFile: non-regular destination file %s (%q)", destinationFileStat.Name(), destinationFileStat.Mode().String())
} }
if os.SameFile(sourceFileStat, destinationFileStat) { if os.SameFile(sourceFileStat, destinationFileStat) {
return return err
} }
} }
@ -78,6 +78,6 @@ func CopyFile(sourceSymLink, destinationFile string) (err error) {
err = copyFileContents(sourceFile, destinationFile) err = copyFileContents(sourceFile, destinationFile)
} }
return return err
} }

View file

@ -23,7 +23,7 @@ type crowdsec_winservice struct {
config *csconfig.Config config *csconfig.Config
} }
func (m *crowdsec_winservice) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) { func (m *crowdsec_winservice) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (bool, uint32) {
const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown
changes <- svc.Status{State: svc.StartPending} changes <- svc.Status{State: svc.StartPending}
tick := time.Tick(500 * time.Millisecond) tick := time.Tick(500 * time.Millisecond)
@ -59,7 +59,8 @@ func (m *crowdsec_winservice) Execute(args []string, r <-chan svc.ChangeRequest,
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
return
return false, 0
} }
func runService(name string) error { func runService(name string) error {