Skip to content

Commit

Permalink
fix(golangcilint): use one config file
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Mar 11, 2024
1 parent 714a2b0 commit 8533d91
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 66 deletions.
48 changes: 0 additions & 48 deletions tools/sggolangcilint/golangci.fix.yml

This file was deleted.

1 change: 0 additions & 1 deletion tools/sggolangcilint/golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
run:
timeout: 10m
allow-parallel-runners: true
skip-dirs:
- node_modules

Expand Down
20 changes: 3 additions & 17 deletions tools/sggolangcilint/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ const (
//go:embed golangci.yml
var DefaultConfig []byte

//go:embed golangci.fix.yml
var defaultFixConfig []byte

func Command(ctx context.Context, args ...string) *exec.Cmd {
sg.Deps(ctx, PrepareCommand)
return sg.Command(ctx, sg.FromBinDir(name), args...)
Expand All @@ -35,10 +32,6 @@ func defaultConfigPath() string {
return sg.FromToolsDir(name, ".golangci.yml")
}

func defaultFixConfigPath() string {
return sg.FromToolsDir(name, ".golangci.fix.yml")
}

func CommandInDirectory(ctx context.Context, directory string, args ...string) *exec.Cmd {
configPath := filepath.Join(directory, ".golangci.yml")
if _, err := os.Lstat(configPath); errors.Is(err, os.ErrNotExist) {
Expand All @@ -48,7 +41,7 @@ func CommandInDirectory(ctx context.Context, directory string, args ...string) *
if directory == sg.FromSageDir() {
excludeArg = append(excludeArg, "--exclude", "(is a global variable|is unused)")
}
cmdArgs := append([]string{"run", "-c", configPath}, args...)
cmdArgs := append([]string{"run", "--allow-parallel-runners", "-c", configPath}, args...)
cmd := Command(ctx, append(cmdArgs, excludeArg...)...)
cmd.Dir = directory
return cmd
Expand Down Expand Up @@ -88,7 +81,7 @@ func Fix(ctx context.Context, args ...string) error {
if d.IsDir() || d.Name() != "go.mod" {
return nil
}
cmd := Command(ctx, append([]string{"run", "-c", defaultFixConfigPath(), "--fix"}, args...)...)
cmd := Command(ctx, append([]string{"run", "--allow-serial-runners", "-c", defaultConfigPath(), "--fix"}, args...)...)
cmd.Dir = filepath.Dir(path)
commands = append(commands, cmd)
return cmd.Start()
Expand Down Expand Up @@ -130,12 +123,5 @@ func PrepareCommand(ctx context.Context) error {
if err := os.MkdirAll(filepath.Dir(configPath), 0o755); err != nil {
return err
}
if err := os.WriteFile(configPath, DefaultConfig, 0o600); err != nil {
return err
}
fixConfigPath := defaultFixConfigPath()
if err := os.MkdirAll(filepath.Dir(fixConfigPath), 0o755); err != nil {
return err
}
return os.WriteFile(fixConfigPath, defaultFixConfig, 0o600)
return os.WriteFile(configPath, DefaultConfig, 0o600)
}

0 comments on commit 8533d91

Please sign in to comment.