Skip to content

Commit 67596e8

Browse files
committed
feat: change Builder interface to return error
1 parent e537313 commit 67596e8

File tree

6 files changed

+27
-23
lines changed

6 files changed

+27
-23
lines changed

.golangci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ linters-settings:
3333
- whyNoLint
3434
gocyclo:
3535
min-complexity: 15
36+
godox:
37+
keywords:
38+
- FIXME
3639
gofmt:
3740
rewrite-rules:
3841
- pattern: 'interface{}'
@@ -96,6 +99,7 @@ linters:
9699
- goconst
97100
- gocritic
98101
- gocyclo
102+
- godox
99103
- gofmt
100104
- goimports
101105
- gomnd
@@ -123,7 +127,6 @@ linters:
123127
# - gochecknoglobals
124128
# - gocognit
125129
# - godot
126-
# - godox
127130
# - goerr113
128131
# - nestif
129132
# - prealloc

pkg/commands/internal/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (b Builder) clone(ctx context.Context) error {
8888
cmd := exec.CommandContext(ctx,
8989
"git", "clone", "--branch", b.cfg.Version,
9090
"--single-branch", "--depth", "1", "-c advice.detachedHead=false", "-q",
91-
"https://github.com/ldez/golangci-lint.git", // FIXME(ldez) use https://github.com/golangci/golangci-lint.git
91+
"https://github.com/golangci/golangci-lint.git",
9292
)
9393
cmd.Dir = b.root
9494

pkg/lint/lintersdb/builder_linter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ func NewLinterBuilder() *LinterBuilder {
1616

1717
// Build loads all the "internal" linters.
1818
// The configuration is use for the linter settings.
19-
func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config {
19+
func (b LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
2020
if cfg == nil {
21-
return nil
21+
return nil, nil
2222
}
2323

2424
const megacheckName = "megacheck"
@@ -707,5 +707,5 @@ func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config {
707707
WithSince("v1.26.0").
708708
WithPresets(linter.PresetStyle).
709709
WithURL("https://github.com/golangci/golangci-lint/blob/master/pkg/golinters/nolintlint/README.md"),
710-
}
710+
}, nil
711711
}

pkg/lint/lintersdb/builder_plugin_go.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ func NewPluginGoBuilder(log logutils.Log) *PluginGoBuilder {
2929
}
3030

3131
// Build loads custom linters that are specified in the golangci-lint config file.
32-
func (b *PluginGoBuilder) Build(cfg *config.Config) []*linter.Config {
32+
func (b *PluginGoBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
3333
if cfg == nil || b.log == nil {
34-
return nil
34+
return nil, nil
3535
}
3636

3737
var linters []*linter.Config
@@ -40,13 +40,13 @@ func (b *PluginGoBuilder) Build(cfg *config.Config) []*linter.Config {
4040
settings := settings
4141
lc, err := b.loadConfig(cfg, name, &settings)
4242
if err != nil {
43-
b.log.Errorf("Unable to load custom analyzer %s:%s, %v", name, settings.Path, err)
43+
return nil, fmt.Errorf("unable to load custom analyzer %s:%s, %w", name, settings.Path, err)
4444
} else {
4545
linters = append(linters, lc)
4646
}
4747
}
4848

49-
return linters
49+
return linters, nil
5050
}
5151

5252
// loadConfig loads the configuration of private linters.

pkg/lint/lintersdb/builder_plugin_module.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package lintersdb
22

33
import (
4+
"fmt"
45
"strings"
56

67
"github.com/golangci/plugin-module-register/register"
@@ -24,9 +25,9 @@ func NewPluginModuleBuilder(log logutils.Log) *PluginModuleBuilder {
2425
}
2526

2627
// Build loads custom linters that are specified in the golangci-lint config file.
27-
func (b *PluginModuleBuilder) Build(cfg *config.Config) []*linter.Config {
28+
func (b *PluginModuleBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
2829
if cfg == nil || b.log == nil {
29-
return nil
30+
return nil, nil
3031
}
3132

3233
var linters []*linter.Config
@@ -40,23 +41,17 @@ func (b *PluginModuleBuilder) Build(cfg *config.Config) []*linter.Config {
4041

4142
newPlugin, err := register.GetPlugin(name)
4243
if err != nil {
43-
// FIXME error
44-
b.log.Fatalf("plugin(%s): %v", name, err)
45-
return nil
44+
return nil, fmt.Errorf("plugin(%s): %w", name, err)
4645
}
4746

4847
p, err := newPlugin(settings.Settings)
4948
if err != nil {
50-
// FIXME error
51-
b.log.Fatalf("plugin(%s): newPlugin %v", name, err)
52-
return nil
49+
return nil, fmt.Errorf("plugin(%s): newPlugin %w", name, err)
5350
}
5451

5552
analyzers, err := p.BuildAnalyzers()
5653
if err != nil {
57-
// FIXME error
58-
b.log.Fatalf("plugin(%s): BuildAnalyzers %v", name, err)
59-
return nil
54+
return nil, fmt.Errorf("plugin(%s): BuildAnalyzers %w", name, err)
6055
}
6156

6257
customLinter := goanalysis.NewLinter(name, settings.Description, analyzers, nil)
@@ -86,5 +81,5 @@ func (b *PluginModuleBuilder) Build(cfg *config.Config) []*linter.Config {
8681
linters = append(linters, lc)
8782
}
8883

89-
return linters
84+
return linters, nil
9085
}

pkg/lint/lintersdb/manager.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package lintersdb
22

33
import (
4+
"fmt"
45
"os"
56
"slices"
67
"sort"
@@ -17,7 +18,7 @@ import (
1718
const EnvTestRun = "GL_TEST_RUN"
1819

1920
type Builder interface {
20-
Build(cfg *config.Config) []*linter.Config
21+
Build(cfg *config.Config) ([]*linter.Config, error)
2122
}
2223

2324
// Manager is a type of database for all linters (internals or plugins).
@@ -48,7 +49,12 @@ func NewManager(log logutils.Log, cfg *config.Config, builders ...Builder) (*Man
4849
}
4950

5051
for _, builder := range builders {
51-
m.linters = append(m.linters, builder.Build(m.cfg)...)
52+
linters, err := builder.Build(m.cfg)
53+
if err != nil {
54+
return nil, fmt.Errorf("build linters: %w", err)
55+
}
56+
57+
m.linters = append(m.linters, linters...)
5258
}
5359

5460
for _, lc := range m.linters {

0 commit comments

Comments
 (0)