Skip to content

Commit ac10e4a

Browse files
committed
review
1 parent 7748b59 commit ac10e4a

File tree

7 files changed

+58
-74
lines changed

7 files changed

+58
-74
lines changed

pkg/config/loader.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,8 @@ func (l *Loader) Load(opts LoadOptions) error {
6969
l.applyStringSliceHack()
7070

7171
if l.cfg.Linters.LinterExclusions.Generated == "" {
72-
// This is always non-empty because of the flag default value.
73-
if l.cfg.Issues.ExcludeGenerated != "" {
74-
l.cfg.Linters.LinterExclusions.Generated = l.cfg.Issues.ExcludeGenerated
75-
} else {
76-
l.cfg.Linters.LinterExclusions.Generated = "strict"
77-
}
72+
// `l.cfg.Issues.ExcludeGenerated` is always non-empty because of the flag default value.
73+
l.cfg.Linters.LinterExclusions.Generated = cmp.Or(l.cfg.Issues.ExcludeGenerated, "strict")
7874
}
7975

8076
if l.cfg.Issues.UseDefaultExcludes {

pkg/golinters/gocritic/testdata/gocritic.yml

-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ linters-settings:
1111
sizeThreshold: 24
1212
ruleguard:
1313
failOn: dsl,import
14-
# Comma-separated paths to ruleguard files.
15-
# The ${configDir} is substituted by the directory containing the golangci-lint config file.
16-
# Note about the directory structure for functional tests:
17-
# The ruleguard files used in functional tests cannot be under the 'testdata' directory.
18-
# This is because they import the 'github.com/quasilyte/go-ruleguard/dsl' package,
19-
# which needs to be added to go.mod. The testdata directory is ignored by go mod.
2014
rules: '${base-path}/ruleguard/preferWriteString.go,${base-path}/ruleguard/stringsSimplify.go'
2115

2216
run:

pkg/golinters/gocritic/testdata/gocritic_configDir.yml

-6
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,4 @@ linters-settings:
1111
sizeThreshold: 24
1212
ruleguard:
1313
failOn: dsl,import
14-
# Comma-separated paths to ruleguard files.
15-
# The ${configDir} is substituted by the directory containing the golangci-lint config file.
16-
# Note about the directory structure for functional tests:
17-
# The ruleguard files used in functional tests cannot be under the 'testdata' directory.
18-
# This is because they import the 'github.com/quasilyte/go-ruleguard/dsl' package,
19-
# which needs to be added to go.mod. The testdata directory is ignored by go mod.
2014
rules: '${configDir}/ruleguard/preferWriteString.go,${configDir}/ruleguard/stringsSimplify.go'

pkg/golinters/internal/commons.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var LinterLogger = logutils.NewStderrLog(logutils.DebugKeyLinter)
99
const (
1010
PlaceholderBasePath = "${base-path}"
1111
// Deprecated: it must be removed in v2.
12-
// [PlaceholderBasePath] will be the only one placeholder as it is a dynamic value base on
12+
// [PlaceholderBasePath] will be the only one placeholder as it is a dynamic value based on
1313
// [github.com/golangci/golangci-lint/pkg/config.Run.RelativePathMode].
1414
PlaceholderConfigDir = "${configDir}"
1515
)

pkg/result/processors/exclusion_rules.go

+47-47
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,6 @@ import (
1414

1515
var _ Processor = (*ExclusionRules)(nil)
1616

17-
type excludeRule struct {
18-
baseRule
19-
}
20-
21-
func (e excludeRule) String() string {
22-
var msg []string
23-
24-
if e.text != nil && e.text.String() != "" {
25-
msg = append(msg, fmt.Sprintf("Text: %q", e.text))
26-
}
27-
28-
if e.source != nil && e.source.String() != "" {
29-
msg = append(msg, fmt.Sprintf("Source: %q", e.source))
30-
}
31-
32-
if e.path != nil && e.path.String() != "" {
33-
msg = append(msg, fmt.Sprintf("Path: %q", e.path))
34-
}
35-
36-
if e.pathExcept != nil && e.pathExcept.String() != "" {
37-
msg = append(msg, fmt.Sprintf("Path Except: %q", e.pathExcept))
38-
}
39-
40-
if len(e.linters) > 0 {
41-
msg = append(msg, fmt.Sprintf("Linters: %q", strings.Join(e.linters, ", ")))
42-
}
43-
44-
return strings.Join(msg, ", ")
45-
}
46-
4717
type ExclusionRules struct {
4818
log logutils.Log
4919
files *fsutils.Files
@@ -68,18 +38,18 @@ func NewExclusionRules(log logutils.Log, files *fsutils.Files, cfg *config.Linte
6838
prefix = ""
6939
}
7040

71-
excludeRules := slices.Clone(cfg.Rules)
72-
excludeRules = append(excludeRules, filterInclude(getDefaultLintersExclusions(cfg.Default), oldCfg.IncludeDefaultExcludes)...)
41+
excludeRules := slices.Concat(slices.Clone(cfg.Rules),
42+
filterInclude(getDefaultLintersExclusions(cfg.Default), oldCfg.IncludeDefaultExcludes))
7343

74-
p.rules = createRules(excludeRules, prefix)
44+
p.rules = createExcludeRules(excludeRules, prefix)
7545

7646
// TODO(ldez): should be removed in v2.
7747
for _, pattern := range oldCfg.ExcludePatterns {
7848
if pattern == "" {
7949
continue
8050
}
8151

82-
rule := createRule(&config.ExcludeRule{
52+
rule := newRule(&config.ExcludeRule{
8353
BaseRule: config.BaseRule{
8454
Path: `.+\.go`,
8555
Text: pattern,
@@ -135,21 +105,11 @@ func (p *ExclusionRules) Finish() {
135105
}
136106
}
137107

138-
func createRules(rules []config.ExcludeRule, prefix string) []excludeRule {
139-
if len(rules) == 0 {
140-
return nil
141-
}
142-
143-
parsedRules := make([]excludeRule, 0, len(rules))
144-
145-
for _, rule := range rules {
146-
parsedRules = append(parsedRules, createRule(&rule, prefix))
147-
}
148-
149-
return parsedRules
108+
type excludeRule struct {
109+
baseRule
150110
}
151111

152-
func createRule(rule *config.ExcludeRule, prefix string) excludeRule {
112+
func newRule(rule *config.ExcludeRule, prefix string) excludeRule {
153113
parsedRule := excludeRule{}
154114
parsedRule.linters = rule.Linters
155115
parsedRule.internalReference = rule.InternalReference
@@ -173,6 +133,46 @@ func createRule(rule *config.ExcludeRule, prefix string) excludeRule {
173133
return parsedRule
174134
}
175135

136+
func (e excludeRule) String() string {
137+
var msg []string
138+
139+
if e.text != nil && e.text.String() != "" {
140+
msg = append(msg, fmt.Sprintf("Text: %q", e.text))
141+
}
142+
143+
if e.source != nil && e.source.String() != "" {
144+
msg = append(msg, fmt.Sprintf("Source: %q", e.source))
145+
}
146+
147+
if e.path != nil && e.path.String() != "" {
148+
msg = append(msg, fmt.Sprintf("Path: %q", e.path))
149+
}
150+
151+
if e.pathExcept != nil && e.pathExcept.String() != "" {
152+
msg = append(msg, fmt.Sprintf("Path Except: %q", e.pathExcept))
153+
}
154+
155+
if len(e.linters) > 0 {
156+
msg = append(msg, fmt.Sprintf("Linters: %q", strings.Join(e.linters, ", ")))
157+
}
158+
159+
return strings.Join(msg, ", ")
160+
}
161+
162+
func createExcludeRules(rules []config.ExcludeRule, prefix string) []excludeRule {
163+
if len(rules) == 0 {
164+
return nil
165+
}
166+
167+
parsedRules := make([]excludeRule, 0, len(rules))
168+
169+
for _, rule := range rules {
170+
parsedRules = append(parsedRules, newRule(&rule, prefix))
171+
}
172+
173+
return parsedRules
174+
}
175+
176176
// TODO(ldez): must be removed in v2, only for compatibility with exclude-use-default/include.
177177
func filterInclude(rules []config.ExcludeRule, refs []string) []config.ExcludeRule {
178178
if len(refs) == 0 {

pkg/result/processors/path_relativity.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
var _ Processor = (*PathRelativity)(nil)
1313

14-
// PathRelativity computes [result.Issue.RelativePath] and [result.Issue.WorkingDirectoryRelativePath],
14+
// PathRelativity computes [result.Issue.RelativePath] and [result.Issue.WorkingDirectoryRelativePath],
1515
// based on the base path.
1616
type PathRelativity struct {
1717
log logutils.Log
@@ -34,22 +34,22 @@ func NewPathRelativity(log logutils.Log, basePath string) (*PathRelativity, erro
3434

3535
func (p *PathRelativity) Process(issues []result.Issue) ([]result.Issue, error) {
3636
return transformIssues(issues, func(issue *result.Issue) *result.Issue {
37-
newIssue := issue
37+
newIssue := *issue
3838

3939
var err error
4040
newIssue.RelativePath, err = filepath.Rel(p.basePath, issue.FilePath())
4141
if err != nil {
42-
p.log.Warnf("relative path (basepath): %v", err)
42+
p.log.Warnf("Getting relative path (basepath): %v", err)
4343
return nil
4444
}
4545

4646
newIssue.WorkingDirectoryRelativePath, err = filepath.Rel(p.wd, issue.FilePath())
4747
if err != nil {
48-
p.log.Warnf("relative path (wd): %v", err)
48+
p.log.Warnf("Getting relative path (wd): %v", err)
4949
return nil
5050
}
5151

52-
return newIssue
52+
return &newIssue
5353
}), nil
5454
}
5555

pkg/result/processors/uniq_by_line.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ var _ Processor = (*UniqByLine)(nil)
1111
// UniqByLine filters reports to keep only one report by line of code.
1212
type UniqByLine struct {
1313
fileLineCounter fileLineCounter
14-
enable bool
14+
enabled bool
1515
}
1616

1717
func NewUniqByLine(enable bool) *UniqByLine {
1818
return &UniqByLine{
1919
fileLineCounter: fileLineCounter{},
20-
enable: enable,
20+
enabled: enable,
2121
}
2222
}
2323

@@ -26,7 +26,7 @@ func (*UniqByLine) Name() string {
2626
}
2727

2828
func (p *UniqByLine) Process(issues []result.Issue) ([]result.Issue, error) {
29-
if !p.enable {
29+
if !p.enabled {
3030
return issues, nil
3131
}
3232

0 commit comments

Comments
 (0)