Skip to content

Commit 04728cf

Browse files
authored
Lint cleanup (#679)
1 parent 31fbdb1 commit 04728cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+203
-233
lines changed

config/config.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func GetLintingRules(config *lint.Config, extraRules []lint.Rule) ([]lint.Rule,
122122

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

134-
lintingRules = append(lintingRules, rule)
134+
lintingRules = append(lintingRules, r)
135135
}
136136

137137
return lintingRules, nil
@@ -155,8 +155,8 @@ func normalizeConfig(config *lint.Config) {
155155
}
156156
if config.EnableAllRules {
157157
// Add to the configuration all rules not yet present in it
158-
for _, rule := range allRules {
159-
ruleName := rule.Name()
158+
for _, r := range allRules {
159+
ruleName := r.Name()
160160
_, alreadyInConf := config.Rules[ruleName]
161161
if alreadyInConf {
162162
continue
@@ -207,15 +207,15 @@ func GetConfig(configPath string) (*lint.Config, error) {
207207
// GetFormatter yields the formatter for lint failures
208208
func GetFormatter(formatterName string) (lint.Formatter, error) {
209209
formatters := getFormatters()
210-
formatter := formatters["default"]
210+
fmtr := formatters["default"]
211211
if formatterName != "" {
212212
f, ok := formatters[formatterName]
213213
if !ok {
214214
return nil, fmt.Errorf("unknown formatter %v", formatterName)
215215
}
216-
formatter = f
216+
fmtr = f
217217
}
218-
return formatter, nil
218+
return fmtr, nil
219219
}
220220

221221
func defaultConfig() *lint.Config {

formatter/checkstyle.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type Checkstyle struct {
1515
}
1616

1717
// Name returns the name of the formatter
18-
func (f *Checkstyle) Name() string {
18+
func (*Checkstyle) Name() string {
1919
return "checkstyle"
2020
}
2121

@@ -29,7 +29,7 @@ type issue struct {
2929
}
3030

3131
// Format formats the failures gotten from the lint.
32-
func (f *Checkstyle) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
32+
func (*Checkstyle) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
3333
issues := map[string][]issue{}
3434
for failure := range failures {
3535
buf := new(bytes.Buffer)

formatter/default.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ type Default struct {
1313
}
1414

1515
// Name returns the name of the formatter
16-
func (f *Default) Name() string {
16+
func (*Default) Name() string {
1717
return "default"
1818
}
1919

2020
// Format formats the failures gotten from the lint.
21-
func (f *Default) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) {
21+
func (*Default) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) {
2222
for failure := range failures {
2323
fmt.Printf("%v: %s\n", failure.Position.Start, failure.Failure)
2424
}

formatter/friendly.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ import (
1010
"github.com/olekukonko/tablewriter"
1111
)
1212

13-
var newLines = map[rune]bool{
14-
0x000A: true,
15-
0x000B: true,
16-
0x000C: true,
17-
0x000D: true,
18-
0x0085: true,
19-
0x2028: true,
20-
0x2029: true,
21-
}
22-
2313
func getErrorEmoji() string {
2414
return color.RedString("✘")
2515
}
@@ -35,7 +25,7 @@ type Friendly struct {
3525
}
3626

3727
// Name returns the name of the formatter
38-
func (f *Friendly) Name() string {
28+
func (*Friendly) Name() string {
3929
return "friendly"
4030
}
4131

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

81-
func (f *Friendly) printFilePosition(failure lint.Failure) {
71+
func (*Friendly) printFilePosition(failure lint.Failure) {
8272
fmt.Printf(" %s:%d:%d", failure.GetFilename(), failure.Position.Start.Line, failure.Position.Start.Column)
8373
}
8474

@@ -87,7 +77,7 @@ type statEntry struct {
8777
failures int
8878
}
8979

90-
func (f *Friendly) printSummary(errors, warnings int) {
80+
func (*Friendly) printSummary(errors, warnings int) {
9181
emoji := getWarningEmoji()
9282
if errors > 0 {
9383
emoji = getErrorEmoji()
@@ -136,7 +126,7 @@ func (f *Friendly) printStatistics(header string, stats map[string]int) {
136126
fmt.Println(f.table(formatted))
137127
}
138128

139-
func (f *Friendly) table(rows [][]string) string {
129+
func (*Friendly) table(rows [][]string) string {
140130
buf := new(bytes.Buffer)
141131
table := tablewriter.NewWriter(buf)
142132
table.SetBorder(false)

formatter/json.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type JSON struct {
1313
}
1414

1515
// Name returns the name of the formatter
16-
func (f *JSON) Name() string {
16+
func (*JSON) Name() string {
1717
return "json"
1818
}
1919

@@ -24,7 +24,7 @@ type jsonObject struct {
2424
}
2525

2626
// Format formats the failures gotten from the lint.
27-
func (f *JSON) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
27+
func (*JSON) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
2828
var slice []jsonObject
2929
for failure := range failures {
3030
obj := jsonObject{}

formatter/ndjson.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ type NDJSON struct {
1414
}
1515

1616
// Name returns the name of the formatter
17-
func (f *NDJSON) Name() string {
17+
func (*NDJSON) Name() string {
1818
return "ndjson"
1919
}
2020

2121
// Format formats the failures gotten from the lint.
22-
func (f *NDJSON) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
22+
func (*NDJSON) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
2323
enc := json.NewEncoder(os.Stdout)
2424
for failure := range failures {
2525
obj := jsonObject{}

formatter/plain.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ type Plain struct {
1313
}
1414

1515
// Name returns the name of the formatter
16-
func (f *Plain) Name() string {
16+
func (*Plain) Name() string {
1717
return "plain"
1818
}
1919

2020
// Format formats the failures gotten from the lint.
21-
func (f *Plain) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) {
21+
func (*Plain) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) {
2222
for failure := range failures {
2323
fmt.Printf("%v: %s %s\n", failure.Position.Start, failure.Failure, "https://revive.run/r#"+failure.RuleName)
2424
}

formatter/sarif.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ type Sarif struct {
1616
}
1717

1818
// Name returns the name of the formatter
19-
func (f *Sarif) Name() string {
19+
func (*Sarif) Name() string {
2020
return "sarif"
2121
}
2222

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

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

2929
for failure := range failures {

formatter/stylish.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type Stylish struct {
1616
}
1717

1818
// Name returns the name of the formatter
19-
func (f *Stylish) Name() string {
19+
func (*Stylish) Name() string {
2020
return "stylish"
2121
}
2222

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

3434
// Format formats the failures gotten from the lint.
35-
func (f *Stylish) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
35+
func (*Stylish) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
3636
var result [][]string
3737
totalErrors := 0
3838
total := 0

formatter/unix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ type Unix struct {
1414
}
1515

1616
// Name returns the name of the formatter
17-
func (f *Unix) Name() string {
17+
func (*Unix) Name() string {
1818
return "unix"
1919
}
2020

2121
// Format formats the failures gotten from the lint.
22-
func (f *Unix) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) {
22+
func (*Unix) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) {
2323
for failure := range failures {
2424
fmt.Printf("%v: [%s] %s\n", failure.Position.Start, failure.RuleName, failure.Failure)
2525
}

lint/file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func (f *File) disabledIntervals(rules []Rule, mustSpecifyDisableReason bool, fa
249249
return getEnabledDisabledIntervals()
250250
}
251251

252-
func (f *File) filterFailures(failures []Failure, disabledIntervals disabledIntervalsMap) []Failure {
252+
func (File) filterFailures(failures []Failure, disabledIntervals disabledIntervalsMap) []Failure {
253253
result := []Failure{}
254254
for _, failure := range failures {
255255
fStart := failure.Position.Start.Line

lint/linter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func addInvalidFileFailure(filename, errStr string, failures chan Failure) {
136136
// errPosRegexp matches with an NewFile error message
137137
// i.e. : corrupted.go:10:4: expected '}', found 'EOF
138138
// first group matches the line and the second group, the column
139-
var errPosRegexp = regexp.MustCompile(".*:(\\d*):(\\d*):.*$")
139+
var errPosRegexp = regexp.MustCompile(`.*:(\d*):(\d*):.*$`)
140140

141141
// getPositionInvalidFile gets the position of the error in an invalid file
142142
func getPositionInvalidFile(filename, s string) FailurePosition {

revivelib/core.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func New(
2828
maxOpenFiles int,
2929
extraRules ...ExtraRule,
3030
) (*Revive, error) {
31-
log, err := logging.GetLogger()
31+
logger, err := logging.GetLogger()
3232
if err != nil {
3333
return nil, errors.Wrap(err, "initializing revive - getting logger")
3434
}
@@ -55,10 +55,10 @@ func New(
5555
return nil, errors.Wrap(err, "initializing revive - gettint lint rules")
5656
}
5757

58-
log.Println("Config loaded")
58+
logger.Println("Config loaded")
5959

6060
return &Revive{
61-
logger: log,
61+
logger: logger,
6262
config: conf,
6363
lintingRules: lintingRules,
6464
maxOpenFiles: maxOpenFiles,

revivelib/core_internal_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ func TestReviveCreateInstance(t *testing.T) {
3939
type mockRule struct {
4040
}
4141

42-
func (r *mockRule) Name() string {
42+
func (*mockRule) Name() string {
4343
return "mock-rule"
4444
}
4545

46-
func (r *mockRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
46+
func (*mockRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
4747
return nil
4848
}
4949

rule/add-constant.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (r *AddConstantRule) Apply(file *lint.File, arguments lint.Arguments) []lin
5555
}
5656

5757
// Name returns the rule name.
58-
func (r *AddConstantRule) Name() string {
58+
func (*AddConstantRule) Name() string {
5959
return "add-constant"
6060
}
6161

rule/argument-limit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (r *ArgumentsLimitRule) Apply(file *lint.File, arguments lint.Arguments) []
4848
}
4949

5050
// Name returns the rule name.
51-
func (r *ArgumentsLimitRule) Name() string {
51+
func (*ArgumentsLimitRule) Name() string {
5252
return "argument-limit"
5353
}
5454

rule/atomic.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
type AtomicRule struct{}
1313

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

2929
// Name returns the rule name.
30-
func (r *AtomicRule) Name() string {
30+
func (*AtomicRule) Name() string {
3131
return "atomic"
3232
}
3333

rule/banned-characters.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (r *BannedCharsRule) Apply(file *lint.File, arguments lint.Arguments) []lin
4545
}
4646

4747
// Name returns the rule name
48-
func (r *BannedCharsRule) Name() string {
48+
func (*BannedCharsRule) Name() string {
4949
return bannedCharsRuleName
5050
}
5151

rule/bare-return.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
type BareReturnRule struct{}
1111

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

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

2525
// Name returns the rule name.
26-
func (r *BareReturnRule) Name() string {
26+
func (*BareReturnRule) Name() string {
2727
return "bare-return"
2828
}
2929

rule/blank-imports.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
type BlankImportsRule struct{}
1212

1313
// Name returns the rule name.
14-
func (r *BlankImportsRule) Name() string {
14+
func (*BlankImportsRule) Name() string {
1515
return "blank-imports"
1616
}
1717

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

65-
func (r *BlankImportsRule) fileHasValidEmbedComment(fileAst *ast.File) bool {
65+
func (*BlankImportsRule) fileHasValidEmbedComment(fileAst *ast.File) bool {
6666
for _, commentGroup := range fileAst.Comments {
6767
for _, comment := range commentGroup.List {
6868
if strings.HasPrefix(comment.Text, "//go:embed ") {

rule/bool-literal-in-expr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
type BoolLiteralRule struct{}
1212

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

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

2828
// Name returns the rule name.
29-
func (r *BoolLiteralRule) Name() string {
29+
func (*BoolLiteralRule) Name() string {
3030
return "bool-literal-in-expr"
3131
}
3232

0 commit comments

Comments
 (0)