[lint] cmd/golint: introduce auto fix option (--fix)

1,694 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Dec 10, 2019, 9:12:55 AM12/10/19
to Taiki Kawakami, Ian Lance Taylor, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot would like Taiki Kawakami to review this change.

View Change

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

This patch introduces an option to fix pointed out warnings automatically.
This one provides such function partially; actually it has the only naming auto-correction.

To be honest, I'm not confident about how to test this feature, this patch contains a simple shell-script based test as you can see. Could you please tell me if there is a good way?

Ref #214

Change-Id: Idc88bc2080d254997109c01302460310ebce1169
GitHub-Last-Rev: c2b0edc28caf9d7d72158d643a6834ca5c2e8f3b
GitHub-Pull-Request: golang/lint#476
---
A .gitignore
M golint/golint.go
M lint.go
A misc/auto_fix_test/auto_fix_expected.go
A misc/auto_fix_test/auto_fix_given.go.orig
A misc/auto_fix_test/auto_fix_test.sh
6 files changed, 117 insertions(+), 42 deletions(-)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..bcfae75
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+misc/auto_fix_test/auto_fix_given.go
diff --git a/golint/golint.go b/golint/golint.go
index ac024b6..5df1795 100644
--- a/golint/golint.go
+++ b/golint/golint.go
@@ -10,7 +10,10 @@
import (
"flag"
"fmt"
+ "go/ast"
"go/build"
+ "go/format"
+ "go/token"
"io/ioutil"
"os"
"path/filepath"
@@ -22,6 +25,7 @@
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)")
suggestions int
)

@@ -116,12 +120,35 @@
fmt.Fprintf(os.Stderr, "%v\n", err)
return
}
+
+ filenameToReplacedFileAST := make(map[string]*ast.File)
+
for _, p := range ps {
if p.Confidence >= *minConfidence {
- fmt.Printf("%v: %s\n", p.Position, p.Text)
+ autoFixedMarker := ""
+ if *shouldFix {
+ if replacer := p.Fixer; replacer != nil {
+ if filename := p.Position.Filename; filename != "" {
+ filenameToReplacedFileAST[filename] = replacer()
+ autoFixedMarker = "[fixed] "
+ }
+ }
+ }
+ fmt.Printf("%v: %s%s\n", p.Position, autoFixedMarker, p.Text)
suggestions++
}
}
+
+ for filename, astFile := range filenameToReplacedFileAST {
+ func() {
+ file, err := os.Create(filename)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "%v\n", err)
+ return
+ }
+ format.Node(file, token.NewFileSet(), astFile)
+ }()
+ }
}

func lintDir(dirname string) {
diff --git a/lint.go b/lint.go
index 532a75a..8a61d70 100644
--- a/lint.go
+++ b/lint.go
@@ -45,6 +45,10 @@
// If the problem has a suggested fix (the minority case),
// ReplacementLine is a full replacement for the relevant line of the source file.
ReplacementLine string
+
+ // Fixer fixes a warning automatically if it is possible and returns fixed file's AST.
+ // If this field is nil, it does nothing.
+ Fixer func() *ast.File
}

