Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint cleanup #679

Merged
merged 4 commits into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func GetLintingRules(config *lint.Config, extraRules []lint.Rule) ([]lint.Rule,

var lintingRules []lint.Rule
for name, ruleConfig := range config.Rules {
rule, ok := rulesMap[name]
r, ok := rulesMap[name]
if !ok {
return nil, fmt.Errorf("cannot find rule: %s", name)
}
Expand All @@ -131,7 +131,7 @@ func GetLintingRules(config *lint.Config, extraRules []lint.Rule) ([]lint.Rule,
continue // skip disabled rules
}

lintingRules = append(lintingRules, rule)
lintingRules = append(lintingRules, r)
}

return lintingRules, nil
Expand All @@ -155,8 +155,8 @@ func normalizeConfig(config *lint.Config) {
}
if config.EnableAllRules {
// Add to the configuration all rules not yet present in it
for _, rule := range allRules {
ruleName := rule.Name()
for _, r := range allRules {
ruleName := r.Name()
_, alreadyInConf := config.Rules[ruleName]
if alreadyInConf {
continue
Expand Down Expand Up @@ -207,15 +207,15 @@ func GetConfig(configPath string) (*lint.Config, error) {
// GetFormatter yields the formatter for lint failures
func GetFormatter(formatterName string) (lint.Formatter, error) {
formatters := getFormatters()
formatter := formatters["default"]
fmtr := formatters["default"]
if formatterName != "" {
f, ok := formatters[formatterName]
if !ok {
return nil, fmt.Errorf("unknown formatter %v", formatterName)
}
formatter = f
fmtr = f
}
return formatter, nil
return fmtr, nil
}

func defaultConfig() *lint.Config {
Expand Down
4 changes: 2 additions & 2 deletions formatter/checkstyle.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Checkstyle struct {
}

// Name returns the name of the formatter
func (f *Checkstyle) Name() string {
func (*Checkstyle) Name() string {
return "checkstyle"
}

Expand All @@ -29,7 +29,7 @@ type issue struct {
}

// Format formats the failures gotten from the lint.
func (f *Checkstyle) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
func (*Checkstyle) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
issues := map[string][]issue{}
for failure := range failures {
buf := new(bytes.Buffer)
Expand Down
4 changes: 2 additions & 2 deletions formatter/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ type Default struct {
}

// Name returns the name of the formatter
func (f *Default) Name() string {
func (*Default) Name() string {
return "default"
}

// Format formats the failures gotten from the lint.
func (f *Default) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) {
func (*Default) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) {
for failure := range failures {
fmt.Printf("%v: %s\n", failure.Position.Start, failure.Failure)
}
Expand Down
18 changes: 4 additions & 14 deletions formatter/friendly.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ import (
"github.com/olekukonko/tablewriter"
)

var newLines = map[rune]bool{
0x000A: true,
0x000B: true,
0x000C: true,
0x000D: true,
0x0085: true,
0x2028: true,
0x2029: true,
}

func getErrorEmoji() string {
return color.RedString("✘")
}
Expand All @@ -35,7 +25,7 @@ type Friendly struct {
}

// Name returns the name of the formatter
func (f *Friendly) Name() string {
func (*Friendly) Name() string {
return "friendly"
}

Expand Down Expand Up @@ -78,7 +68,7 @@ func (f *Friendly) printHeaderRow(failure lint.Failure, severity lint.Severity)
fmt.Print(f.table([][]string{{emoji, "https://revive.run/r#" + failure.RuleName, color.GreenString(failure.Failure)}}))
}

func (f *Friendly) printFilePosition(failure lint.Failure) {
func (*Friendly) printFilePosition(failure lint.Failure) {
fmt.Printf(" %s:%d:%d", failure.GetFilename(), failure.Position.Start.Line, failure.Position.Start.Column)
}

Expand All @@ -87,7 +77,7 @@ type statEntry struct {
failures int
}

func (f *Friendly) printSummary(errors, warnings int) {
func (*Friendly) printSummary(errors, warnings int) {
emoji := getWarningEmoji()
if errors > 0 {
emoji = getErrorEmoji()
Expand Down Expand Up @@ -136,7 +126,7 @@ func (f *Friendly) printStatistics(header string, stats map[string]int) {
fmt.Println(f.table(formatted))
}

func (f *Friendly) table(rows [][]string) string {
func (*Friendly) table(rows [][]string) string {
buf := new(bytes.Buffer)
table := tablewriter.NewWriter(buf)
table.SetBorder(false)
Expand Down
4 changes: 2 additions & 2 deletions formatter/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type JSON struct {
}

// Name returns the name of the formatter
func (f *JSON) Name() string {
func (*JSON) Name() string {
return "json"
}

Expand All @@ -24,7 +24,7 @@ type jsonObject struct {
}

// Format formats the failures gotten from the lint.
func (f *JSON) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
func (*JSON) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
var slice []jsonObject
for failure := range failures {
obj := jsonObject{}
Expand Down
4 changes: 2 additions & 2 deletions formatter/ndjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ type NDJSON struct {
}

// Name returns the name of the formatter
func (f *NDJSON) Name() string {
func (*NDJSON) Name() string {
return "ndjson"
}

// Format formats the failures gotten from the lint.
func (f *NDJSON) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
func (*NDJSON) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
enc := json.NewEncoder(os.Stdout)
for failure := range failures {
obj := jsonObject{}
Expand Down
4 changes: 2 additions & 2 deletions formatter/plain.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ type Plain struct {
}

// Name returns the name of the formatter
func (f *Plain) Name() string {
func (*Plain) Name() string {
return "plain"
}

// Format formats the failures gotten from the lint.
func (f *Plain) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) {
func (*Plain) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) {
for failure := range failures {
fmt.Printf("%v: %s %s\n", failure.Position.Start, failure.Failure, "https://revive.run/r#"+failure.RuleName)
}
Expand Down
4 changes: 2 additions & 2 deletions formatter/sarif.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ type Sarif struct {
}

// Name returns the name of the formatter
func (f *Sarif) Name() string {
func (*Sarif) Name() string {
return "sarif"
}

const reviveSite = "https://revive.run"

// Format formats the failures gotten from the lint.
func (f *Sarif) Format(failures <-chan lint.Failure, cfg lint.Config) (string, error) {
func (*Sarif) Format(failures <-chan lint.Failure, cfg lint.Config) (string, error) {
sarifLog := newReviveRunLog(cfg)

for failure := range failures {
Expand Down
4 changes: 2 additions & 2 deletions formatter/stylish.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Stylish struct {
}

// Name returns the name of the formatter
func (f *Stylish) Name() string {
func (*Stylish) Name() string {
return "stylish"
}

Expand All @@ -32,7 +32,7 @@ func formatFailure(failure lint.Failure, severity lint.Severity) []string {
}

// Format formats the failures gotten from the lint.
func (f *Stylish) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
func (*Stylish) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
var result [][]string
totalErrors := 0
total := 0
Expand Down
4 changes: 2 additions & 2 deletions formatter/unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ type Unix struct {
}

// Name returns the name of the formatter
func (f *Unix) Name() string {
func (*Unix) Name() string {
return "unix"
}

// Format formats the failures gotten from the lint.
func (f *Unix) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) {
func (*Unix) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) {
for failure := range failures {
fmt.Printf("%v: [%s] %s\n", failure.Position.Start, failure.RuleName, failure.Failure)
}
Expand Down
2 changes: 1 addition & 1 deletion lint/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (f *File) disabledIntervals(rules []Rule, mustSpecifyDisableReason bool, fa
return getEnabledDisabledIntervals()
}

func (f *File) filterFailures(failures []Failure, disabledIntervals disabledIntervalsMap) []Failure {
func (File) filterFailures(failures []Failure, disabledIntervals disabledIntervalsMap) []Failure {
result := []Failure{}
for _, failure := range failures {
fStart := failure.Position.Start.Line
Expand Down
2 changes: 1 addition & 1 deletion lint/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func addInvalidFileFailure(filename, errStr string, failures chan Failure) {
// errPosRegexp matches with an NewFile error message
// i.e. : corrupted.go:10:4: expected '}', found 'EOF
// first group matches the line and the second group, the column
var errPosRegexp = regexp.MustCompile(".*:(\\d*):(\\d*):.*$")
var errPosRegexp = regexp.MustCompile(`.*:(\d*):(\d*):.*$`)

// getPositionInvalidFile gets the position of the error in an invalid file
func getPositionInvalidFile(filename, s string) FailurePosition {
Expand Down
6 changes: 3 additions & 3 deletions revivelib/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func New(
maxOpenFiles int,
extraRules ...ExtraRule,
) (*Revive, error) {
log, err := logging.GetLogger()
logger, err := logging.GetLogger()
if err != nil {
return nil, errors.Wrap(err, "initializing revive - getting logger")
}
Expand All @@ -55,10 +55,10 @@ func New(
return nil, errors.Wrap(err, "initializing revive - gettint lint rules")
}

log.Println("Config loaded")
logger.Println("Config loaded")

return &Revive{
logger: log,
logger: logger,
config: conf,
lintingRules: lintingRules,
maxOpenFiles: maxOpenFiles,
Expand Down
4 changes: 2 additions & 2 deletions revivelib/core_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ func TestReviveCreateInstance(t *testing.T) {
type mockRule struct {
}

func (r *mockRule) Name() string {
func (*mockRule) Name() string {
return "mock-rule"
}

func (r *mockRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
func (*mockRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion rule/add-constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (r *AddConstantRule) Apply(file *lint.File, arguments lint.Arguments) []lin
}

// Name returns the rule name.
func (r *AddConstantRule) Name() string {
func (*AddConstantRule) Name() string {
return "add-constant"
}

Expand Down
2 changes: 1 addition & 1 deletion rule/argument-limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (r *ArgumentsLimitRule) Apply(file *lint.File, arguments lint.Arguments) []
}

// Name returns the rule name.
func (r *ArgumentsLimitRule) Name() string {
func (*ArgumentsLimitRule) Name() string {
return "argument-limit"
}

Expand Down
4 changes: 2 additions & 2 deletions rule/atomic.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type AtomicRule struct{}

// Apply applies the rule to given file.
func (r *AtomicRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
func (*AtomicRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure
walker := atomic{
pkgTypesInfo: file.Pkg.TypesInfo(),
Expand All @@ -27,7 +27,7 @@ func (r *AtomicRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
}

// Name returns the rule name.
func (r *AtomicRule) Name() string {
func (*AtomicRule) Name() string {
return "atomic"
}

Expand Down
2 changes: 1 addition & 1 deletion rule/banned-characters.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (r *BannedCharsRule) Apply(file *lint.File, arguments lint.Arguments) []lin
}

// Name returns the rule name
func (r *BannedCharsRule) Name() string {
func (*BannedCharsRule) Name() string {
return bannedCharsRuleName
}

Expand Down
4 changes: 2 additions & 2 deletions rule/bare-return.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type BareReturnRule struct{}

// Apply applies the rule to given file.
func (r *BareReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
func (*BareReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure

onFailure := func(failure lint.Failure) {
Expand All @@ -23,7 +23,7 @@ func (r *BareReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure
}

// Name returns the rule name.
func (r *BareReturnRule) Name() string {
func (*BareReturnRule) Name() string {
return "bare-return"
}

Expand Down
4 changes: 2 additions & 2 deletions rule/blank-imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
type BlankImportsRule struct{}

// Name returns the rule name.
func (r *BlankImportsRule) Name() string {
func (*BlankImportsRule) Name() string {
return "blank-imports"
}

Expand Down Expand Up @@ -62,7 +62,7 @@ func (r *BlankImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failu
return failures
}

func (r *BlankImportsRule) fileHasValidEmbedComment(fileAst *ast.File) bool {
func (*BlankImportsRule) fileHasValidEmbedComment(fileAst *ast.File) bool {
for _, commentGroup := range fileAst.Comments {
for _, comment := range commentGroup.List {
if strings.HasPrefix(comment.Text, "//go:embed ") {
Expand Down
4 changes: 2 additions & 2 deletions rule/bool-literal-in-expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
type BoolLiteralRule struct{}

// Apply applies the rule to given file.
func (r *BoolLiteralRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
func (*BoolLiteralRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure

onFailure := func(failure lint.Failure) {
Expand All @@ -26,7 +26,7 @@ func (r *BoolLiteralRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failur
}

// Name returns the rule name.
func (r *BoolLiteralRule) Name() string {
func (*BoolLiteralRule) Name() string {
return "bool-literal-in-expr"
}

Expand Down
Loading