Skip to content

Commit

Permalink
refactor: fix golangci
Browse files Browse the repository at this point in the history
jdkato committed Dec 22, 2024
1 parent ccf35b9 commit 4a2d94f
Showing 2 changed files with 25 additions and 5 deletions.
20 changes: 20 additions & 0 deletions internal/core/util.go
Original file line number Diff line number Diff line change
@@ -7,7 +7,9 @@ import (
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strings"
"syscall"
"unicode"

"github.com/errata-ai/vale/v3/internal/nlp"
@@ -329,3 +331,21 @@ func ReplaceExt(fp string, formats map[string]string) string {

return fp
}

// FindProcess checks if a process with the given PID exists.
func FindProcess(pid int) *os.Process {
if pid <= 0 {
return nil
}

p, err := os.FindProcess(pid)
if runtime.GOOS != "windows" {
err = p.Signal(os.Signal(syscall.Signal(0)))
}

if err != nil {
return nil
}

return p
}
10 changes: 5 additions & 5 deletions internal/lint/lint.go
Original file line number Diff line number Diff line change
@@ -343,16 +343,16 @@ func (l *Linter) setup() error {

func (l *Linter) teardown() error {
for _, pid := range l.pids {
if p, err := os.FindProcess(pid); err == nil {
if err := p.Kill(); err != nil {
return err
if p := core.FindProcess(pid); p != nil {
if procErr := p.Kill(); procErr != nil {
return procErr
}
}
}

for _, f := range l.temps {
if err := os.Remove(f.Name()); err != nil {
return err
if ferr := os.Remove(f.Name()); ferr != nil {
return ferr
}
}

0 comments on commit 4a2d94f

Please sign in to comment.