func (p *Problem) String() string {
@@ -218,18 +222,19 @@
// The variadic arguments may start with link and category types,
// and must end with a format string and any arguments.
// It returns the new Problem.
-func (f *file) errorf(n ast.Node, confidence float64, args ...interface{}) *Problem {
+func (f *file) errorf(n ast.Node, confidence float64, fixer func() *ast.File, args ...interface{}) *Problem {
pos := f.fset.Position(n.Pos())
if pos.Filename == "" {
pos.Filename = f.filename
}
- return f.pkg.errorfAt(pos, confidence, args...)
+ return f.pkg.errorfAt(pos, confidence, fixer, args...)
}

-func (p *pkg) errorfAt(pos token.Position, confidence float64, args ...interface{}) *Problem {
+func (p *pkg) errorfAt(pos token.Position, confidence float64, fixer func() *ast.File, args ...interface{}) *Problem {
problem := Problem{
Position: pos,
Confidence: confidence,
+ Fixer: fixer,
}
if pos.Filename != "" {
// The file might not exist in our mapping if a //line directive was encountered.
@@ -407,23 +412,23 @@
Line: endPos.Line + 1,
Column: 1,
}
- f.pkg.errorfAt(pos, 0.9, link(ref), category("comments"), "package comment is detached; there should be no blank lines between it and the package statement")
+ f.pkg.errorfAt(pos, 0.9, nil, link(ref), category("comments"), "package comment is detached; there should be no blank lines between it and the package statement")
return
}
}

if f.f.Doc == nil {
- f.errorf(f.f, 0.2, link(ref), category("comments"), "should have a package comment, unless it's in another file for this package")
+ f.errorf(f.f, 0.2, nil, link(ref), category("comments"), "should have a package comment, unless it's in another file for this package")
return
}
s := f.f.Doc.Text()
if ts := strings.TrimLeft(s, " \t"); ts != s {
- f.errorf(f.f.Doc, 1, link(ref), category("comments"), "package comment should not have leading space")
+ f.errorf(f.f.Doc, 1, nil, link(ref), category("comments"), "package comment should not have leading space")
s = ts
}
// Only non-main packages need to keep to this form.
if !f.pkg.main && !strings.HasPrefix(s, prefix) {
- f.errorf(f.f.Doc, 1, link(ref), category("comments"), `package comment should be of the form "%s..."`, prefix)
+ f.errorf(f.f.Doc, 1, nil, link(ref), category("comments"), `package comment should be of the form "%s..."`, prefix)
}
}

@@ -454,7 +459,7 @@
// This is the first blank import of a group.
if imp.Doc == nil && imp.Comment == nil {
ref := ""
- f.errorf(imp, 1, link(ref), category("imports"), "a blank import should be only in a main or test package, or have a comment justifying it")
+ f.errorf(imp, 1, nil, link(ref), category("imports"), "a blank import should be only in a main or test package, or have a comment justifying it")
}
}
}
@@ -464,7 +469,7 @@
for i, is := range f.f.Imports {
_ = i
if is.Name != nil && is.Name.Name == "." && !f.isTest() {
- f.errorf(is, 1, link(styleGuideBase+"#import-dot"), category("imports"), "should not use dot imports")
+ f.errorf(is, 1, nil, link(styleGuideBase+"#import-dot"), category("imports"), "should not use dot imports")
}

}
@@ -556,10 +561,15 @@
func (f *file) lintNames() {
// Package names need slightly different handling than other names.
if strings.Contains(f.f.Name.Name, "_") && !strings.HasSuffix(f.f.Name.Name, "_test") {
- f.errorf(f.f, 1, link("http://golang.org/doc/effective_go.html#package-names"), category("naming"), "don't use an underscore in package name")
+ f.errorf(f.f, 1, nil, link("http://golang.org/doc/effective_go.html#package-names"), category("naming"), "don't use an underscore in package name")
}
if anyCapsRE.MatchString(f.f.Name.Name) {
- f.errorf(f.f, 1, link("http://golang.org/doc/effective_go.html#package-names"), category("mixed-caps"), "don't use MixedCaps in package name; %s should be %s", f.f.Name.Name, strings.ToLower(f.f.Name.Name))
+ should := strings.ToLower(f.f.Name.Name)
+ fixer := func() *ast.File {
+ f.f.Name.Name = should
+ return f.f
+ }
+ f.errorf(f.f, 1, fixer, link("http://golang.org/doc/effective_go.html#package-names"), category("mixed-caps"), "don't use MixedCaps in package name; %s should be %s", f.f.Name.Name, should)
}

check := func(id *ast.Ident, thing string) {
@@ -579,14 +589,19 @@
}
}
if capCount >= 2 {
- f.errorf(id, 0.8, link(styleGuideBase+"#mixed-caps"), category("naming"), "don't use ALL_CAPS in Go names; use CamelCase")
+ // TODO support auto fixing
+ f.errorf(id, 0.8, nil, link(styleGuideBase+"#mixed-caps"), category("naming"), "don't use ALL_CAPS in Go names; use CamelCase")
return
}
}
if thing == "const" || (thing == "var" && isInTopLevel(f.f, id)) {
if len(id.Name) > 2 && id.Name[0] == 'k' && id.Name[1] >= 'A' && id.Name[1] <= 'Z' {
should := string(id.Name[1]+'a'-'A') + id.Name[2:]
- f.errorf(id, 0.8, link(styleGuideBase+"#mixed-caps"), category("naming"), "don't use leading k in Go names; %s %s should be %s", thing, id.Name, should)
+ fixer := func() *ast.File {
+ id.Name = should
+ return f.f
+ }
+ f.errorf(id, 0.8, fixer, link(styleGuideBase+"#mixed-caps"), category("naming"), "don't use leading k in Go names; %s %s should be %s", thing, id.Name, should)
}
}

