diff --git a/formatter/cli_formatter.go b/formatter/cli_formatter.go index e346f52..a51959f 100644 --- a/formatter/cli_formatter.go +++ b/formatter/cli_formatter.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/fatih/color" - "github.com/mgechev/revive/linter" + "github.com/mgechev/revive/lint" "github.com/olekukonko/tablewriter" ) @@ -17,35 +17,35 @@ const ( // CLIFormatter is an implementation of the Formatter interface // which formats the errors to JSON. type CLIFormatter struct { - Metadata linter.FormatterMetadata + Metadata lint.FormatterMetadata } -func formatFailure(failure linter.Failure, severity linter.Severity) []string { +func formatFailure(failure lint.Failure, severity lint.Severity) []string { fString := color.BlueString(failure.Failure) fTypeStr := string(severity) fType := color.RedString(fTypeStr) lineColumn := failure.Position pos := fmt.Sprintf("(%d, %d)", lineColumn.Start.Line, lineColumn.Start.Column) - if severity == linter.SeverityWarning { + if severity == lint.SeverityWarning { fType = color.YellowString(fTypeStr) } return []string{failure.GetFilename(), pos, fType, fString} } -// Format formats the failures gotten from the linter. -func (f *CLIFormatter) Format(failures <-chan linter.Failure, config linter.RulesConfig) (string, error) { +// Format formats the failures gotten from the lint. +func (f *CLIFormatter) Format(failures <-chan lint.Failure, config lint.RulesConfig) (string, error) { var result [][]string var totalErrors = 0 var total = 0 for f := range failures { total++ - currentType := linter.SeverityWarning - if config, ok := config[f.RuleName]; ok && config.Severity == linter.SeverityError { - currentType = linter.SeverityError + currentType := lint.SeverityWarning + if config, ok := config[f.RuleName]; ok && config.Severity == lint.SeverityError { + currentType = lint.SeverityError totalErrors++ } - result = append(result, formatFailure(f, linter.Severity(currentType))) + result = append(result, formatFailure(f, lint.Severity(currentType))) } ps := "problems" if total == 1 { diff --git a/formatter/json_formatter.go b/formatter/json_formatter.go index 32b7a39..ea88dad 100644 --- a/formatter/json_formatter.go +++ b/formatter/json_formatter.go @@ -3,18 +3,18 @@ package formatter import ( "encoding/json" - "github.com/mgechev/revive/linter" + "github.com/mgechev/revive/lint" ) // JSONFormatter is an implementation of the Formatter interface // which formats the errors to JSON. type JSONFormatter struct { - Metadata linter.FormatterMetadata + Metadata lint.FormatterMetadata } -// Format formats the failures gotten from the linter. -func (f *JSONFormatter) Format(failures <-chan linter.Failure, config linter.RulesConfig) (string, error) { - var slice []linter.Failure +// Format formats the failures gotten from the lint. +func (f *JSONFormatter) Format(failures <-chan lint.Failure, config lint.RulesConfig) (string, error) { + var slice []lint.Failure for failure := range failures { slice = append(slice, failure) } diff --git a/linter/file.go b/lint/file.go similarity index 99% rename from linter/file.go rename to lint/file.go index 29c52a5..72777a6 100644 --- a/linter/file.go +++ b/lint/file.go @@ -1,4 +1,4 @@ -package linter +package lint import ( "bytes" diff --git a/linter/formatter.go b/lint/formatter.go similarity index 94% rename from linter/formatter.go rename to lint/formatter.go index 3344e97..448a107 100644 --- a/linter/formatter.go +++ b/lint/formatter.go @@ -1,4 +1,4 @@ -package linter +package lint // FormatterMetadata configuration of a formatter type FormatterMetadata struct { diff --git a/linter/linter.go b/lint/linter.go similarity index 96% rename from linter/linter.go rename to lint/linter.go index c114662..f8e179b 100644 --- a/linter/linter.go +++ b/lint/linter.go @@ -1,4 +1,4 @@ -package linter +package lint import ( "bufio" @@ -29,7 +29,7 @@ var ( // isGenerated reports whether the source file is generated code // according the rules from https://golang.org/s/generatedcode. -// This is inherited from the original go linter. +// This is inherited from the original go lint. func isGenerated(src []byte) bool { sc := bufio.NewScanner(bytes.NewReader(src)) for sc.Scan() { diff --git a/linter/package.go b/lint/package.go similarity index 99% rename from linter/package.go rename to lint/package.go index ad082fc..796b0d4 100644 --- a/linter/package.go +++ b/lint/package.go @@ -1,4 +1,4 @@ -package linter +package lint import ( "go/ast" diff --git a/linter/rule.go b/lint/rule.go similarity index 99% rename from linter/rule.go rename to lint/rule.go index f282737..ebfbaca 100644 --- a/linter/rule.go +++ b/lint/rule.go @@ -1,4 +1,4 @@ -package linter +package lint import ( "go/ast" diff --git a/linter/utils.go b/lint/utils.go similarity index 95% rename from linter/utils.go rename to lint/utils.go index 3beebb5..c9e83e5 100644 --- a/linter/utils.go +++ b/lint/utils.go @@ -1,12 +1,12 @@ -package linter +package lint import ( "strings" "unicode" ) -// LintName returns a different name if it should be different. -func LintName(name string) (should string) { +// Name returns a different name if it should be different. +func Name(name string) (should string) { // Fast path for simple cases: "_" and all lowercase. if name == "_" { return name diff --git a/main.go b/main.go index c37c0ec..ad6c769 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ import ( "os" "github.com/mgechev/revive/formatter" - "github.com/mgechev/revive/linter" + "github.com/mgechev/revive/lint" "github.com/mgechev/revive/rule" ) @@ -26,16 +26,16 @@ func main() { } ` - revive := linter.New(func(file string) ([]byte, error) { + revive := lint.New(func(file string) ([]byte, error) { return []byte(src), nil }) - var result []linter.Rule + var result []lint.Rule result = append(result, &rule.LintElseRule{}, &rule.ArgumentsLimitRule{}, &rule.NamesRule{}) - var config = linter.RulesConfig{ - "argument-limit": linter.RuleConfig{ + var config = lint.RulesConfig{ + "argument-limit": lint.RuleConfig{ Arguments: []string{"3"}, - Severity: linter.SeverityWarning, + Severity: lint.SeverityWarning, }, } @@ -44,7 +44,7 @@ func main() { panic(err) } - formatChan := make(chan linter.Failure) + formatChan := make(chan lint.Failure) exitChan := make(chan bool) var output string @@ -59,7 +59,7 @@ func main() { exitCode := 0 for f := range failures { - if c, ok := config[f.RuleName]; ok && c.Severity == linter.SeverityError { + if c, ok := config[f.RuleName]; ok && c.Severity == lint.SeverityError { exitCode = 1 } formatChan <- f diff --git a/rule/argument-limit.go b/rule/argument-limit.go index ee71762..3bb2051 100644 --- a/rule/argument-limit.go +++ b/rule/argument-limit.go @@ -5,14 +5,14 @@ import ( "go/ast" "strconv" - "github.com/mgechev/revive/linter" + "github.com/mgechev/revive/lint" ) // ArgumentsLimitRule lints given else constructs. type ArgumentsLimitRule struct{} // Apply applies the rule to given file. -func (r *ArgumentsLimitRule) Apply(file *linter.File, arguments linter.Arguments) []linter.Failure { +func (r *ArgumentsLimitRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { if len(arguments) != 1 { panic(`invalid configuration for "argument-limit"`) } @@ -21,11 +21,11 @@ func (r *ArgumentsLimitRule) Apply(file *linter.File, arguments linter.Arguments panic(`invalid configuration for "argument-limit"`) } - var failures []linter.Failure + var failures []lint.Failure walker := lintArgsNum{ total: total, - onFailure: func(failure linter.Failure) { + onFailure: func(failure lint.Failure) { failures = append(failures, failure) }, } @@ -42,7 +42,7 @@ func (r *ArgumentsLimitRule) Name() string { type lintArgsNum struct { total int64 - onFailure func(linter.Failure) + onFailure func(lint.Failure) } func (w lintArgsNum) Visit(n ast.Node) ast.Visitor { @@ -50,7 +50,7 @@ func (w lintArgsNum) Visit(n ast.Node) ast.Visitor { if ok { num := int64(len(node.Type.Params.List)) if num > w.total { - w.onFailure(linter.Failure{ + w.onFailure(lint.Failure{ Failure: fmt.Sprintf("maximum number of arguments per function exceeded; max %d but got %d", w.total, num), Node: node.Type, }) diff --git a/rule/blank-imports.go b/rule/blank-imports.go index 8341ff4..bd3ed1b 100644 --- a/rule/blank-imports.go +++ b/rule/blank-imports.go @@ -3,21 +3,21 @@ package rule import ( "go/ast" - "github.com/mgechev/revive/linter" + "github.com/mgechev/revive/lint" ) // BlankImportsRule lints given else constructs. type BlankImportsRule struct{} // Apply applies the rule to given file. -func (r *BlankImportsRule) Apply(file *linter.File, arguments linter.Arguments) []linter.Failure { - var failures []linter.Failure +func (r *BlankImportsRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { + var failures []lint.Failure fileAst := file.AST walker := lintBlankImports{ file: file, fileAst: fileAst, - onFailure: func(failure linter.Failure) { + onFailure: func(failure lint.Failure) { failures = append(failures, failure) }, } @@ -34,8 +34,8 @@ func (r *BlankImportsRule) Name() string { type lintBlankImports struct { fileAst *ast.File - file *linter.File - onFailure func(linter.Failure) + file *lint.File + onFailure func(lint.Failure) } func (w lintBlankImports) Visit(n ast.Node) ast.Visitor { @@ -62,7 +62,7 @@ func (w lintBlankImports) Visit(n ast.Node) ast.Visitor { // This is the first blank import of a group. if imp.Doc == nil && imp.Comment == nil { - w.onFailure(linter.Failure{ + w.onFailure(lint.Failure{ Node: imp, Failure: "a blank import should be only in a main or test package, or have a comment justifying it", Confidence: 1, diff --git a/rule/dot-imports.go b/rule/dot-imports.go index 5f49bea..bd625c5 100644 --- a/rule/dot-imports.go +++ b/rule/dot-imports.go @@ -3,21 +3,21 @@ package rule import ( "go/ast" - "github.com/mgechev/revive/linter" + "github.com/mgechev/revive/lint" ) // DotImportsRule lints given else constructs. type DotImportsRule struct{} // Apply applies the rule to given file. -func (r *DotImportsRule) Apply(file *linter.File, arguments linter.Arguments) []linter.Failure { - var failures []linter.Failure +func (r *DotImportsRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { + var failures []lint.Failure fileAst := file.AST walker := lintImports{ file: file, fileAst: fileAst, - onFailure: func(failure linter.Failure) { + onFailure: func(failure lint.Failure) { failures = append(failures, failure) }, } @@ -33,16 +33,16 @@ func (r *DotImportsRule) Name() string { } type lintImports struct { - file *linter.File + file *lint.File fileAst *ast.File - onFailure func(linter.Failure) + onFailure func(lint.Failure) } func (w lintImports) Visit(n ast.Node) ast.Visitor { for i, is := range w.fileAst.Imports { _ = i if is.Name != nil && is.Name.Name == "." && !w.file.IsTest() { - w.onFailure(linter.Failure{ + w.onFailure(lint.Failure{ Confidence: 1, Failure: "should not use dot imports", Node: is, diff --git a/rule/exported.go b/rule/exported.go index 7f007cc..880755e 100644 --- a/rule/exported.go +++ b/rule/exported.go @@ -8,15 +8,15 @@ import ( "unicode" "unicode/utf8" - "github.com/mgechev/revive/linter" + "github.com/mgechev/revive/lint" ) // ExportedRule lints given else constructs. type ExportedRule struct{} // Apply applies the rule to given file. -func (r *ExportedRule) Apply(file *linter.File, arguments linter.Arguments) []linter.Failure { - var failures []linter.Failure +func (r *ExportedRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { + var failures []lint.Failure if isTest(file) { return failures @@ -26,7 +26,7 @@ func (r *ExportedRule) Apply(file *linter.File, arguments linter.Arguments) []li walker := lintExported{ file: file, fileAst: fileAst, - onFailure: func(failure linter.Failure) { + onFailure: func(failure lint.Failure) { failures = append(failures, failure) }, genDeclMissingComments: make(map[*ast.GenDecl]bool), @@ -43,11 +43,11 @@ func (r *ExportedRule) Name() string { } type lintExported struct { - file *linter.File + file *lint.File fileAst *ast.File lastGen *ast.GenDecl genDeclMissingComments map[*ast.GenDecl]bool - onFailure func(linter.Failure) + onFailure func(lint.Failure) } func (w *lintExported) lintFuncDoc(fn *ast.FuncDecl) { @@ -77,7 +77,7 @@ func (w *lintExported) lintFuncDoc(fn *ast.FuncDecl) { name = recv + "." + name } if fn.Doc == nil { - w.onFailure(linter.Failure{ + w.onFailure(lint.Failure{ Node: fn, Confidence: 1, URL: "#doc-comments", @@ -89,7 +89,7 @@ func (w *lintExported) lintFuncDoc(fn *ast.FuncDecl) { s := fn.Doc.Text() prefix := fn.Name.Name + " " if !strings.HasPrefix(s, prefix) { - w.onFailure(linter.Failure{ + w.onFailure(lint.Failure{ Node: fn.Doc, Confidence: 0.8, URL: "#doc-comments", @@ -120,7 +120,7 @@ func (w *lintExported) checkStutter(id *ast.Ident, thing string) { // 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) { - w.onFailure(linter.Failure{ + w.onFailure(lint.Failure{ Node: id, Confidence: 0.8, URL: "#package-names", @@ -135,7 +135,7 @@ func (w *lintExported) lintTypeDoc(t *ast.TypeSpec, doc *ast.CommentGroup) { return } if doc == nil { - w.onFailure(linter.Failure{ + w.onFailure(lint.Failure{ Node: t, Confidence: 1, URL: "#doc-comments", @@ -154,7 +154,7 @@ func (w *lintExported) lintTypeDoc(t *ast.TypeSpec, doc *ast.CommentGroup) { } } if !strings.HasPrefix(s, t.Name.Name+" ") { - w.onFailure(linter.Failure{ + w.onFailure(lint.Failure{ Node: doc, Confidence: 1, URL: "#doc-comments", @@ -174,7 +174,7 @@ func (w *lintExported) lintValueSpecDoc(vs *ast.ValueSpec, gd *ast.GenDecl, genD // Check that none are exported except for the first. for _, n := range vs.Names[1:] { if ast.IsExported(n.Name) { - w.onFailure(linter.Failure{ + w.onFailure(lint.Failure{ Category: "comments", Confidence: 1, Failure: fmt.Sprintf("exported %s %s should have its own declaration", kind, n.Name), @@ -199,7 +199,7 @@ func (w *lintExported) lintValueSpecDoc(vs *ast.ValueSpec, gd *ast.GenDecl, genD if kind == "const" && gd.Lparen.IsValid() { block = " (or a comment on this block)" } - w.onFailure(linter.Failure{ + w.onFailure(lint.Failure{ Confidence: 1, Node: vs, URL: "#doc-comments", @@ -221,7 +221,7 @@ func (w *lintExported) lintValueSpecDoc(vs *ast.ValueSpec, gd *ast.GenDecl, genD } prefix := name + " " if !strings.HasPrefix(doc.Text(), prefix) { - w.onFailure(linter.Failure{ + w.onFailure(lint.Failure{ Confidence: 1, Node: doc, URL: "#doc-comments", diff --git a/rule/names.go b/rule/names.go index b15d7cb..8486a65 100644 --- a/rule/names.go +++ b/rule/names.go @@ -6,15 +6,15 @@ import ( "go/token" "strings" - "github.com/mgechev/revive/linter" + "github.com/mgechev/revive/lint" ) // NamesRule lints given else constructs. type NamesRule struct{} // Apply applies the rule to given file. -func (r *NamesRule) Apply(file *linter.File, arguments linter.Arguments) []linter.Failure { - var failures []linter.Failure +func (r *NamesRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { + var failures []lint.Failure if isTest(file) { return failures @@ -24,14 +24,14 @@ func (r *NamesRule) Apply(file *linter.File, arguments linter.Arguments) []linte walker := lintNames{ file: file, fileAst: fileAst, - onFailure: func(failure linter.Failure) { + onFailure: func(failure lint.Failure) { failures = append(failures, failure) }, } // Package names need slightly different handling than other names. if strings.Contains(walker.fileAst.Name.Name, "_") && !strings.HasSuffix(walker.fileAst.Name.Name, "_test") { - walker.onFailure(linter.Failure{ + walker.onFailure(lint.Failure{ Failure: "don't use an underscore in package name", Confidence: 1, Node: walker.fileAst, @@ -71,7 +71,7 @@ func check(id *ast.Ident, thing string, w *lintNames) { // Handle two common styles from other languages that don't belong in Go. if len(id.Name) >= 5 && allCapsRE.MatchString(id.Name) && strings.Contains(id.Name, "_") { - w.onFailure(linter.Failure{ + w.onFailure(lint.Failure{ Failure: "don't use ALL_CAPS in Go names; use CamelCase", Confidence: 0.8, Node: id, @@ -82,7 +82,7 @@ func check(id *ast.Ident, thing string, w *lintNames) { } 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:] - w.onFailure(linter.Failure{ + w.onFailure(lint.Failure{ Failure: fmt.Sprintf("don't use leading k in Go names; %s %s should be %s", thing, id.Name, should), Confidence: 0.8, Node: id, @@ -91,13 +91,13 @@ func check(id *ast.Ident, thing string, w *lintNames) { }) } - should := linter.LintName(id.Name) + should := lint.Name(id.Name) if id.Name == should { return } if len(id.Name) > 2 && strings.Contains(id.Name[1:], "_") { - w.onFailure(linter.Failure{ + w.onFailure(lint.Failure{ Failure: fmt.Sprintf("don't use underscores in Go names; %s %s should be %s", thing, id.Name, should), Confidence: 0.9, Node: id, @@ -106,7 +106,7 @@ func check(id *ast.Ident, thing string, w *lintNames) { }) return } - w.onFailure(linter.Failure{ + w.onFailure(lint.Failure{ Failure: fmt.Sprintf("%s %s should be %s", thing, id.Name, should), Confidence: 0.8, Node: id, @@ -116,11 +116,11 @@ func check(id *ast.Ident, thing string, w *lintNames) { } type lintNames struct { - file *linter.File + file *lint.File fileAst *ast.File lastGen *ast.GenDecl genDeclMissingComments map[*ast.GenDecl]bool - onFailure func(linter.Failure) + onFailure func(lint.Failure) } func (w *lintNames) Visit(n ast.Node) ast.Visitor { diff --git a/rule/no-else-return.go b/rule/no-else-return.go index f23748e..33cd52b 100644 --- a/rule/no-else-return.go +++ b/rule/no-else-return.go @@ -4,17 +4,17 @@ import ( "go/ast" "go/token" - "github.com/mgechev/revive/linter" + "github.com/mgechev/revive/lint" ) // LintElseRule lints given else constructs. type LintElseRule struct{} // Apply applies the rule to given file. -func (r *LintElseRule) Apply(file *linter.File, arguments linter.Arguments) []linter.Failure { - var failures []linter.Failure +func (r *LintElseRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { + var failures []lint.Failure - onFailure := func(failure linter.Failure) { + onFailure := func(failure lint.Failure) { failures = append(failures, failure) } @@ -30,7 +30,7 @@ func (r *LintElseRule) Name() string { type lintElse struct { ignore map[*ast.IfStmt]bool - onFailure func(linter.Failure) + onFailure func(lint.Failure) } func (w lintElse) Visit(node ast.Node) ast.Visitor { @@ -64,7 +64,7 @@ func (w lintElse) Visit(node ast.Node) ast.Visitor { if shortDecl { extra = " (move short variable declaration to its own line if necessary)" } - w.onFailure(linter.Failure{ + w.onFailure(lint.Failure{ Failure: "if block ends with a return statement, so drop this else and outdent its block" + extra, Node: ifStmt.Else, }) diff --git a/rule/package-comments.go b/rule/package-comments.go index a567b61..5a473dd 100644 --- a/rule/package-comments.go +++ b/rule/package-comments.go @@ -6,7 +6,7 @@ import ( "go/token" "strings" - "github.com/mgechev/revive/linter" + "github.com/mgechev/revive/lint" ) // PackageCommentsRule lints the package comments. It complains if @@ -17,14 +17,14 @@ import ( type PackageCommentsRule struct{} // Apply applies the rule to given file. -func (r *PackageCommentsRule) Apply(file *linter.File, arguments linter.Arguments) []linter.Failure { - var failures []linter.Failure +func (r *PackageCommentsRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { + var failures []lint.Failure if isTest(file) { return failures } - onFailure := func(failure linter.Failure) { + onFailure := func(failure lint.Failure) { failures = append(failures, failure) } @@ -41,8 +41,8 @@ func (r *PackageCommentsRule) Name() string { type lintPackageComments struct { fileAst *ast.File - file *linter.File - onFailure func(linter.Failure) + file *lint.File + onFailure func(lint.Failure) } func (l *lintPackageComments) Visit(n ast.Node) ast.Visitor { @@ -76,9 +76,9 @@ func (l *lintPackageComments) Visit(n ast.Node) ast.Visitor { Line: endPos.Line + 1, Column: 1, } - l.onFailure(linter.Failure{ + l.onFailure(lint.Failure{ Category: "comments", - Position: linter.FailurePosition{ + Position: lint.FailurePosition{ Start: pos, End: pos, }, @@ -91,7 +91,7 @@ func (l *lintPackageComments) Visit(n ast.Node) ast.Visitor { } if l.fileAst.Doc == nil { - l.onFailure(linter.Failure{ + l.onFailure(lint.Failure{ Category: "comments", Node: l.fileAst, Confidence: 0.2, @@ -102,7 +102,7 @@ func (l *lintPackageComments) Visit(n ast.Node) ast.Visitor { } s := l.fileAst.Doc.Text() if ts := strings.TrimLeft(s, " \t"); ts != s { - l.onFailure(linter.Failure{ + l.onFailure(lint.Failure{ Category: "comments", Node: l.fileAst.Doc, Confidence: 1, @@ -113,7 +113,7 @@ func (l *lintPackageComments) Visit(n ast.Node) ast.Visitor { } // Only non-main packages need to keep to this form. if !l.file.Pkg.IsMain() && !strings.HasPrefix(s, prefix) { - l.onFailure(linter.Failure{ + l.onFailure(lint.Failure{ Category: "comments", Node: l.fileAst.Doc, Confidence: 1, diff --git a/rule/ranges.go b/rule/ranges.go index 20af4b2..f8cebe8 100644 --- a/rule/ranges.go +++ b/rule/ranges.go @@ -4,17 +4,17 @@ import ( "fmt" "go/ast" - "github.com/mgechev/revive/linter" + "github.com/mgechev/revive/lint" ) // LintRangesRule lints given else constructs. type LintRangesRule struct{} // Apply applies the rule to given file. -func (r *LintRangesRule) Apply(file *linter.File, arguments linter.Arguments) []linter.Failure { - var failures []linter.Failure +func (r *LintRangesRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { + var failures []lint.Failure - onFailure := func(failure linter.Failure) { + onFailure := func(failure lint.Failure) { failures = append(failures, failure) } @@ -29,8 +29,8 @@ func (r *LintRangesRule) Name() string { } type lintRanges struct { - file *linter.File - onFailure func(linter.Failure) + file *lint.File + onFailure func(lint.Failure) } func (w *lintRanges) Visit(node ast.Node) ast.Visitor { @@ -47,7 +47,7 @@ func (w *lintRanges) Visit(node ast.Node) ast.Visitor { return w } - w.onFailure(linter.Failure{ + w.onFailure(lint.Failure{ Failure: fmt.Sprintf("should omit 2nd value from range; this loop is equivalent to `for %s %s range ...`", w.file.Render(rs.Key), rs.Tok), Confidence: 1, Node: rs.Value, diff --git a/rule/utils.go b/rule/utils.go index 42309a6..b8574b5 100644 --- a/rule/utils.go +++ b/rule/utils.go @@ -7,7 +7,7 @@ import ( "regexp" "strings" - "github.com/mgechev/revive/linter" + "github.com/mgechev/revive/lint" ) const styleGuideBase = "https://golang.org/wiki/CodeReviewComments" @@ -16,7 +16,7 @@ const styleGuideBase = "https://golang.org/wiki/CodeReviewComments" // If id == nil, the answer is false. func isBlank(id *ast.Ident) bool { return id != nil && id.Name == "_" } -func isTest(f *linter.File) bool { +func isTest(f *lint.File) bool { return strings.HasSuffix(f.Name, "_test.go") } diff --git a/rule/var-declarations.go b/rule/var-declarations.go index d2f2ff2..1266517 100644 --- a/rule/var-declarations.go +++ b/rule/var-declarations.go @@ -6,21 +6,21 @@ import ( "go/token" "go/types" - "github.com/mgechev/revive/linter" + "github.com/mgechev/revive/lint" ) // VarDeclarationsRule lints given else constructs. type VarDeclarationsRule struct{} // Apply applies the rule to given file. -func (r *VarDeclarationsRule) Apply(file *linter.File, arguments linter.Arguments) []linter.Failure { - var failures []linter.Failure +func (r *VarDeclarationsRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { + var failures []lint.Failure fileAst := file.AST walker := &lintVarDeclarations{ file: file, fileAst: fileAst, - onFailure: func(failure linter.Failure) { + onFailure: func(failure lint.Failure) { failures = append(failures, failure) }, } @@ -37,9 +37,9 @@ func (r *VarDeclarationsRule) Name() string { type lintVarDeclarations struct { fileAst *ast.File - file *linter.File + file *lint.File lastGen *ast.GenDecl - onFailure func(linter.Failure) + onFailure func(lint.Failure) } func (w *lintVarDeclarations) Visit(node ast.Node) ast.Visitor { @@ -71,7 +71,7 @@ func (w *lintVarDeclarations) Visit(node ast.Node) ast.Visitor { zero = true } if zero { - w.onFailure(linter.Failure{ + w.onFailure(lint.Failure{ Confidence: 0.9, Node: rhs, Failure: fmt.Sprintf("should drop = %s from declaration of var %s; it is the zero value", w.file.Render(rhs), v.Names[0]), @@ -106,7 +106,7 @@ func (w *lintVarDeclarations) Visit(node ast.Node) ast.Visitor { return nil } - w.onFailure(linter.Failure{ + w.onFailure(lint.Failure{ Category: "type-inference", Confidence: 0.8, Node: v.Type, diff --git a/testutil/lint_test.go b/testutil/lint_test.go index a3c715a..618fa1b 100644 --- a/testutil/lint_test.go +++ b/testutil/lint_test.go @@ -27,12 +27,12 @@ import ( "github.com/mgechev/revive/rule" - "github.com/mgechev/revive/linter" + "github.com/mgechev/revive/lint" ) var lintMatch = flag.String("lint.match", "", "restrict fixtures matches to this pattern") -var rules = []linter.Rule{ +var rules = []lint.Rule{ &rule.VarDeclarationsRule{}, &rule.PackageCommentsRule{}, &rule.DotImportsRule{}, @@ -43,7 +43,7 @@ var rules = []linter.Rule{ func TestAll(t *testing.T) { baseDir := "../fixtures/" - l := linter.New(func(file string) ([]byte, error) { + l := lint.New(func(file string) ([]byte, error) { return ioutil.ReadFile(baseDir + file) }) rx, err := regexp.Compile(*lintMatch) @@ -74,13 +74,13 @@ func TestAll(t *testing.T) { continue } - ps, err := l.Lint([]string{fi.Name()}, rules, map[string]linter.Arguments{}) + ps, err := l.Lint([]string{fi.Name()}, rules, map[string]lint.Arguments{}) if err != nil { t.Errorf("Linting %s: %v", fi.Name(), err) continue } - failures := []linter.Failure{} + failures := []lint.Failure{} for f := range ps { failures = append(failures, f) } @@ -275,7 +275,7 @@ func TestLintName(t *testing.T) { {"IEEE802_16Bit", "IEEE802_16Bit"}, } for _, test := range tests { - got := linter.LintName(test.name) + got := lint.Name(test.name) if got != test.want { t.Errorf("lintName(%q) = %q, want %q", test.name, got, test.want) }