dev: change format like function without args (#3012)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
parent
c7ed8b67a7
commit
a9dc1ce178
4
internal/cache/cache.go
vendored
4
internal/cache/cache.go
vendored
@ -58,7 +58,7 @@ func Open(dir string) (*Cache, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if !info.IsDir() {
|
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++ {
|
for i := 0; i < 256; i++ {
|
||||||
name := filepath.Join(dir, fmt.Sprintf("%02x", 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)
|
sum := h.Sum(nil)
|
||||||
if !bytes.Equal(sum, out[:]) {
|
if !bytes.Equal(sum, out[:]) {
|
||||||
_ = f.Truncate(0)
|
_ = f.Truncate(0)
|
||||||
return fmt.Errorf("file content changed underfoot")
|
return errors.New("file content changed underfoot")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit cache file entry.
|
// Commit cache file entry.
|
||||||
|
3
internal/cache/default.go
vendored
3
internal/cache/default.go
vendored
@ -5,6 +5,7 @@
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@ -69,7 +70,7 @@ func DefaultDir() string {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if defaultDir != "" {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +281,7 @@ func (e *Executor) initRun() {
|
|||||||
Run: e.executeRun,
|
Run: e.executeRun,
|
||||||
PreRunE: func(_ *cobra.Command, _ []string) error {
|
PreRunE: func(_ *cobra.Command, _ []string) error {
|
||||||
if ok := e.acquireFileLock(); !ok {
|
if ok := e.acquireFileLock(); !ok {
|
||||||
return fmt.Errorf("parallel golangci-lint is running")
|
return errors.New("parallel golangci-lint is running")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"log"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -10,45 +10,50 @@ import (
|
|||||||
"github.com/golangci/golangci-lint/pkg/logutils"
|
"github.com/golangci/golangci-lint/pkg/logutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUtils(t *testing.T) {
|
func Test_intersectStringSlice(t *testing.T) {
|
||||||
s1 := []string{"diagnostic", "experimental", "opinionated"}
|
s1 := []string{"diagnostic", "experimental", "opinionated"}
|
||||||
s2 := []string{"opinionated", "experimental"}
|
s2 := []string{"opinionated", "experimental"}
|
||||||
|
|
||||||
s3 := intersectStringSlice(s1, s2)
|
s3 := intersectStringSlice(s1, s2)
|
||||||
|
|
||||||
sort.Strings(s3)
|
sort.Strings(s3)
|
||||||
|
|
||||||
assert.Equal(t, s3, []string{"experimental", "opinionated"})
|
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{}
|
type tLog struct{}
|
||||||
|
|
||||||
func (l *tLog) Fatalf(format string, args ...interface{}) {
|
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{}) {
|
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{}) {
|
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{}) {
|
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{}) {
|
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) Child(name string) logutils.Log { return nil }
|
||||||
|
|
||||||
func (l *tLog) SetLevel(level logutils.LogLevel) {}
|
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)
|
r.log.Infof("Used config file %s", usedConfigFile)
|
||||||
usedConfigDir := filepath.Dir(usedConfigFile)
|
usedConfigDir := filepath.Dir(usedConfigFile)
|
||||||
if usedConfigDir, err = filepath.Abs(usedConfigDir); err != nil {
|
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
|
r.cfg.cfgDir = usedConfigDir
|
||||||
|
|
||||||
@ -216,7 +216,7 @@ func (r *FileReader) parseConfigOption() (string, error) {
|
|||||||
|
|
||||||
configFile := cfg.Run.Config
|
configFile := cfg.Run.Config
|
||||||
if cfg.Run.NoConfig && configFile != "" {
|
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 {
|
if cfg.Run.NoConfig {
|
||||||
@ -225,7 +225,7 @@ func (r *FileReader) parseConfigOption() (string, error) {
|
|||||||
|
|
||||||
configFile, err := homedir.Expand(configFile)
|
configFile, err := homedir.Expand(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to expand configuration path")
|
return "", errors.New("failed to expand configuration path")
|
||||||
}
|
}
|
||||||
|
|
||||||
return configFile, nil
|
return configFile, nil
|
||||||
|
@ -108,7 +108,7 @@ func (lnt *Linter) configureAnalyzer(a *analysis.Analyzer, cfg map[string]interf
|
|||||||
if f == nil {
|
if f == nil {
|
||||||
validFlagNames := allFlagNames(&a.Flags)
|
validFlagNames := allFlagNames(&a.Flags)
|
||||||
if len(validFlagNames) == 0 {
|
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",
|
return fmt.Errorf("analyzer doesn't have setting %q, valid settings: %v",
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package lintersdb
|
package lintersdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -47,7 +48,7 @@ func (v Validator) validatePresets(cfg *config.Linters) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(cfg.Presets) != 0 && cfg.EnableAll {
|
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
|
return nil
|
||||||
@ -55,12 +56,12 @@ func (v Validator) validatePresets(cfg *config.Linters) error {
|
|||||||
|
|
||||||
func (v Validator) validateAllDisableEnableOptions(cfg *config.Linters) error {
|
func (v Validator) validateAllDisableEnableOptions(cfg *config.Linters) error {
|
||||||
if cfg.EnableAll && cfg.DisableAll {
|
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 cfg.DisableAll {
|
||||||
if len(cfg.Enable) == 0 && len(cfg.Presets) == 0 {
|
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 {
|
if len(cfg.Disable) != 0 {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package processors
|
package processors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"go/parser"
|
"go/parser"
|
||||||
"go/token"
|
"go/token"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -103,7 +102,7 @@ func (p *AutogeneratedExclude) getOrCreateFileSummary(i *result.Issue) (*ageFile
|
|||||||
p.fileSummaryCache[i.FilePath()] = fs
|
p.fileSummaryCache[i.FilePath()] = fs
|
||||||
|
|
||||||
if i.FilePath() == "" {
|
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())
|
doc, err := getDoc(i.FilePath())
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package processors
|
package processors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"errors"
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"go/parser"
|
"go/parser"
|
||||||
"go/token"
|
"go/token"
|
||||||
@ -105,7 +105,7 @@ func (p *Nolint) getOrCreateFileData(i *result.Issue) (*fileData, error) {
|
|||||||
p.cache[i.FilePath()] = fd
|
p.cache[i.FilePath()] = fd
|
||||||
|
|
||||||
if i.FilePath() == "" {
|
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
|
// TODO: migrate this parsing to go/analysis facts
|
||||||
|
@ -50,7 +50,7 @@ func main() {
|
|||||||
if err := rewriteDocs(replacements); err != nil {
|
if err := rewriteDocs(replacements); err != nil {
|
||||||
log.Fatalf("Failed to rewrite docs: %s", err)
|
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 {
|
func updateStateFile(replacements map[string]string) error {
|
||||||
|
@ -2,6 +2,7 @@ package bench
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/build"
|
"go/build"
|
||||||
"log"
|
"log"
|
||||||
@ -123,7 +124,7 @@ func getLinterMemoryMB(b *testing.B, progName string) (int, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if progPID == 0 {
|
if progPID == 0 {
|
||||||
return 0, fmt.Errorf("no process")
|
return 0, errors.New("no process")
|
||||||
}
|
}
|
||||||
|
|
||||||
allProgPIDs := []int{progPID}
|
allProgPIDs := []int{progPID}
|
||||||
|
@ -96,7 +96,7 @@ func errorCheck(outStr string, wantAuto bool, defaultWantedLinter string, fullsh
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(out) > 0 {
|
if len(out) > 0 {
|
||||||
errs = append(errs, fmt.Errorf("unmatched errors"))
|
errs = append(errs, errors.New("unmatched errors"))
|
||||||
for _, errLine := range out {
|
for _, errLine := range out {
|
||||||
errs = append(errs, fmt.Errorf("%s", errLine))
|
errs = append(errs, fmt.Errorf("%s", errLine))
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,6 @@ func f() {
|
|||||||
if true {
|
if true {
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("")
|
fmt.Print("")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user