@@ -595,11 +610,16 @@
return
}

+ fixer := func() *ast.File {
+ id.Name = should
+ return f.f
+ }
+
if len(id.Name) > 2 && strings.Contains(id.Name[1:], "_") {
- f.errorf(id, 0.9, link("http://golang.org/doc/effective_go.html#mixed-caps"), category("naming"), "don't use underscores in Go names; %s %s should be %s", thing, id.Name, should)
+ f.errorf(id, 0.9, fixer, link("http://golang.org/doc/effective_go.html#mixed-caps"), category("naming"), "don't use underscores in Go names; %s %s should be %s", thing, id.Name, should)
return
}
- f.errorf(id, 0.8, link(styleGuideBase+"#initialisms"), category("naming"), "%s %s should be %s", thing, id.Name, should)
+ f.errorf(id, 0.8, fixer, link(styleGuideBase+"#initialisms"), category("naming"), "%s %s should be %s", thing, id.Name, should)
}
checkList := func(fl *ast.FieldList, thing string) {
if fl == nil {
@@ -816,7 +836,7 @@
return
}
if doc == nil {
- f.errorf(t, 1, link(docCommentsLink), category("comments"), "exported type %v should have comment or be unexported", t.Name)
+ f.errorf(t, 1, nil, link(docCommentsLink), category("comments"), "exported type %v should have comment or be unexported", t.Name)
return
}

@@ -829,7 +849,7 @@
}
}
if !strings.HasPrefix(s, t.Name.Name+" ") {
- f.errorf(doc, 1, link(docCommentsLink), category("comments"), `comment on exported type %v should be of the form "%v ..." (with optional leading article)`, t.Name, t.Name)
+ f.errorf(doc, 1, nil, link(docCommentsLink), category("comments"), `comment on exported type %v should be of the form "%v ..." (with optional leading article)`, t.Name, t.Name)
}
}

@@ -871,13 +891,13 @@
name = recv + "." + name
}
if fn.Doc == nil {
- f.errorf(fn, 1, link(docCommentsLink), category("comments"), "exported %s %s should have comment or be unexported", kind, name)
+ f.errorf(fn, 1, nil, link(docCommentsLink), category("comments"), "exported %s %s should have comment or be unexported", kind, name)
return
}
s := fn.Doc.Text()
prefix := fn.Name.Name + " "
if !strings.HasPrefix(s, prefix) {
- f.errorf(fn.Doc, 1, link(docCommentsLink), category("comments"), `comment on exported %s %s should be of the form "%s..."`, kind, name, prefix)
+ f.errorf(fn.Doc, 1, nil, link(docCommentsLink), category("comments"), `comment on exported %s %s should be of the form "%s..."`, kind, name, prefix)
}
}

