Skip to content
This repository has been archived by the owner on May 9, 2021. It is now read-only.

cmd/golint: introduce auto fix option (--fix) #476

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
lint: rename *ast.Ident value automatically when the ident violated…
… name rule on fix mode

When `*ast.Ident` value was fixed, it doesn't show a warning message.
  • Loading branch information
moznion committed Dec 12, 2019
commit 9ceeaa38f1710f96dd9f0dc840a44b4e0de0c390
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
misc/auto_fix_test/auto_fix_given.go
testdata/auto_fix/given.go
12 changes: 9 additions & 3 deletions golint/golint.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
var (
minConfidence = flag.Float64("min_confidence", 0.8, "minimum confidence of a problem to print it")
setExitStatus = flag.Bool("set_exit_status", false, "set exit status to 1 if any issues are found")
shouldFix = flag.Bool("fix", false, "fix automatically if it is possible (this may overwrite warned files)")
isFixMode = flag.Bool("fix", false, "fix automatically if it is possible (this may overwrite warned files)")
suggestions int
)

Expand Down Expand Up @@ -120,7 +120,7 @@ func lintFiles(filenames ...string) {
}

l := new(lint.Linter)
ps, err := l.LintFiles(files)
ps, err := l.LintFiles(files, *isFixMode)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
return
Expand All @@ -131,7 +131,7 @@ func lintFiles(filenames ...string) {
for _, p := range ps {
if p.Confidence >= *minConfidence {
autoFixedMarker := ""
if *shouldFix {
if *isFixMode {
if fixer := p.Fixer; fixer != nil {
if filename := p.Position.Filename; filename != "" {
filenameToSrcAutoFix[filename] = &srcInfoForAutoFix{
Expand All @@ -142,6 +142,12 @@ func lintFiles(filenames ...string) {
}
}
}

if p.OnlyUsedToFix {
// don't show a warning message
continue
}

fmt.Printf("%v: %s%s\n", p.Position, autoFixedMarker, p.Text)
suggestions++
}
Expand Down
Loading