Skip to content

Commit 5895172

Browse files
committed
Lint fixes
1 parent 5e06efe commit 5895172

File tree

16 files changed

+66
-89
lines changed

16 files changed

+66
-89
lines changed

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ linters:
3131
- third_party$
3232
- builtin$
3333
- examples$
34+
rules:
35+
- path: util
36+
text: 'var-naming: avoid meaningless package names'
37+
linters:
38+
- revive
3439
issues:
3540
fix: true
3641
formatters:

config/config.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,10 @@ func (c *Config) Prepare() error {
9898
c.SourceDir = c.CurrentDir
9999
}
100100

101-
//nolint:revive
102-
if absP, err := filepath.Abs(c.SourceDir); err != nil {
101+
var err error
102+
c.SourceDir, err = filepath.Abs(c.SourceDir)
103+
if err != nil {
103104
return err
104-
} else {
105-
c.SourceDir = absP
106105
}
107106

108107
if c.OutputFile != "" {
@@ -112,11 +111,9 @@ func (c *Config) Prepare() error {
112111
c.OutputFile = c.DefaultDomain + "." + c.ExtractFormat
113112
}
114113

115-
//nolint:revive
116-
if absP, err := filepath.Abs(c.OutputDir); err != nil {
114+
c.OutputDir, err = filepath.Abs(c.OutputDir)
115+
if err != nil {
117116
return err
118-
} else {
119-
c.OutputDir = absP
120117
}
121118

122119
if c.DontWrap {

extract/extractors/context.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func (c *Context) SearchStrings(startExpr ast.Expr) []*SearchResult {
225225
return results
226226
}
227227

228-
c.Inspector.WithStack([]ast.Node{&ast.AssignStmt{}}, func(raw ast.Node, push bool, stack []ast.Node) (proceed bool) {
228+
c.Inspector.WithStack([]ast.Node{&ast.AssignStmt{}}, func(raw ast.Node, _ bool, _ []ast.Node) (proceed bool) {
229229
proceed = false
230230

231231
node := raw.(*ast.AssignStmt)
@@ -275,7 +275,7 @@ func (c *Context) GetComments(pkg *packages.Package, nodes ...ast.Node) []string
275275
break
276276
}
277277

278-
c.Inspector.WithStack([]ast.Node{node}, func(n ast.Node, push bool, stack []ast.Node) (proceed bool) {
278+
c.Inspector.WithStack([]ast.Node{node}, func(n ast.Node, _ bool, stack []ast.Node) (proceed bool) {
279279
proceed = false
280280
// Search stack for our node
281281
if n != node {

goextractors/definition.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,21 @@ func (de *definitionExtractorRunner) extractStruct(decl *ast.GenDecl) {
140140
tok = de.extractCtx.GetLocalizeTypeToken(field.Type)
141141
break
142142
}
143-
if selector := searchSelector(field.Type); selector == nil {
143+
144+
selector := searchSelector(field.Type)
145+
if selector == nil {
144146
continue
145-
} else {
146-
tok = de.extractCtx.GetLocalizeTypeToken(selector)
147147
}
148+
149+
tok = de.extractCtx.GetLocalizeTypeToken(selector)
150+
148151
default:
149-
if selector := searchSelector(field.Type); selector == nil {
152+
selector := searchSelector(field.Type)
153+
if selector == nil {
150154
continue
151-
} else {
152-
tok = de.extractCtx.GetLocalizeTypeToken(selector)
153155
}
156+
157+
tok = de.extractCtx.GetLocalizeTypeToken(selector)
154158
}
155159

156160
if tok == etype.None {

goextractors/error.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (v errorExtractor) Run(_ context.Context, extractCtx *extractors.Context) (
4343
return
4444
}
4545

46-
if "errors" != obj.Pkg().Path() || !config.ShouldExtractPackage(pkg.PkgPath) {
46+
if obj.Pkg().Path() != "errors" || !config.ShouldExtractPackage(pkg.PkgPath) {
4747
return
4848
}
4949

goextractors/funccall.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import (
1313

1414
type funcCallExtractor struct{}
1515

16-
func NewFuncCallExtractor() extractors.Extractor {
17-
return &funcCallExtractor{}
18-
}
16+
func NewFuncCallExtractor() extractors.Extractor { return &funcCallExtractor{} }
1917

2018
func (v funcCallExtractor) Run(_ context.Context, extractCtx *extractors.Context) ([]result.Issue, error) {
2119
util.TrackTime(time.Now(), "extract func calls")
@@ -84,7 +82,7 @@ func (v funcCallExtractor) Run(_ context.Context, extractCtx *extractors.Context
8482
// Function calls
8583
for _, def := range funcParameterDefs {
8684
for i, arg := range node.Args {
87-
if (def.FieldPos != i) && !(i >= def.FieldPos && def.IsVariadic) {
85+
if (def.FieldPos != i) && (i < def.FieldPos || !def.IsVariadic) {
8886
continue
8987
}
9088

goextractors/funcreturn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (e *funcReturnExtractor) Run(_ context.Context, extractCtx *extractors.Cont
2121
util.TrackTime(time.Now(), "extract func return values")
2222
var issues []result.Issue
2323

24-
extractCtx.Inspector.WithStack([]ast.Node{&ast.FuncDecl{}}, func(rawNode ast.Node, push bool, stack []ast.Node) (proceed bool) {
24+
extractCtx.Inspector.WithStack([]ast.Node{&ast.FuncDecl{}}, func(rawNode ast.Node, push bool, _ []ast.Node) (proceed bool) {
2525
proceed = true
2626
if !push {
2727
return

result/issue.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import (
1010
)
1111

1212
type Issue struct {
13+
// FromExtractor is the name of the extractor that found this issue.
1314
FromExtractor string
14-
IDToken etype.Token
15+
16+
IDToken etype.Token
1517

1618
Domain string
1719
Context string
@@ -26,18 +28,7 @@ type Issue struct {
2628
Pos token.Position
2729
}
2830

29-
func (i *Issue) FilePath() string {
30-
return i.Pos.Filename
31-
}
32-
33-
func (i *Issue) Line() int {
34-
return i.Pos.Line
35-
}
36-
37-
func (i *Issue) Column() int {
38-
return i.Pos.Column
39-
}
40-
41-
func (i *Issue) Description() string {
42-
return fmt.Sprintf("%s: %s", i.FromExtractor, i.MsgID)
43-
}
31+
func (i *Issue) FilePath() string { return i.Pos.Filename }
32+
func (i *Issue) Line() int { return i.Pos.Line }
33+
func (i *Issue) Column() int { return i.Pos.Column }
34+
func (i *Issue) Description() string { return fmt.Sprintf("%s: %s", i.FromExtractor, i.MsgID) }

result/processors/prepare_key.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010

1111
type prepareKey struct{}
1212

13-
func NewPrepareKey() Processor {
14-
return &prepareKey{}
15-
}
13+
func NewPrepareKey() Processor { return &prepareKey{} }
14+
15+
func (p prepareKey) Name() string { return "prepare-key" }
1616

1717
func (p prepareKey) Process(inIssues []result.Issue) ([]result.Issue, error) {
1818
util.TrackTime(time.Now(), "Prepare key")
@@ -26,7 +26,3 @@ func (p prepareKey) Process(inIssues []result.Issue) ([]result.Issue, error) {
2626
}
2727
return outIssues, nil
2828
}
29-
30-
func (p prepareKey) Name() string {
31-
return "prepare_key"
32-
}
Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package processors
22

33
import (
4+
"slices"
45
"time"
56

67
"github.com/vorlif/xspreak/result"
@@ -9,26 +10,13 @@ import (
910

1011
type skipEmptyMsgID struct{}
1112

12-
func NewSkipEmptyMsgID() Processor {
13-
return &skipEmptyMsgID{}
14-
}
13+
// NewSkipEmptyMsgID create a new processor that removes issues with an empty msgId.
14+
func NewSkipEmptyMsgID() Processor { return &skipEmptyMsgID{} }
15+
16+
func (s skipEmptyMsgID) Name() string { return "skip_empty_msgid" }
1517

1618
func (s skipEmptyMsgID) Process(issues []result.Issue) ([]result.Issue, error) {
1719
util.TrackTime(time.Now(), "Clean empty msgid")
18-
return filterIssues(issues, func(i *result.Issue) bool { return i.MsgID != "" }), nil
19-
}
20-
21-
func (s skipEmptyMsgID) Name() string {
22-
return "skip_empty_msgid"
23-
}
24-
25-
func filterIssues(issues []result.Issue, filter func(i *result.Issue) bool) []result.Issue {
26-
retIssues := make([]result.Issue, 0, len(issues))
27-
for i := range issues {
28-
if filter(&issues[i]) {
29-
retIssues = append(retIssues, issues[i])
30-
}
31-
}
32-
33-
return retIssues
20+
issues = slices.DeleteFunc(issues, func(iss result.Issue) bool { return iss.MsgID == "" })
21+
return issues, nil
3422
}

0 commit comments

Comments
 (0)