@@ -894,7 +914,7 @@
// Check that none are exported except for the first.
for _, n := range vs.Names[1:] {
if ast.IsExported(n.Name) {
- f.errorf(vs, 1, category("comments"), "exported %s %s should have its own declaration", kind, n.Name)
+ f.errorf(vs, 1, nil, category("comments"), "exported %s %s should have its own declaration", kind, n.Name)
return
}
}
@@ -914,7 +934,7 @@
if kind == "const" && gd.Lparen.IsValid() {
block = " (or a comment on this block)"
}
- f.errorf(vs, 1, link(docCommentsLink), category("comments"), "exported %s %s should have comment%s or be unexported", kind, name, block)
+ f.errorf(vs, 1, nil, link(docCommentsLink), category("comments"), "exported %s %s should have comment%s or be unexported", kind, name, block)
genDeclMissingComments[gd] = true
return
}
@@ -930,7 +950,7 @@
}
prefix := name + " "
if !strings.HasPrefix(doc.Text(), prefix) {
- f.errorf(doc, 1, link(docCommentsLink), category("comments"), `comment on exported %s %s should be of the form "%s..."`, kind, name, prefix)
+ f.errorf(doc, 1, nil, link(docCommentsLink), category("comments"), `comment on exported %s %s should be of the form "%s..."`, kind, name, prefix)
}
}

@@ -955,7 +975,7 @@
// the it's starting a new word and thus this name stutters.
rem := name[len(pkg):]
if next, _ := utf8.DecodeRuneInString(rem); next == '_' || unicode.IsUpper(next) {
- f.errorf(id, 0.8, link(styleGuideBase+"#package-names"), category("naming"), "%s name will be used as %s.%s by other packages, and that stutters; consider calling this %s", thing, pkg, name, rem)
+ f.errorf(id, 0.8, nil, link(styleGuideBase+"#package-names"), category("naming"), "%s name will be used as %s.%s by other packages, and that stutters; consider calling this %s", thing, pkg, name, rem)
}
}

@@ -1014,7 +1034,7 @@
if shortDecl {
extra = " (move short variable declaration to its own line if necessary)"
}
- f.errorf(ifStmt.Else, 1, link(styleGuideBase+"#indent-error-flow"), category("indent"), "if block ends with a return statement, so drop this else and outdent its block"+extra)
+ f.errorf(ifStmt.Else, 1, nil, link(styleGuideBase+"#indent-error-flow"), category("indent"), "if block ends with a return statement, so drop this else and outdent its block"+extra)
}
return true
})
@@ -1029,7 +1049,7 @@
}

if isIdent(rs.Key, "_") && (rs.Value == nil || isIdent(rs.Value, "_")) {
- p := f.errorf(rs.Key, 1, category("range-loop"), "should omit values from range; this loop is equivalent to `for range ...`")
+ p := f.errorf(rs.Key, 1, nil, category("range-loop"), "should omit values from range; this loop is equivalent to `for range ...`")

newRS := *rs // shallow copy
newRS.Value = nil
@@ -1040,7 +1060,7 @@
}

if isIdent(rs.Value, "_") {
- p := f.errorf(rs.Value, 1, category("range-loop"), "should omit 2nd value from range; this loop is equivalent to `for %s %s range ...`", f.render(rs.Key), rs.Tok)
+ p := f.errorf(rs.Value, 1, nil, category("range-loop"), "should omit 2nd value from range; this loop is equivalent to `for %s %s range ...`", f.render(rs.Key), rs.Tok)

newRS := *rs // shallow copy
newRS.Value = nil
@@ -1081,7 +1101,7 @@
if isTestingError {
errorfPrefix = f.render(se.X)
}
- p := f.errorf(node, 1, category("errors"), "should replace %s(fmt.Sprintf(...)) with %s.Errorf(...)", f.render(se), errorfPrefix)
+ p := f.errorf(node, 1, nil, category("errors"), "should replace %s(fmt.Sprintf(...)) with %s.Errorf(...)", f.render(se), errorfPrefix)

m := f.srcLineWithMatch(ce, `^(.*)`+f.render(se)+`\(fmt\.Sprintf\((.*)\)\)(.*)$`)
if m != nil {
@@ -1118,7 +1138,7 @@
prefix = "Err"
}
if !strings.HasPrefix(id.Name, prefix) {
- f.errorf(id, 0.9, category("naming"), "error var %s should have name of the form %sFoo", id.Name, prefix)
+ f.errorf(id, 0.9, nil, category("naming"), "error var %s should have name of the form %sFoo", id.Name, prefix)
}
}
}
@@ -1173,8 +1193,7 @@
return true
}

