Skip to content

Commit a9dc1ce

Browse files
sashamelentyevldez
andauthored
dev: change format like function without args (#3012)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent c7ed8b6 commit a9dc1ce

File tree

13 files changed

+42
-35
lines changed

13 files changed

+42
-35
lines changed

internal/cache/cache.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func Open(dir string) (*Cache, error) {
5858
return nil, err
5959
}
6060
if !info.IsDir() {
61-
return nil, &os.PathError{Op: "open", Path: dir, Err: fmt.Errorf("not a directory")}
61+
return nil, &os.PathError{Op: "open", Path: dir, Err: errors.New("not a directory")}
6262
}
6363
for i := 0; i < 256; i++ {
6464
name := filepath.Join(dir, fmt.Sprintf("%02x", i))
@@ -504,7 +504,7 @@ func (c *Cache) copyFile(file io.ReadSeeker, out OutputID, size int64) error {
504504
sum := h.Sum(nil)
505505
if !bytes.Equal(sum, out[:]) {
506506
_ = f.Truncate(0)
507-
return fmt.Errorf("file content changed underfoot")
507+
return errors.New("file content changed underfoot")
508508
}
509509

510510
// Commit cache file entry.

internal/cache/default.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package cache
66

77
import (
8+
"errors"
89
"fmt"
910
"log"
1011
"os"
@@ -69,7 +70,7 @@ func DefaultDir() string {
6970
return
7071
}
7172
if defaultDir != "" {
72-
defaultDirErr = fmt.Errorf("GOLANGCI_LINT_CACHE is not an absolute path")
73+
defaultDirErr = errors.New("GOLANGCI_LINT_CACHE is not an absolute path")
7374
return
7475
}
7576

pkg/commands/run.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func (e *Executor) initRun() {
281281
Run: e.executeRun,
282282
PreRunE: func(_ *cobra.Command, _ []string) error {
283283
if ok := e.acquireFileLock(); !ok {
284-
return fmt.Errorf("parallel golangci-lint is running")
284+
return errors.New("parallel golangci-lint is running")
285285
}
286286
return nil
287287
},

pkg/config/linters_settings_gocritic_test.go

+21-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package config
22

33
import (
4-
"fmt"
4+
"log"
55
"sort"
66
"testing"
77

@@ -10,45 +10,50 @@ import (
1010
"github.com/golangci/golangci-lint/pkg/logutils"
1111
)
1212

13-
func TestUtils(t *testing.T) {
13+
func Test_intersectStringSlice(t *testing.T) {
1414
s1 := []string{"diagnostic", "experimental", "opinionated"}
1515
s2 := []string{"opinionated", "experimental"}
16+
1617
s3 := intersectStringSlice(s1, s2)
18+
1719
sort.Strings(s3)
20+
1821
assert.Equal(t, s3, []string{"experimental", "opinionated"})
1922
}
2023

24+
func Test_filterByDisableTags(t *testing.T) {
25+
disabledTags := []string{"experimental", "opinionated"}
26+
enabledChecks := []string{"appendAssign", "sortSlice", "caseOrder", "dupImport"}
27+
28+
filterEnabledChecks := filterByDisableTags(enabledChecks, disabledTags, &tLog{})
29+
30+
sort.Strings(filterEnabledChecks)
31+
32+
assert.Equal(t, []string{"appendAssign", "caseOrder"}, filterEnabledChecks)
33+
}
34+
2135
type tLog struct{}
2236

2337
func (l *tLog) Fatalf(format string, args ...interface{}) {
24-
fmt.Printf(fmt.Sprintf(format, args...) + "\n")
38+
log.Printf(format, args...)
2539
}
2640

2741
func (l *tLog) Panicf(format string, args ...interface{}) {
28-
fmt.Printf(fmt.Sprintf(format, args...) + "\n")
42+
log.Printf(format, args...)
2943
}
3044

3145
func (l *tLog) Errorf(format string, args ...interface{}) {
32-
fmt.Printf(fmt.Sprintf(format, args...) + "\n")
46+
log.Printf(format, args...)
3347
}
3448

3549
func (l *tLog) Warnf(format string, args ...interface{}) {
36-
fmt.Printf(fmt.Sprintf(format, args...) + "\n")
50+
log.Printf(format, args...)
3751
}
3852

3953
func (l *tLog) Infof(format string, args ...interface{}) {
40-
fmt.Printf(fmt.Sprintf(format, args...) + "\n")
54+
log.Printf(format, args...)
4155
}
4256

4357
func (l *tLog) Child(name string) logutils.Log { return nil }
4458

4559
func (l *tLog) SetLevel(level logutils.LogLevel) {}
46-
47-
func TestFilterByDisableTags(t *testing.T) {
48-
testLog := &tLog{}
49-
disabledTags := []string{"experimental", "opinionated"}
50-
enabledChecks := []string{"appendAssign", "sortSlice", "caseOrder", "dupImport"}
51-
filterEnabledChecks := filterByDisableTags(enabledChecks, disabledTags, testLog)
52-
sort.Strings(filterEnabledChecks)
53-
assert.Equal(t, []string{"appendAssign", "caseOrder"}, filterEnabledChecks)
54-
}

pkg/config/reader.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (r *FileReader) parseConfig() error {
7979
r.log.Infof("Used config file %s", usedConfigFile)
8080
usedConfigDir := filepath.Dir(usedConfigFile)
8181
if usedConfigDir, err = filepath.Abs(usedConfigDir); err != nil {
82-
return fmt.Errorf("can't get config directory")
82+
return errors.New("can't get config directory")
8383
}
8484
r.cfg.cfgDir = usedConfigDir
8585

@@ -216,7 +216,7 @@ func (r *FileReader) parseConfigOption() (string, error) {
216216

217217
configFile := cfg.Run.Config
218218
if cfg.Run.NoConfig && configFile != "" {
219-
return "", fmt.Errorf("can't combine option --config and --no-config")
219+
return "", errors.New("can't combine option --config and --no-config")
220220
}
221221

222222
if cfg.Run.NoConfig {
@@ -225,7 +225,7 @@ func (r *FileReader) parseConfigOption() (string, error) {
225225

226226
configFile, err := homedir.Expand(configFile)
227227
if err != nil {
228-
return "", fmt.Errorf("failed to expand configuration path")
228+
return "", errors.New("failed to expand configuration path")
229229
}
230230

231231
return configFile, nil

pkg/golinters/goanalysis/linter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (lnt *Linter) configureAnalyzer(a *analysis.Analyzer, cfg map[string]interf
108108
if f == nil {
109109
validFlagNames := allFlagNames(&a.Flags)
110110
if len(validFlagNames) == 0 {
111-
return fmt.Errorf("analyzer doesn't have settings")
111+
return errors.New("analyzer doesn't have settings")
112112
}
113113

114114
return fmt.Errorf("analyzer doesn't have setting %q, valid settings: %v",

pkg/lint/lintersdb/validator.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package lintersdb
22

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

@@ -47,20 +48,20 @@ func (v Validator) validatePresets(cfg *config.Linters) error {
4748
}
4849

4950
if len(cfg.Presets) != 0 && cfg.EnableAll {
50-
return fmt.Errorf("--presets is incompatible with --enable-all")
51+
return errors.New("--presets is incompatible with --enable-all")
5152
}
5253

5354
return nil
5455
}
5556

5657
func (v Validator) validateAllDisableEnableOptions(cfg *config.Linters) error {
5758
if cfg.EnableAll && cfg.DisableAll {
58-
return fmt.Errorf("--enable-all and --disable-all options must not be combined")
59+
return errors.New("--enable-all and --disable-all options must not be combined")
5960
}
6061

6162
if cfg.DisableAll {
6263
if len(cfg.Enable) == 0 && len(cfg.Presets) == 0 {
63-
return fmt.Errorf("all linters were disabled, but no one linter was enabled: must enable at least one")
64+
return errors.New("all linters were disabled, but no one linter was enabled: must enable at least one")
6465
}
6566

6667
if len(cfg.Disable) != 0 {

pkg/result/processors/autogenerated_exclude.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package processors
22

33
import (
4-
"fmt"
54
"go/parser"
65
"go/token"
76
"path/filepath"
@@ -103,7 +102,7 @@ func (p *AutogeneratedExclude) getOrCreateFileSummary(i *result.Issue) (*ageFile
103102
p.fileSummaryCache[i.FilePath()] = fs
104103

105104
if i.FilePath() == "" {
106-
return nil, fmt.Errorf("no file path for issue")
105+
return nil, errors.New("no file path for issue")
107106
}
108107

109108
doc, err := getDoc(i.FilePath())

pkg/result/processors/nolint.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package processors
22

33
import (
4-
"fmt"
4+
"errors"
55
"go/ast"
66
"go/parser"
77
"go/token"
@@ -105,7 +105,7 @@ func (p *Nolint) getOrCreateFileData(i *result.Issue) (*fileData, error) {
105105
p.cache[i.FilePath()] = fd
106106

107107
if i.FilePath() == "" {
108-
return nil, fmt.Errorf("no file path for issue")
108+
return nil, errors.New("no file path for issue")
109109
}
110110

111111
// TODO: migrate this parsing to go/analysis facts

scripts/expand_website_templates/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func main() {
5050
if err := rewriteDocs(replacements); err != nil {
5151
log.Fatalf("Failed to rewrite docs: %s", err)
5252
}
53-
log.Printf("Successfully expanded templates")
53+
log.Print("Successfully expanded templates")
5454
}
5555

5656
func updateStateFile(replacements map[string]string) error {

test/bench/bench_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package bench
22

33
import (
44
"bytes"
5+
"errors"
56
"fmt"
67
"go/build"
78
"log"
@@ -123,7 +124,7 @@ func getLinterMemoryMB(b *testing.B, progName string) (int, error) {
123124
}
124125
}
125126
if progPID == 0 {
126-
return 0, fmt.Errorf("no process")
127+
return 0, errors.New("no process")
127128
}
128129

129130
allProgPIDs := []int{progPID}

test/errchk.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func errorCheck(outStr string, wantAuto bool, defaultWantedLinter string, fullsh
9696
}
9797

9898
if len(out) > 0 {
99-
errs = append(errs, fmt.Errorf("unmatched errors"))
99+
errs = append(errs, errors.New("unmatched errors"))
100100
for _, errLine := range out {
101101
errs = append(errs, fmt.Errorf("%s", errLine))
102102
}

test/testdata_etc/abspath/with_issue.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ func f() {
66
if true {
77
return
88
} else {
9-
fmt.Printf("")
9+
fmt.Print("")
1010
}
1111
}

0 commit comments

Comments
 (0)