Skip to content

Commit

Permalink
dev: change format like function without args (golangci#3012)
Browse files Browse the repository at this point in the history
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
  • Loading branch information
2 people authored and SeigeC committed Apr 4, 2023
1 parent 8872840 commit b83f375
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 35 deletions.
4 changes: 2 additions & 2 deletions internal/cache/cache.go
Expand Up @@ -58,7 +58,7 @@ func Open(dir string) (*Cache, error) {
return nil, err
}
if !info.IsDir() {
return nil, &os.PathError{Op: "open", Path: dir, Err: fmt.Errorf("not a directory")}
return nil, &os.PathError{Op: "open", Path: dir, Err: errors.New("not a directory")}
}
for i := 0; i < 256; i++ {
name := filepath.Join(dir, fmt.Sprintf("%02x", i))
Expand Down Expand Up @@ -504,7 +504,7 @@ func (c *Cache) copyFile(file io.ReadSeeker, out OutputID, size int64) error {
sum := h.Sum(nil)
if !bytes.Equal(sum, out[:]) {
_ = f.Truncate(0)
return fmt.Errorf("file content changed underfoot")
return errors.New("file content changed underfoot")
}

// Commit cache file entry.
Expand Down
3 changes: 2 additions & 1 deletion internal/cache/default.go
Expand Up @@ -5,6 +5,7 @@
package cache

import (
"errors"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -69,7 +70,7 @@ func DefaultDir() string {
return
}
if defaultDir != "" {
defaultDirErr = fmt.Errorf("GOLANGCI_LINT_CACHE is not an absolute path")
defaultDirErr = errors.New("GOLANGCI_LINT_CACHE is not an absolute path")
return
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/run.go
Expand Up @@ -281,7 +281,7 @@ func (e *Executor) initRun() {
Run: e.executeRun,
PreRunE: func(_ *cobra.Command, _ []string) error {
if ok := e.acquireFileLock(); !ok {
return fmt.Errorf("parallel golangci-lint is running")
return errors.New("parallel golangci-lint is running")
}
return nil
},
Expand Down
37 changes: 21 additions & 16 deletions pkg/config/linters_settings_gocritic_test.go
@@ -1,7 +1,7 @@
package config

import (
"fmt"
"log"
"sort"
"testing"

Expand All @@ -10,45 +10,50 @@ import (
"github.com/golangci/golangci-lint/pkg/logutils"
)

func TestUtils(t *testing.T) {
func Test_intersectStringSlice(t *testing.T) {
s1 := []string{"diagnostic", "experimental", "opinionated"}
s2 := []string{"opinionated", "experimental"}

s3 := intersectStringSlice(s1, s2)

sort.Strings(s3)

assert.Equal(t, s3, []string{"experimental", "opinionated"})
}

func Test_filterByDisableTags(t *testing.T) {
disabledTags := []string{"experimental", "opinionated"}
enabledChecks := []string{"appendAssign", "sortSlice", "caseOrder", "dupImport"}

filterEnabledChecks := filterByDisableTags(enabledChecks, disabledTags, &tLog{})

sort.Strings(filterEnabledChecks)

assert.Equal(t, []string{"appendAssign", "caseOrder"}, filterEnabledChecks)
}

type tLog struct{}

func (l *tLog) Fatalf(format string, args ...interface{}) {
fmt.Printf(fmt.Sprintf(format, args...) + "\n")
log.Printf(format, args...)
}

func (l *tLog) Panicf(format string, args ...interface{}) {
fmt.Printf(fmt.Sprintf(format, args...) + "\n")
log.Printf(format, args...)
}

func (l *tLog) Errorf(format string, args ...interface{}) {
fmt.Printf(fmt.Sprintf(format, args...) + "\n")
log.Printf(format, args...)
}

func (l *tLog) Warnf(format string, args ...interface{}) {
fmt.Printf(fmt.Sprintf(format, args...) + "\n")
log.Printf(format, args...)
}

func (l *tLog) Infof(format string, args ...interface{}) {
fmt.Printf(fmt.Sprintf(format, args...) + "\n")
log.Printf(format, args...)
}

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

func (l *tLog) SetLevel(level logutils.LogLevel) {}

func TestFilterByDisableTags(t *testing.T) {
testLog := &tLog{}
disabledTags := []string{"experimental", "opinionated"}
enabledChecks := []string{"appendAssign", "sortSlice", "caseOrder", "dupImport"}
filterEnabledChecks := filterByDisableTags(enabledChecks, disabledTags, testLog)
sort.Strings(filterEnabledChecks)
assert.Equal(t, []string{"appendAssign", "caseOrder"}, filterEnabledChecks)
}
6 changes: 3 additions & 3 deletions pkg/config/reader.go
Expand Up @@ -79,7 +79,7 @@ func (r *FileReader) parseConfig() error {
r.log.Infof("Used config file %s", usedConfigFile)
usedConfigDir := filepath.Dir(usedConfigFile)
if usedConfigDir, err = filepath.Abs(usedConfigDir); err != nil {
return fmt.Errorf("can't get config directory")
return errors.New("can't get config directory")
}
r.cfg.cfgDir = usedConfigDir

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

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

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

configFile, err := homedir.Expand(configFile)
if err != nil {
return "", fmt.Errorf("failed to expand configuration path")
return "", errors.New("failed to expand configuration path")
}

return configFile, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/goanalysis/linter.go
Expand Up @@ -108,7 +108,7 @@ func (lnt *Linter) configureAnalyzer(a *analysis.Analyzer, cfg map[string]interf
if f == nil {
validFlagNames := allFlagNames(&a.Flags)
if len(validFlagNames) == 0 {
return fmt.Errorf("analyzer doesn't have settings")
return errors.New("analyzer doesn't have settings")
}

return fmt.Errorf("analyzer doesn't have setting %q, valid settings: %v",
Expand Down
7 changes: 4 additions & 3 deletions pkg/lint/lintersdb/validator.go
@@ -1,6 +1,7 @@
package lintersdb

import (
"errors"
"fmt"
"strings"

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

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

return nil
}

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

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

if len(cfg.Disable) != 0 {
Expand Down
3 changes: 1 addition & 2 deletions pkg/result/processors/autogenerated_exclude.go
@@ -1,7 +1,6 @@
package processors

import (
"fmt"
"go/parser"
"go/token"
"path/filepath"
Expand Down Expand Up @@ -103,7 +102,7 @@ func (p *AutogeneratedExclude) getOrCreateFileSummary(i *result.Issue) (*ageFile
p.fileSummaryCache[i.FilePath()] = fs

if i.FilePath() == "" {
return nil, fmt.Errorf("no file path for issue")
return nil, errors.New("no file path for issue")
}

doc, err := getDoc(i.FilePath())
Expand Down
4 changes: 2 additions & 2 deletions pkg/result/processors/nolint.go
@@ -1,7 +1,7 @@
package processors

import (
"fmt"
"errors"
"go/ast"
"go/parser"
"go/token"
Expand Down Expand Up @@ -105,7 +105,7 @@ func (p *Nolint) getOrCreateFileData(i *result.Issue) (*fileData, error) {
p.cache[i.FilePath()] = fd

if i.FilePath() == "" {
return nil, fmt.Errorf("no file path for issue")
return nil, errors.New("no file path for issue")
}

// TODO: migrate this parsing to go/analysis facts
Expand Down
2 changes: 1 addition & 1 deletion scripts/expand_website_templates/main.go
Expand Up @@ -50,7 +50,7 @@ func main() {
if err := rewriteDocs(replacements); err != nil {
log.Fatalf("Failed to rewrite docs: %s", err)
}
log.Printf("Successfully expanded templates")
log.Print("Successfully expanded templates")
}

func updateStateFile(replacements map[string]string) error {
Expand Down
3 changes: 2 additions & 1 deletion test/bench/bench_test.go
Expand Up @@ -2,6 +2,7 @@ package bench

import (
"bytes"
"errors"
"fmt"
"go/build"
"log"
Expand Down Expand Up @@ -123,7 +124,7 @@ func getLinterMemoryMB(b *testing.B, progName string) (int, error) {
}
}
if progPID == 0 {
return 0, fmt.Errorf("no process")
return 0, errors.New("no process")
}

allProgPIDs := []int{progPID}
Expand Down
2 changes: 1 addition & 1 deletion test/errchk.go
Expand Up @@ -96,7 +96,7 @@ func errorCheck(outStr string, wantAuto bool, defaultWantedLinter string, fullsh
}

if len(out) > 0 {
errs = append(errs, fmt.Errorf("unmatched errors"))
errs = append(errs, errors.New("unmatched errors"))
for _, errLine := range out {
errs = append(errs, fmt.Errorf("%s", errLine))
}
Expand Down
2 changes: 1 addition & 1 deletion test/testdata_etc/abspath/with_issue.go
Expand Up @@ -6,6 +6,6 @@ func f() {
if true {
return
} else {
fmt.Printf("")
fmt.Print("")
}
}

0 comments on commit b83f375

Please sign in to comment.