- f.errorf(str, conf, link(styleGuideBase+"#error-strings"), category("errors"),
- "error strings should not be capitalized or end with punctuation or a newline")
+ f.errorf(str, conf, nil, link(styleGuideBase+"#error-strings"), category("errors"), "error strings should not be capitalized or end with punctuation or a newline")
return true
})
}
@@ -1195,16 +1214,16 @@
name := names[0].Name
const ref = styleGuideBase + "#receiver-names"
if name == "_" {
- f.errorf(n, 1, link(ref), category("naming"), `receiver name should not be an underscore, omit the name if it is unused`)
+ f.errorf(n, 1, nil, link(ref), category("naming"), `receiver name should not be an underscore, omit the name if it is unused`)
return true
}
if name == "this" || name == "self" {
- f.errorf(n, 1, link(ref), category("naming"), `receiver name should be a reflection of its identity; don't use generic names such as "this" or "self"`)
+ f.errorf(n, 1, nil, link(ref), category("naming"), `receiver name should be a reflection of its identity; don't use generic names such as "this" or "self"`)
return true
}
recv := receiverType(fn)
if prev, ok := typeReceiver[recv]; ok && prev != name {
- f.errorf(n, 1, link(ref), category("naming"), "receiver name %s should be consistent with previous receiver name %s for %s", name, prev, recv)
+ f.errorf(n, 1, nil, link(ref), category("naming"), "receiver name %s should be consistent with previous receiver name %s for %s", name, prev, recv)
return true
}
typeReceiver[recv] = name
@@ -1235,7 +1254,7 @@
default:
return true
}
- f.errorf(as, 0.8, category("unary-op"), "should replace %s with %s%s", f.render(as), f.render(as.Lhs[0]), suffix)
+ f.errorf(as, 0.8, nil, category("unary-op"), "should replace %s with %s%s", f.render(as), f.render(as.Lhs[0]), suffix)
return true
})
}
@@ -1259,7 +1278,7 @@
// Flag any error parameters found before the last.
for _, r := range ret[:len(ret)-1] {
if isIdent(r.Type, "error") {
- f.errorf(fn, 0.9, category("arg-order"), "error should be the last type when returning multiple items")
+ f.errorf(fn, 0.9, nil, category("arg-order"), "error should be the last type when returning multiple items")
break // only flag one
}
}
@@ -1295,9 +1314,7 @@
if exportedType(typ) {
continue
}
- f.errorf(ret.Type, 0.8, category("unexported-type-in-api"),
- "exported %s %s returns unexported type %s, which can be annoying to use",
- thing, fn.Name.Name, typ)
+ f.errorf(ret.Type, 0.8, nil, category("unexported-type-in-api"), "exported %s %s returns unexported type %s, which can be annoying to use", thing, fn.Name.Name, typ)
break // only flag one
}
return false
@@ -1360,7 +1377,7 @@
if suffix == "" {
continue
}
- f.errorf(v, 0.9, category("time"), "var %s is of type %v; don't use unit-specific suffix %q", name.Name, origTyp, suffix)
+ f.errorf(v, 0.9, nil, category("time"), "var %s is of type %v; don't use unit-specific suffix %q", name.Name, origTyp, suffix)
}
return true
})
@@ -1402,7 +1419,7 @@
key := f.pkg.typesInfo.Types[x.Args[1]]

if ktyp, ok := key.Type.(*types.Basic); ok && ktyp.Kind() != types.Invalid {
- f.errorf(x, 1.0, category("context"), fmt.Sprintf("should not use basic type %s as key in context.WithValue", key.Type))
+ f.errorf(x, 1.0, nil, category("context"), fmt.Sprintf("should not use basic type %s as key in context.WithValue", key.Type))
}
}

