dev: change format like function without args ()

Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
Sasha Melentyev 2022-07-24 19:24:01 +03:00 committed by GitHub
parent c7ed8b67a7
commit a9dc1ce178
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 42 additions and 35 deletions
internal/cache
pkg
scripts/expand_website_templates
test
bench
errchk.go
testdata_etc/abspath

@ -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))
@ -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.

@ -5,6 +5,7 @@
package cache
import (
"errors"
"fmt"
"log"
"os"
@ -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
}

@ -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
},

@ -1,7 +1,7 @@
package config
import (
"fmt"
"log"
"sort"
"testing"
@ -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)
}

@ -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
@ -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 {
@ -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

@ -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",

@ -1,6 +1,7 @@
package lintersdb
import (
"errors"
"fmt"
"strings"
@ -47,7 +48,7 @@ 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
@ -55,12 +56,12 @@ func (v Validator) validatePresets(cfg *config.Linters) error {
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 {

@ -1,7 +1,6 @@
package processors
import (
"fmt"
"go/parser"
"go/token"
"path/filepath"
@ -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())

@ -1,7 +1,7 @@
package processors
import (
"fmt"
"errors"
"go/ast"
"go/parser"
"go/token"
@ -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

@ -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 {

@ -2,6 +2,7 @@ package bench
import (
"bytes"
"errors"
"fmt"
"go/build"
"log"
@ -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}

@ -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))
}

@ -6,6 +6,6 @@ func f() {
if true {
return
} else {
fmt.Printf("")
fmt.Print("")
}
}