@@ -1419,7 +1436,7 @@
// Flag any that show up after the first.
for _, arg := range fn.Type.Params.List[1:] {
if isPkgDot(arg.Type, "context", "Context") {
- f.errorf(fn, 0.9, link("https://golang.org/pkg/context/"), category("arg-order"), "context.Context should be the first parameter of a function")
+ f.errorf(fn, 0.9, nil, link("https://golang.org/pkg/context/"), category("arg-order"), "context.Context should be the first parameter of a function")
break // only flag one
}
}
diff --git a/misc/auto_fix_test/auto_fix_expected.go b/misc/auto_fix_test/auto_fix_expected.go
new file mode 100644
index 0000000..f69886b
--- /dev/null
+++ b/misc/auto_fix_test/auto_fix_expected.go
@@ -0,0 +1,8 @@
+package testtest
+
+const foo = ""
+
+func foo() {
+ const fooBar = ""
+ const isHTTP = false
+}
diff --git a/misc/auto_fix_test/auto_fix_given.go.orig b/misc/auto_fix_test/auto_fix_given.go.orig
new file mode 100644
index 0000000..891c740
--- /dev/null
+++ b/misc/auto_fix_test/auto_fix_given.go.orig
@@ -0,0 +1,8 @@
+package testTest
+
+const kFoo = ""
+
+func foo() {
+ const foo_bar = ""
+ const isHttp = false
+}
diff --git a/misc/auto_fix_test/auto_fix_test.sh b/misc/auto_fix_test/auto_fix_test.sh
new file mode 100755
index 0000000..3e73429
--- /dev/null
+++ b/misc/auto_fix_test/auto_fix_test.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+set -ue
+
+cp ./misc/auto_fix_test/auto_fix_given.go.orig ./misc/auto_fix_test/auto_fix_given.go
+go run ./golint/* --fix -- ./misc/auto_fix_test/auto_fix_given.go
+
+if ! diff ./misc/auto_fix_test/auto_fix_given.go ./misc/auto_fix_test/auto_fix_expected.go; then
+ echo not ok
+ exit 1
+fi
+
+echo ok
+

To view, visit change 210659. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: lint
Gerrit-Branch: master
Gerrit-Change-Id: Idc88bc2080d254997109c01302460310ebce1169
Gerrit-Change-Number: 210659
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-Reviewer: Taiki Kawakami <moz...@gmail.com>
Gerrit-MessageType: newchange

Gerrit Bot (Gerrit)

unread,
Dec 10, 2019, 9:15:25 AM12/10/19
to Taiki Kawakami, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot uploaded patch set #2 to this change.

View Change

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

This patch introduces an option to fix pointed out warnings automatically.
This one provides such function partially; actually it has the only naming auto-correction.

To be honest, I'm not confident about how to test this feature, this patch contains a simple shell-script based test as you can see. Could you please tell me if there is a good way?

Ref #214

Change-Id: Idc88bc2080d254997109c01302460310ebce1169
GitHub-Last-Rev: 00dcd60cc6eaf893088ee938894aef4193ffaf02

GitHub-Pull-Request: golang/lint#476
---
A .gitignore
M golint/golint.go
M lint.go
A misc/auto_fix_test/auto_fix_expected
A misc/auto_fix_test/auto_fix_given.go.orig
A misc/auto_fix_test/auto_fix_test.sh
6 files changed, 117 insertions(+), 42 deletions(-)

To view, visit change 210659. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: lint
Gerrit-Branch: master
Gerrit-Change-Id: Idc88bc2080d254997109c01302460310ebce1169
Gerrit-Change-Number: 210659
Gerrit-PatchSet: 2
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-Reviewer: Taiki Kawakami <moz...@gmail.com>
Gerrit-MessageType: newpatchset

Gerrit Bot (Gerrit)

unread,
Dec 12, 2019, 11:09:11 AM12/12/19
to Taiki Kawakami, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot uploaded patch set #3 to this change.

View Change

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

This patch introduces an option to fix pointed out warnings automatically.
This one provides such function partially; actually it has the only naming auto-correction.

To be honest, I'm not confident about how to test this feature, this patch contains a simple shell-script based test as you can see. Could you please tell me if there is a good way?

Ref #214

Change-Id: Idc88bc2080d254997109c01302460310ebce1169
GitHub-Last-Rev: 86ac9149668b2514f199ad5a0126a94c5176d0d8

GitHub-Pull-Request: golang/lint#476
---
A .gitignore
M golint/golint.go
M lint.go
M lint_test.go
A testdata/auto_fix/expected.go
5 files changed, 329 insertions(+), 68 deletions(-)

To view, visit change 210659. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: lint
Gerrit-Branch: master
Gerrit-Change-Id: Idc88bc2080d254997109c01302460310ebce1169
Gerrit-Change-Number: 210659
Gerrit-PatchSet: 3
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-Reviewer: Taiki Kawakami <moz...@gmail.com>
Gerrit-MessageType: newpatchset

Gerrit Bot (Gerrit)

unread,
Dec 12, 2019, 11:10:34 AM12/12/19
to Taiki Kawakami, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot uploaded patch set #4 to this change.

View Change

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

This patch introduces an option to fix pointed out warnings automatically.
This one provides such function partially; actually it has the only naming auto-correction.

~To be honest, I'm not confident about how to test this feature, this patch contains a simple shell-script based test as you can see. Could you please tell me if there is a good way?~

Update: I wrote a test case to check the behavior of auto-fix mode at 86ac9149668b2514f199ad5a0126a94c5176d0d8

Ref #214

Change-Id: Idc88bc2080d254997109c01302460310ebce1169
GitHub-Last-Rev: 86ac9149668b2514f199ad5a0126a94c5176d0d8

GitHub-Pull-Request: golang/lint#476
---
A .gitignore
M golint/golint.go
M lint.go
M lint_test.go
A testdata/auto_fix/expected.go
5 files changed, 329 insertions(+), 68 deletions(-)

To view, visit change 210659. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: lint
Gerrit-Branch: master
Gerrit-Change-Id: Idc88bc2080d254997109c01302460310ebce1169
Gerrit-Change-Number: 210659
Gerrit-PatchSet: 4
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-Reviewer: Taiki Kawakami <moz...@gmail.com>
Gerrit-MessageType: newpatchset

Gerrit Bot (Gerrit)

unread,
Dec 12, 2019, 11:45:06 AM12/12/19
to Taiki Kawakami, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot uploaded patch set #5 to this change.

View Change

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

This patch introduces an option to fix pointed out warnings automatically.
This one provides such function partially; actually it has the only naming auto-correction.

~To be honest, I'm not confident about how to test this feature, this patch contains a simple shell-script based test as you can see. Could you please tell me if there is a good way?~

Update: I wrote a test case to check the behavior of auto-fix mode at 86ac9149668b2514f199ad5a0126a94c5176d0d8

Ref #214

Change-Id: Idc88bc2080d254997109c01302460310ebce1169
GitHub-Last-Rev: 9ceeaa38f1710f96dd9f0dc840a44b4e0de0c390

GitHub-Pull-Request: golang/lint#476
---
A .gitignore
M golint/golint.go
M lint.go
M lint_test.go
A testdata/auto_fix/expected.go
5 files changed, 338 insertions(+), 68 deletions(-)

To view, visit change 210659. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: lint
Gerrit-Branch: master
Gerrit-Change-Id: Idc88bc2080d254997109c01302460310ebce1169
Gerrit-Change-Number: 210659
Gerrit-PatchSet: 5
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-Reviewer: Taiki Kawakami <moz...@gmail.com>
Gerrit-MessageType: newpatchset

Gerrit Bot (Gerrit)

unread,
Dec 13, 2019, 2:12:55 AM12/13/19
to Taiki Kawakami, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot uploaded patch set #6 to this change.

View Change

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

This patch introduces an option to fix pointed out warnings automatically.
This one provides such function partially; actually it has the only naming auto-correction.

~To be honest, I'm not confident about how to test this feature, this patch contains a simple shell-script based test as you can see. Could you please tell me if there is a good way?~

Update: I wrote a test case to check the behavior of auto-fix mode at 86ac9149668b2514f199ad5a0126a94c5176d0d8

It can fix like so:
https://github.com/golang/lint/blob/9ceeaa38f1710f96dd9f0dc840a44b4e0de0c390/testdata/names.go
=>
https://github.com/golang/lint/blob/9ceeaa38f1710f96dd9f0dc840a44b4e0de0c390/testdata/auto_fix/expected.go

Ref #214

Change-Id: Idc88bc2080d254997109c01302460310ebce1169
GitHub-Last-Rev: 9ceeaa38f1710f96dd9f0dc840a44b4e0de0c390

GitHub-Pull-Request: golang/lint#476
---
A .gitignore
M golint/golint.go
M lint.go
M lint_test.go
A testdata/auto_fix/expected.go
5 files changed, 338 insertions(+), 68 deletions(-)

To view, visit change 210659. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: lint
Gerrit-Branch: master
Gerrit-Change-Id: Idc88bc2080d254997109c01302460310ebce1169
Gerrit-Change-Number: 210659
Gerrit-PatchSet: 6
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-Reviewer: Taiki Kawakami <moz...@gmail.com>
Gerrit-MessageType: newpatchset

Gerrit Bot (Gerrit)

unread,
Dec 14, 2019, 5:57:40 AM12/14/19
to Taiki Kawakami, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot uploaded patch set #7 to this change.

View Change

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

This patch introduces an option to fix pointed out warnings automatically.
This one provides such function partially; actually it has the only naming auto-correction.

~To be honest, I'm not confident about how to test this feature, this patch contains a simple shell-script based test as you can see. Could you please tell me if there is a good way?~

Update: I wrote a test case to check the behavior of auto-fix mode at 86ac9149668b2514f199ad5a0126a94c5176d0d8

It can fix like so:
https://github.com/golang/lint/blob/9ceeaa38f1710f96dd9f0dc840a44b4e0de0c390/testdata/names.go
=>
https://github.com/golang/lint/blob/9ceeaa38f1710f96dd9f0dc840a44b4e0de0c390/testdata/auto_fix/expected.go

Ref #214

Change-Id: Idc88bc2080d254997109c01302460310ebce1169
GitHub-Last-Rev: 601803c91bf977cffb78dbfd6027b47e710b1cda

GitHub-Pull-Request: golang/lint#476
---
A .gitignore
M golint/golint.go
M lint.go
M lint_test.go
A testdata/auto_fix/expected.go
5 files changed, 355 insertions(+), 68 deletions(-)

To view, visit change 210659. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: lint
Gerrit-Branch: master
Gerrit-Change-Id: Idc88bc2080d254997109c01302460310ebce1169
Gerrit-Change-Number: 210659
Gerrit-PatchSet: 7
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-Reviewer: Taiki Kawakami <moz...@gmail.com>
Gerrit-MessageType: newpatchset

Daniel Martí (Gerrit)

unread,
May 8, 2021, 4:29:47 PM5/8/21
to Gerrit Bot, Taiki Kawakami, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Daniel Martí abandoned this change.

View Change

Abandoned Thank you for submitting this patch! As proposed[1], we are freezing and deprecating golint. There's no drop-in replacement to golint per se, but you should find that Staticcheck[2] works well in encouraging good Go code, much like golint did in the past, since it also includes style checks. There's always gofmt and "go vet" too, of course. If you would like to contribute further, I'd encourage you to engage Staticcheck's issue tracker[3] or look at vet's open issues[4], as they are both actively maintained. If you have an idea that doesn't fit into either of those tools, you could look at other Go linters[5], or write your own - these days it's fairly straightforward with go/analysis[6]. To help avoid confusion, I'm closing all CLs before we freeze the repository. If you have any feedback, you can leave a comment on the proposal thread where it was decided to deprecate golint - though note that the proposal has been accepted for nearly a year. Thanks! [1] https://github.com/golang/go/issues/38968 [2] https://staticcheck.io/ [3] https://github.com/dominikh/go-tools/issues [4] https://github.com/golang/go/issues?q=is%3Aissue+is%3Aopen+cmd%2Fvet+in%3Atitle [5] https://github.com/golangci/awesome-go-linters [6] https://pkg.go.dev/golang.org/x/tools/go/analysis

To view, visit change 210659. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: lint
Gerrit-Branch: master
Gerrit-Change-Id: Idc88bc2080d254997109c01302460310ebce1169
Gerrit-Change-Number: 210659
Gerrit-PatchSet: 7
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-Reviewer: Taiki Kawakami <moz...@gmail.com>
Gerrit-MessageType: abandon
Reply all
Reply to author
Forward
0 new messages