1
0
mirror of https://github.com/mgechev/revive.git synced 2025-02-01 13:07:44 +02:00

Lint cleanup (#679)

This commit is contained in:
chavacava 2022-04-10 11:55:13 +02:00 committed by GitHub
parent 31fbdb1833
commit 04728cf0de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
83 changed files with 203 additions and 233 deletions

View File

@ -122,7 +122,7 @@ func GetLintingRules(config *lint.Config, extraRules []lint.Rule) ([]lint.Rule,
var lintingRules []lint.Rule var lintingRules []lint.Rule
for name, ruleConfig := range config.Rules { for name, ruleConfig := range config.Rules {
rule, ok := rulesMap[name] r, ok := rulesMap[name]
if !ok { if !ok {
return nil, fmt.Errorf("cannot find rule: %s", name) return nil, fmt.Errorf("cannot find rule: %s", name)
} }
@ -131,7 +131,7 @@ func GetLintingRules(config *lint.Config, extraRules []lint.Rule) ([]lint.Rule,
continue // skip disabled rules continue // skip disabled rules
} }
lintingRules = append(lintingRules, rule) lintingRules = append(lintingRules, r)
} }
return lintingRules, nil return lintingRules, nil
@ -155,8 +155,8 @@ func normalizeConfig(config *lint.Config) {
} }
if config.EnableAllRules { if config.EnableAllRules {
// Add to the configuration all rules not yet present in it // Add to the configuration all rules not yet present in it
for _, rule := range allRules { for _, r := range allRules {
ruleName := rule.Name() ruleName := r.Name()
_, alreadyInConf := config.Rules[ruleName] _, alreadyInConf := config.Rules[ruleName]
if alreadyInConf { if alreadyInConf {
continue continue
@ -207,15 +207,15 @@ func GetConfig(configPath string) (*lint.Config, error) {
// GetFormatter yields the formatter for lint failures // GetFormatter yields the formatter for lint failures
func GetFormatter(formatterName string) (lint.Formatter, error) { func GetFormatter(formatterName string) (lint.Formatter, error) {
formatters := getFormatters() formatters := getFormatters()
formatter := formatters["default"] fmtr := formatters["default"]
if formatterName != "" { if formatterName != "" {
f, ok := formatters[formatterName] f, ok := formatters[formatterName]
if !ok { if !ok {
return nil, fmt.Errorf("unknown formatter %v", formatterName) return nil, fmt.Errorf("unknown formatter %v", formatterName)
} }
formatter = f fmtr = f
} }
return formatter, nil return fmtr, nil
} }
func defaultConfig() *lint.Config { func defaultConfig() *lint.Config {

View File

@ -15,7 +15,7 @@ type Checkstyle struct {
} }
// Name returns the name of the formatter // Name returns the name of the formatter
func (f *Checkstyle) Name() string { func (*Checkstyle) Name() string {
return "checkstyle" return "checkstyle"
} }
@ -29,7 +29,7 @@ type issue struct {
} }
// Format formats the failures gotten from the lint. // 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{} issues := map[string][]issue{}
for failure := range failures { for failure := range failures {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)

View File

@ -13,12 +13,12 @@ type Default struct {
} }
// Name returns the name of the formatter // Name returns the name of the formatter
func (f *Default) Name() string { func (*Default) Name() string {
return "default" return "default"
} }
// Format formats the failures gotten from the lint. // 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 { for failure := range failures {
fmt.Printf("%v: %s\n", failure.Position.Start, failure.Failure) fmt.Printf("%v: %s\n", failure.Position.Start, failure.Failure)
} }

View File

@ -10,16 +10,6 @@ import (
"github.com/olekukonko/tablewriter" "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 { func getErrorEmoji() string {
return color.RedString("✘") return color.RedString("✘")
} }
@ -35,7 +25,7 @@ type Friendly struct {
} }
// Name returns the name of the formatter // Name returns the name of the formatter
func (f *Friendly) Name() string { func (*Friendly) Name() string {
return "friendly" return "friendly"
} }
@ -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)}})) 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) fmt.Printf(" %s:%d:%d", failure.GetFilename(), failure.Position.Start.Line, failure.Position.Start.Column)
} }
@ -87,7 +77,7 @@ type statEntry struct {
failures int failures int
} }
func (f *Friendly) printSummary(errors, warnings int) { func (*Friendly) printSummary(errors, warnings int) {
emoji := getWarningEmoji() emoji := getWarningEmoji()
if errors > 0 { if errors > 0 {
emoji = getErrorEmoji() emoji = getErrorEmoji()
@ -136,7 +126,7 @@ func (f *Friendly) printStatistics(header string, stats map[string]int) {
fmt.Println(f.table(formatted)) fmt.Println(f.table(formatted))
} }
func (f *Friendly) table(rows [][]string) string { func (*Friendly) table(rows [][]string) string {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
table := tablewriter.NewWriter(buf) table := tablewriter.NewWriter(buf)
table.SetBorder(false) table.SetBorder(false)

View File

@ -13,7 +13,7 @@ type JSON struct {
} }
// Name returns the name of the formatter // Name returns the name of the formatter
func (f *JSON) Name() string { func (*JSON) Name() string {
return "json" return "json"
} }
@ -24,7 +24,7 @@ type jsonObject struct {
} }
// Format formats the failures gotten from the lint. // 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 var slice []jsonObject
for failure := range failures { for failure := range failures {
obj := jsonObject{} obj := jsonObject{}

View File

@ -14,12 +14,12 @@ type NDJSON struct {
} }
// Name returns the name of the formatter // Name returns the name of the formatter
func (f *NDJSON) Name() string { func (*NDJSON) Name() string {
return "ndjson" return "ndjson"
} }
// Format formats the failures gotten from the lint. // 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) enc := json.NewEncoder(os.Stdout)
for failure := range failures { for failure := range failures {
obj := jsonObject{} obj := jsonObject{}

View File

@ -13,12 +13,12 @@ type Plain struct {
} }
// Name returns the name of the formatter // Name returns the name of the formatter
func (f *Plain) Name() string { func (*Plain) Name() string {
return "plain" return "plain"
} }
// Format formats the failures gotten from the lint. // 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 { for failure := range failures {
fmt.Printf("%v: %s %s\n", failure.Position.Start, failure.Failure, "https://revive.run/r#"+failure.RuleName) fmt.Printf("%v: %s %s\n", failure.Position.Start, failure.Failure, "https://revive.run/r#"+failure.RuleName)
} }

View File

@ -16,14 +16,14 @@ type Sarif struct {
} }
// Name returns the name of the formatter // Name returns the name of the formatter
func (f *Sarif) Name() string { func (*Sarif) Name() string {
return "sarif" return "sarif"
} }
const reviveSite = "https://revive.run" const reviveSite = "https://revive.run"
// Format formats the failures gotten from the lint. // 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) sarifLog := newReviveRunLog(cfg)
for failure := range failures { for failure := range failures {

View File

@ -16,7 +16,7 @@ type Stylish struct {
} }
// Name returns the name of the formatter // Name returns the name of the formatter
func (f *Stylish) Name() string { func (*Stylish) Name() string {
return "stylish" return "stylish"
} }
@ -32,7 +32,7 @@ func formatFailure(failure lint.Failure, severity lint.Severity) []string {
} }
// Format formats the failures gotten from the lint. // 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 var result [][]string
totalErrors := 0 totalErrors := 0
total := 0 total := 0

View File

@ -14,12 +14,12 @@ type Unix struct {
} }
// Name returns the name of the formatter // Name returns the name of the formatter
func (f *Unix) Name() string { func (*Unix) Name() string {
return "unix" return "unix"
} }
// Format formats the failures gotten from the lint. // 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 { for failure := range failures {
fmt.Printf("%v: [%s] %s\n", failure.Position.Start, failure.RuleName, failure.Failure) fmt.Printf("%v: [%s] %s\n", failure.Position.Start, failure.RuleName, failure.Failure)
} }

View File

@ -249,7 +249,7 @@ func (f *File) disabledIntervals(rules []Rule, mustSpecifyDisableReason bool, fa
return getEnabledDisabledIntervals() return getEnabledDisabledIntervals()
} }
func (f *File) filterFailures(failures []Failure, disabledIntervals disabledIntervalsMap) []Failure { func (File) filterFailures(failures []Failure, disabledIntervals disabledIntervalsMap) []Failure {
result := []Failure{} result := []Failure{}
for _, failure := range failures { for _, failure := range failures {
fStart := failure.Position.Start.Line fStart := failure.Position.Start.Line

View File

@ -136,7 +136,7 @@ func addInvalidFileFailure(filename, errStr string, failures chan Failure) {
// errPosRegexp matches with an NewFile error message // errPosRegexp matches with an NewFile error message
// i.e. : corrupted.go:10:4: expected '}', found 'EOF // i.e. : corrupted.go:10:4: expected '}', found 'EOF
// first group matches the line and the second group, the column // 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 // getPositionInvalidFile gets the position of the error in an invalid file
func getPositionInvalidFile(filename, s string) FailurePosition { func getPositionInvalidFile(filename, s string) FailurePosition {

View File

@ -28,7 +28,7 @@ func New(
maxOpenFiles int, maxOpenFiles int,
extraRules ...ExtraRule, extraRules ...ExtraRule,
) (*Revive, error) { ) (*Revive, error) {
log, err := logging.GetLogger() logger, err := logging.GetLogger()
if err != nil { if err != nil {
return nil, errors.Wrap(err, "initializing revive - getting logger") return nil, errors.Wrap(err, "initializing revive - getting logger")
} }
@ -55,10 +55,10 @@ func New(
return nil, errors.Wrap(err, "initializing revive - gettint lint rules") return nil, errors.Wrap(err, "initializing revive - gettint lint rules")
} }
log.Println("Config loaded") logger.Println("Config loaded")
return &Revive{ return &Revive{
logger: log, logger: logger,
config: conf, config: conf,
lintingRules: lintingRules, lintingRules: lintingRules,
maxOpenFiles: maxOpenFiles, maxOpenFiles: maxOpenFiles,

View File

@ -39,11 +39,11 @@ func TestReviveCreateInstance(t *testing.T) {
type mockRule struct { type mockRule struct {
} }
func (r *mockRule) Name() string { func (*mockRule) Name() string {
return "mock-rule" 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 return nil
} }

View File

@ -55,7 +55,7 @@ func (r *AddConstantRule) Apply(file *lint.File, arguments lint.Arguments) []lin
} }
// Name returns the rule name. // Name returns the rule name.
func (r *AddConstantRule) Name() string { func (*AddConstantRule) Name() string {
return "add-constant" return "add-constant"
} }

View File

@ -48,7 +48,7 @@ func (r *ArgumentsLimitRule) Apply(file *lint.File, arguments lint.Arguments) []
} }
// Name returns the rule name. // Name returns the rule name.
func (r *ArgumentsLimitRule) Name() string { func (*ArgumentsLimitRule) Name() string {
return "argument-limit" return "argument-limit"
} }

View File

@ -12,7 +12,7 @@ import (
type AtomicRule struct{} type AtomicRule struct{}
// Apply applies the rule to given file. // 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 var failures []lint.Failure
walker := atomic{ walker := atomic{
pkgTypesInfo: file.Pkg.TypesInfo(), pkgTypesInfo: file.Pkg.TypesInfo(),
@ -27,7 +27,7 @@ func (r *AtomicRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
} }
// Name returns the rule name. // Name returns the rule name.
func (r *AtomicRule) Name() string { func (*AtomicRule) Name() string {
return "atomic" return "atomic"
} }

View File

@ -45,7 +45,7 @@ func (r *BannedCharsRule) Apply(file *lint.File, arguments lint.Arguments) []lin
} }
// Name returns the rule name // Name returns the rule name
func (r *BannedCharsRule) Name() string { func (*BannedCharsRule) Name() string {
return bannedCharsRuleName return bannedCharsRuleName
} }

View File

@ -10,7 +10,7 @@ import (
type BareReturnRule struct{} type BareReturnRule struct{}
// Apply applies the rule to given file. // 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 var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -23,7 +23,7 @@ func (r *BareReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure
} }
// Name returns the rule name. // Name returns the rule name.
func (r *BareReturnRule) Name() string { func (*BareReturnRule) Name() string {
return "bare-return" return "bare-return"
} }

View File

@ -11,7 +11,7 @@ import (
type BlankImportsRule struct{} type BlankImportsRule struct{}
// Name returns the rule name. // Name returns the rule name.
func (r *BlankImportsRule) Name() string { func (*BlankImportsRule) Name() string {
return "blank-imports" return "blank-imports"
} }
@ -62,7 +62,7 @@ func (r *BlankImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failu
return failures return failures
} }
func (r *BlankImportsRule) fileHasValidEmbedComment(fileAst *ast.File) bool { func (*BlankImportsRule) fileHasValidEmbedComment(fileAst *ast.File) bool {
for _, commentGroup := range fileAst.Comments { for _, commentGroup := range fileAst.Comments {
for _, comment := range commentGroup.List { for _, comment := range commentGroup.List {
if strings.HasPrefix(comment.Text, "//go:embed ") { if strings.HasPrefix(comment.Text, "//go:embed ") {

View File

@ -11,7 +11,7 @@ import (
type BoolLiteralRule struct{} type BoolLiteralRule struct{}
// Apply applies the rule to given file. // 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 var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -26,7 +26,7 @@ func (r *BoolLiteralRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failur
} }
// Name returns the rule name. // Name returns the rule name.
func (r *BoolLiteralRule) Name() string { func (*BoolLiteralRule) Name() string {
return "bool-literal-in-expr" return "bool-literal-in-expr"
} }

View File

@ -10,7 +10,7 @@ import (
type CallToGCRule struct{} type CallToGCRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *CallToGCRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*CallToGCRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
failures = append(failures, failure) failures = append(failures, failure)
@ -27,7 +27,7 @@ func (r *CallToGCRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
} }
// Name returns the rule name. // Name returns the rule name.
func (r *CallToGCRule) Name() string { func (*CallToGCRule) Name() string {
return "call-to-gc" return "call-to-gc"
} }

View File

@ -44,13 +44,13 @@ func (r *CognitiveComplexityRule) Apply(file *lint.File, arguments lint.Argument
}, },
} }
linter.lint() linter.lintCognitiveComplexity()
return failures return failures
} }
// Name returns the rule name. // Name returns the rule name.
func (r *CognitiveComplexityRule) Name() string { func (*CognitiveComplexityRule) Name() string {
return "cognitive-complexity" return "cognitive-complexity"
} }
@ -60,7 +60,7 @@ type cognitiveComplexityLinter struct {
onFailure func(lint.Failure) onFailure func(lint.Failure)
} }
func (w cognitiveComplexityLinter) lint() { func (w cognitiveComplexityLinter) lintCognitiveComplexity() {
f := w.file f := w.file
for _, decl := range f.AST.Decls { for _, decl := range f.AST.Decls {
if fn, ok := decl.(*ast.FuncDecl); ok && fn.Body != nil { if fn, ok := decl.(*ast.FuncDecl); ok && fn.Body != nil {

View File

@ -48,7 +48,7 @@ var allPkgs = packages{pkgs: make([]pkgMethods, 1)}
type ConfusingNamingRule struct{} type ConfusingNamingRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *ConfusingNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*ConfusingNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
fileAst := file.AST fileAst := file.AST
pkgm := allPkgs.methodNames(file.Pkg) pkgm := allPkgs.methodNames(file.Pkg)
@ -66,7 +66,7 @@ func (r *ConfusingNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fa
} }
// Name returns the rule name. // Name returns the rule name.
func (r *ConfusingNamingRule) Name() string { func (*ConfusingNamingRule) Name() string {
return "confusing-naming" return "confusing-naming"
} }

View File

@ -10,7 +10,7 @@ import (
type ConfusingResultsRule struct{} type ConfusingResultsRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *ConfusingResultsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*ConfusingResultsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
fileAst := file.AST fileAst := file.AST
@ -26,7 +26,7 @@ func (r *ConfusingResultsRule) Apply(file *lint.File, _ lint.Arguments) []lint.F
} }
// Name returns the rule name. // Name returns the rule name.
func (r *ConfusingResultsRule) Name() string { func (*ConfusingResultsRule) Name() string {
return "confusing-results" return "confusing-results"
} }
@ -60,7 +60,6 @@ func (w lintConfusingResults) Visit(n ast.Node) ast.Visitor {
break break
} }
lastType = t.Name lastType = t.Name
} }
return w return w

View File

@ -25,7 +25,7 @@ func (r *ConstantLogicalExprRule) Apply(file *lint.File, _ lint.Arguments) []lin
} }
// Name returns the rule name. // Name returns the rule name.
func (r *ConstantLogicalExprRule) Name() string { func (*ConstantLogicalExprRule) Name() string {
return "constant-logical-expr" return "constant-logical-expr"
} }

View File

@ -17,7 +17,6 @@ type ContextAsArgumentRule struct {
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *ContextAsArgumentRule) Apply(file *lint.File, args lint.Arguments) []lint.Failure { func (r *ContextAsArgumentRule) Apply(file *lint.File, args lint.Arguments) []lint.Failure {
r.Lock() r.Lock()
if r.allowTypesLUT == nil { if r.allowTypesLUT == nil {
r.allowTypesLUT = getAllowTypesFromArguments(args) r.allowTypesLUT = getAllowTypesFromArguments(args)
@ -40,7 +39,7 @@ func (r *ContextAsArgumentRule) Apply(file *lint.File, args lint.Arguments) []li
} }
// Name returns the rule name. // Name returns the rule name.
func (r *ContextAsArgumentRule) Name() string { func (*ContextAsArgumentRule) Name() string {
return "context-as-argument" return "context-as-argument"
} }

View File

@ -12,7 +12,7 @@ import (
type ContextKeysType struct{} type ContextKeysType struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *ContextKeysType) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*ContextKeysType) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
fileAst := file.AST fileAst := file.AST
@ -31,7 +31,7 @@ func (r *ContextKeysType) Apply(file *lint.File, _ lint.Arguments) []lint.Failur
} }
// Name returns the rule name. // Name returns the rule name.
func (r *ContextKeysType) Name() string { func (*ContextKeysType) Name() string {
return "context-keys-type" return "context-keys-type"
} }

View File

@ -52,7 +52,7 @@ func (r *CyclomaticRule) Apply(file *lint.File, arguments lint.Arguments) []lint
} }
// Name returns the rule name. // Name returns the rule name.
func (r *CyclomaticRule) Name() string { func (*CyclomaticRule) Name() string {
return "cyclomatic" return "cyclomatic"
} }

View File

@ -11,7 +11,7 @@ import (
type DeepExitRule struct{} type DeepExitRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *DeepExitRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*DeepExitRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
failures = append(failures, failure) failures = append(failures, failure)
@ -36,7 +36,7 @@ func (r *DeepExitRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
} }
// Name returns the rule name. // Name returns the rule name.
func (r *DeepExitRule) Name() string { func (*DeepExitRule) Name() string {
return "deep-exit" return "deep-exit"
} }

View File

@ -38,11 +38,11 @@ func (r *DeferRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Fail
} }
// Name returns the rule name. // Name returns the rule name.
func (r *DeferRule) Name() string { func (*DeferRule) Name() string {
return "defer" return "defer"
} }
func (r *DeferRule) allowFromArgs(args lint.Arguments) map[string]bool { func (*DeferRule) allowFromArgs(args lint.Arguments) map[string]bool {
if len(args) < 1 { if len(args) < 1 {
allow := map[string]bool{ allow := map[string]bool{
"loop": true, "loop": true,

View File

@ -10,7 +10,7 @@ import (
type DotImportsRule struct{} type DotImportsRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *DotImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*DotImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
fileAst := file.AST fileAst := file.AST
@ -28,7 +28,7 @@ func (r *DotImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure
} }
// Name returns the rule name. // Name returns the rule name.
func (r *DotImportsRule) Name() string { func (*DotImportsRule) Name() string {
return "dot-imports" return "dot-imports"
} }

View File

@ -10,7 +10,7 @@ import (
type DuplicatedImportsRule struct{} type DuplicatedImportsRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *DuplicatedImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*DuplicatedImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
impPaths := map[string]struct{}{} impPaths := map[string]struct{}{}
@ -34,6 +34,6 @@ func (r *DuplicatedImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.
} }
// Name returns the rule name. // Name returns the rule name.
func (r *DuplicatedImportsRule) Name() string { func (*DuplicatedImportsRule) Name() string {
return "duplicated-imports" return "duplicated-imports"
} }

View File

@ -10,7 +10,7 @@ import (
type EarlyReturnRule struct{} type EarlyReturnRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *EarlyReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*EarlyReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -23,7 +23,7 @@ func (r *EarlyReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failur
} }
// Name returns the rule name. // Name returns the rule name.
func (r *EarlyReturnRule) Name() string { func (*EarlyReturnRule) Name() string {
return "early-return" return "early-return"
} }

View File

@ -10,7 +10,7 @@ import (
type EmptyBlockRule struct{} type EmptyBlockRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *EmptyBlockRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*EmptyBlockRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -23,7 +23,7 @@ func (r *EmptyBlockRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure
} }
// Name returns the rule name. // Name returns the rule name.
func (r *EmptyBlockRule) Name() string { func (*EmptyBlockRule) Name() string {
return "empty-block" return "empty-block"
} }

View File

@ -11,7 +11,7 @@ import (
type EmptyLinesRule struct{} type EmptyLinesRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *EmptyLinesRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*EmptyLinesRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -24,7 +24,7 @@ func (r *EmptyLinesRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure
} }
// Name returns the rule name. // Name returns the rule name.
func (r *EmptyLinesRule) Name() string { func (*EmptyLinesRule) Name() string {
return "empty-lines" return "empty-lines"
} }

View File

@ -13,7 +13,7 @@ import (
type ErrorNamingRule struct{} type ErrorNamingRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *ErrorNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*ErrorNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
fileAst := file.AST fileAst := file.AST
@ -31,7 +31,7 @@ func (r *ErrorNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failur
} }
// Name returns the rule name. // Name returns the rule name.
func (r *ErrorNamingRule) Name() string { func (*ErrorNamingRule) Name() string {
return "error-naming" return "error-naming"
} }

View File

@ -10,7 +10,7 @@ import (
type ErrorReturnRule struct{} type ErrorReturnRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *ErrorReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*ErrorReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
fileAst := file.AST fileAst := file.AST
@ -28,7 +28,7 @@ func (r *ErrorReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failur
} }
// Name returns the rule name. // Name returns the rule name.
func (r *ErrorReturnRule) Name() string { func (*ErrorReturnRule) Name() string {
return "error-return" return "error-return"
} }

View File

@ -14,7 +14,7 @@ import (
type ErrorStringsRule struct{} type ErrorStringsRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *ErrorStringsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*ErrorStringsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
errorFunctions := map[string]map[string]struct{}{ errorFunctions := map[string]map[string]struct{}{
@ -47,7 +47,7 @@ func (r *ErrorStringsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failu
} }
// Name returns the rule name. // Name returns the rule name.
func (r *ErrorStringsRule) Name() string { func (*ErrorStringsRule) Name() string {
return "error-strings" return "error-strings"
} }

View File

@ -13,7 +13,7 @@ import (
type ErrorfRule struct{} type ErrorfRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *ErrorfRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*ErrorfRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
fileAst := file.AST fileAst := file.AST
@ -32,7 +32,7 @@ func (r *ErrorfRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
} }
// Name returns the rule name. // Name returns the rule name.
func (r *ErrorfRule) Name() string { func (*ErrorfRule) Name() string {
return "errorf" return "errorf"
} }

View File

@ -65,7 +65,7 @@ func (r *ExportedRule) Apply(file *lint.File, args lint.Arguments) []lint.Failur
} }
// Name returns the rule name. // Name returns the rule name.
func (r *ExportedRule) Name() string { func (*ExportedRule) Name() string {
return "exported" return "exported"
} }

View File

@ -15,7 +15,7 @@ type FileHeaderRule struct {
} }
var ( var (
multiRegexp = regexp.MustCompile("^/\\*") multiRegexp = regexp.MustCompile(`^/\*`)
singleRegexp = regexp.MustCompile("^//") singleRegexp = regexp.MustCompile("^//")
) )
@ -75,6 +75,6 @@ func (r *FileHeaderRule) Apply(file *lint.File, arguments lint.Arguments) []lint
} }
// Name returns the rule name. // Name returns the rule name.
func (r *FileHeaderRule) Name() string { func (*FileHeaderRule) Name() string {
return "file-header" return "file-header"
} }

View File

@ -11,7 +11,7 @@ import (
type FlagParamRule struct{} type FlagParamRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *FlagParamRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*FlagParamRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -24,7 +24,7 @@ func (r *FlagParamRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure
} }
// Name returns the rule name. // Name returns the rule name.
func (r *FlagParamRule) Name() string { func (*FlagParamRule) Name() string {
return "flag-parameter" return "flag-parameter"
} }

View File

@ -47,11 +47,11 @@ func (r *FunctionLength) Apply(file *lint.File, arguments lint.Arguments) []lint
} }
// Name returns the rule name. // Name returns the rule name.
func (r *FunctionLength) Name() string { func (*FunctionLength) Name() string {
return "function-length" return "function-length"
} }
func (r *FunctionLength) parseArguments(arguments lint.Arguments) (maxStmt, maxLines int64) { func (*FunctionLength) parseArguments(arguments lint.Arguments) (maxStmt, maxLines int64) {
if len(arguments) != 2 { if len(arguments) != 2 {
panic(fmt.Sprintf(`invalid configuration for "function-length" rule, expected 2 arguments but got %d`, len(arguments))) panic(fmt.Sprintf(`invalid configuration for "function-length" rule, expected 2 arguments but got %d`, len(arguments)))
} }
@ -72,7 +72,7 @@ func (r *FunctionLength) parseArguments(arguments lint.Arguments) (maxStmt, maxL
panic(fmt.Sprintf(`the configuration value for max statements in "function-length" rule cannot be negative, got %d`, maxLines)) panic(fmt.Sprintf(`the configuration value for max statements in "function-length" rule cannot be negative, got %d`, maxLines))
} }
return return maxStmt, maxLines
} }
type lintFuncLength struct { type lintFuncLength struct {

View File

@ -50,7 +50,7 @@ func (r *FunctionResultsLimitRule) Apply(file *lint.File, arguments lint.Argumen
} }
// Name returns the rule name. // Name returns the rule name.
func (r *FunctionResultsLimitRule) Name() string { func (*FunctionResultsLimitRule) Name() string {
return "function-result-limit" return "function-result-limit"
} }

View File

@ -12,7 +12,7 @@ import (
type GetReturnRule struct{} type GetReturnRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *GetReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*GetReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -25,7 +25,7 @@ func (r *GetReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure
} }
// Name returns the rule name. // Name returns the rule name.
func (r *GetReturnRule) Name() string { func (*GetReturnRule) Name() string {
return "get-return" return "get-return"
} }

View File

@ -10,7 +10,7 @@ import (
type IdenticalBranchesRule struct{} type IdenticalBranchesRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *IdenticalBranchesRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*IdenticalBranchesRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -24,7 +24,7 @@ func (r *IdenticalBranchesRule) Apply(file *lint.File, _ lint.Arguments) []lint.
} }
// Name returns the rule name. // Name returns the rule name.
func (r *IdenticalBranchesRule) Name() string { func (*IdenticalBranchesRule) Name() string {
return "identical-branches" return "identical-branches"
} }
@ -57,7 +57,7 @@ func (w *lintIdenticalBranches) Visit(node ast.Node) ast.Visitor {
return w return w
} }
func (w *lintIdenticalBranches) identicalBranches(branches []*ast.BlockStmt) bool { func (lintIdenticalBranches) identicalBranches(branches []*ast.BlockStmt) bool {
if len(branches) < 2 { if len(branches) < 2 {
return false return false
} }

View File

@ -12,7 +12,7 @@ import (
type IfReturnRule struct{} type IfReturnRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *IfReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*IfReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -26,7 +26,7 @@ func (r *IfReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
} }
// Name returns the rule name. // Name returns the rule name.
func (r *IfReturnRule) Name() string { func (*IfReturnRule) Name() string {
return "if-return" return "if-return"
} }

View File

@ -13,7 +13,7 @@ import (
type ImportShadowingRule struct{} type ImportShadowingRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *ImportShadowingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*ImportShadowingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
importNames := map[string]struct{}{} importNames := map[string]struct{}{}
@ -37,7 +37,7 @@ func (r *ImportShadowingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fa
} }
// Name returns the rule name. // Name returns the rule name.
func (r *ImportShadowingRule) Name() string { func (*ImportShadowingRule) Name() string {
return "import-shadowing" return "import-shadowing"
} }

View File

@ -59,6 +59,6 @@ func (r *ImportsBlacklistRule) Apply(file *lint.File, arguments lint.Arguments)
} }
// Name returns the rule name. // Name returns the rule name.
func (r *ImportsBlacklistRule) Name() string { func (*ImportsBlacklistRule) Name() string {
return "imports-blacklist" return "imports-blacklist"
} }

View File

@ -12,7 +12,7 @@ import (
type IncrementDecrementRule struct{} type IncrementDecrementRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *IncrementDecrementRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*IncrementDecrementRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
fileAst := file.AST fileAst := file.AST
@ -29,13 +29,12 @@ func (r *IncrementDecrementRule) Apply(file *lint.File, _ lint.Arguments) []lint
} }
// Name returns the rule name. // Name returns the rule name.
func (r *IncrementDecrementRule) Name() string { func (*IncrementDecrementRule) Name() string {
return "increment-decrement" return "increment-decrement"
} }
type lintIncrementDecrement struct { type lintIncrementDecrement struct {
file *lint.File file *lint.File
fileAst *ast.File
onFailure func(lint.Failure) onFailure func(lint.Failure)
} }

View File

@ -11,7 +11,7 @@ import (
type IndentErrorFlowRule struct{} type IndentErrorFlowRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *IndentErrorFlowRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*IndentErrorFlowRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -24,7 +24,7 @@ func (r *IndentErrorFlowRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fa
} }
// Name returns the rule name. // Name returns the rule name.
func (r *IndentErrorFlowRule) Name() string { func (*IndentErrorFlowRule) Name() string {
return "indent-error-flow" return "indent-error-flow"
} }

View File

@ -53,7 +53,7 @@ func (r *LineLengthLimitRule) Apply(file *lint.File, arguments lint.Arguments) [
} }
// Name returns the rule name. // Name returns the rule name.
func (r *LineLengthLimitRule) Name() string { func (*LineLengthLimitRule) Name() string {
return "line-length-limit" return "line-length-limit"
} }

View File

@ -58,7 +58,7 @@ func (r *MaxPublicStructsRule) Apply(file *lint.File, arguments lint.Arguments)
} }
// Name returns the rule name. // Name returns the rule name.
func (r *MaxPublicStructsRule) Name() string { func (*MaxPublicStructsRule) Name() string {
return "max-public-structs" return "max-public-structs"
} }

View File

@ -11,7 +11,7 @@ import (
type ModifiesParamRule struct{} type ModifiesParamRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *ModifiesParamRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*ModifiesParamRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -24,7 +24,7 @@ func (r *ModifiesParamRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fail
} }
// Name returns the rule name. // Name returns the rule name.
func (r *ModifiesParamRule) Name() string { func (*ModifiesParamRule) Name() string {
return "modifies-parameter" return "modifies-parameter"
} }

View File

@ -11,7 +11,7 @@ import (
type ModifiesValRecRule struct{} type ModifiesValRecRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *ModifiesValRecRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*ModifiesValRecRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -26,7 +26,7 @@ func (r *ModifiesValRecRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fai
} }
// Name returns the rule name. // Name returns the rule name.
func (r *ModifiesValRecRule) Name() string { func (*ModifiesValRecRule) Name() string {
return "modifies-value-receiver" return "modifies-value-receiver"
} }

View File

@ -10,7 +10,7 @@ import (
type NestedStructs struct{} type NestedStructs struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *NestedStructs) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*NestedStructs) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
walker := &lintNestedStructs{ walker := &lintNestedStructs{
@ -26,7 +26,7 @@ func (r *NestedStructs) Apply(file *lint.File, _ lint.Arguments) []lint.Failure
} }
// Name returns the rule name. // Name returns the rule name.
func (r *NestedStructs) Name() string { func (*NestedStructs) Name() string {
return "nested-structs" return "nested-structs"
} }

View File

@ -12,7 +12,7 @@ import (
type OptimizeOperandsOrderRule struct{} type OptimizeOperandsOrderRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *OptimizeOperandsOrderRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*OptimizeOperandsOrderRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -26,7 +26,7 @@ func (r *OptimizeOperandsOrderRule) Apply(file *lint.File, _ lint.Arguments) []l
} }
// Name returns the rule name. // Name returns the rule name.
func (r *OptimizeOperandsOrderRule) Name() string { func (*OptimizeOperandsOrderRule) Name() string {
return "optimize-operands-order" return "optimize-operands-order"
} }

View File

@ -17,7 +17,7 @@ import (
type PackageCommentsRule struct{} type PackageCommentsRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *PackageCommentsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*PackageCommentsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
if file.IsTest() { if file.IsTest() {
@ -35,7 +35,7 @@ func (r *PackageCommentsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fa
} }
// Name returns the rule name. // Name returns the rule name.
func (r *PackageCommentsRule) Name() string { func (*PackageCommentsRule) Name() string {
return "package-comments" return "package-comments"
} }
@ -50,7 +50,6 @@ func (l *lintPackageComments) Visit(_ ast.Node) ast.Visitor {
return nil return nil
} }
const ref = styleGuideBase + "#package-comments"
prefix := "Package " + l.fileAst.Name.Name + " " prefix := "Package " + l.fileAst.Name.Name + " "
// Look for a detached package comment. // Look for a detached package comment.

View File

@ -13,7 +13,7 @@ import (
type RangeValAddress struct{} type RangeValAddress struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *RangeValAddress) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*RangeValAddress) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
walker := rangeValAddress{ walker := rangeValAddress{
@ -30,7 +30,7 @@ func (r *RangeValAddress) Apply(file *lint.File, _ lint.Arguments) []lint.Failur
} }
// Name returns the rule name. // Name returns the rule name.
func (r *RangeValAddress) Name() string { func (*RangeValAddress) Name() string {
return "range-val-address" return "range-val-address"
} }

View File

@ -11,7 +11,7 @@ import (
type RangeValInClosureRule struct{} type RangeValInClosureRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *RangeValInClosureRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*RangeValInClosureRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
walker := rangeValInClosure{ walker := rangeValInClosure{
@ -26,7 +26,7 @@ func (r *RangeValInClosureRule) Apply(file *lint.File, _ lint.Arguments) []lint.
} }
// Name returns the rule name. // Name returns the rule name.
func (r *RangeValInClosureRule) Name() string { func (*RangeValInClosureRule) Name() string {
return "range-val-in-closure" return "range-val-in-closure"
} }

View File

@ -12,7 +12,7 @@ import (
type RangeRule struct{} type RangeRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *RangeRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*RangeRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -25,7 +25,7 @@ func (r *RangeRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
} }
// Name returns the rule name. // Name returns the rule name.
func (r *RangeRule) Name() string { func (*RangeRule) Name() string {
return "range" return "range"
} }

View File

@ -11,7 +11,7 @@ import (
type ReceiverNamingRule struct{} type ReceiverNamingRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *ReceiverNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*ReceiverNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
fileAst := file.AST fileAst := file.AST
@ -28,7 +28,7 @@ func (r *ReceiverNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fai
} }
// Name returns the rule name. // Name returns the rule name.
func (r *ReceiverNamingRule) Name() string { func (*ReceiverNamingRule) Name() string {
return "receiver-naming" return "receiver-naming"
} }
@ -47,7 +47,6 @@ func (w lintReceiverName) Visit(n ast.Node) ast.Visitor {
return w return w
} }
name := names[0].Name name := names[0].Name
const ref = styleGuideBase + "#receiver-names"
if name == "_" { if name == "_" {
w.onFailure(lint.Failure{ w.onFailure(lint.Failure{
Node: n, Node: n,

View File

@ -61,7 +61,7 @@ var builtInTypes = map[string]bool{
type RedefinesBuiltinIDRule struct{} type RedefinesBuiltinIDRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *RedefinesBuiltinIDRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*RedefinesBuiltinIDRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -76,7 +76,7 @@ func (r *RedefinesBuiltinIDRule) Apply(file *lint.File, _ lint.Arguments) []lint
} }
// Name returns the rule name. // Name returns the rule name.
func (r *RedefinesBuiltinIDRule) Name() string { func (*RedefinesBuiltinIDRule) Name() string {
return "redefines-builtin-id" return "redefines-builtin-id"
} }
@ -159,7 +159,7 @@ func (w lintRedefinesBuiltinID) addFailure(node ast.Node, msg string) {
}) })
} }
func (w lintRedefinesBuiltinID) isBuiltIn(id string) (r bool, builtInKind string) { func (lintRedefinesBuiltinID) isBuiltIn(id string) (r bool, builtInKind string) {
if builtFunctions[id] { if builtFunctions[id] {
return true, "function" return true, "function"
} }

View File

@ -16,7 +16,7 @@ import (
type StringFormatRule struct{} type StringFormatRule struct{}
// Apply applies the rule to the given file. // Apply applies the rule to the given file.
func (r *StringFormatRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { func (*StringFormatRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -31,12 +31,12 @@ func (r *StringFormatRule) Apply(file *lint.File, arguments lint.Arguments) []li
} }
// Name returns the rule name. // Name returns the rule name.
func (r *StringFormatRule) Name() string { func (*StringFormatRule) Name() string {
return "string-format" return "string-format"
} }
// ParseArgumentsTest is a public wrapper around w.parseArguments used for testing. Returns the error message provided to panic, or nil if no error was encountered // ParseArgumentsTest is a public wrapper around w.parseArguments used for testing. Returns the error message provided to panic, or nil if no error was encountered
func (r *StringFormatRule) ParseArgumentsTest(arguments lint.Arguments) *string { func (StringFormatRule) ParseArgumentsTest(arguments lint.Arguments) *string {
w := lintStringFormatRule{} w := lintStringFormatRule{}
c := make(chan interface{}) c := make(chan interface{})
// Parse the arguments in a goroutine, defer a recover() call, return the error encountered (or nil if there was no error) // Parse the arguments in a goroutine, defer a recover() call, return the error encountered (or nil if there was no error)
@ -61,9 +61,7 @@ func (r *StringFormatRule) ParseArgumentsTest(arguments lint.Arguments) *string
type lintStringFormatRule struct { type lintStringFormatRule struct {
onFailure func(lint.Failure) onFailure func(lint.Failure)
rules []stringFormatSubrule
rules []stringFormatSubrule
stringDeclarations map[string]string
} }
type stringFormatSubrule struct { type stringFormatSubrule struct {
@ -161,12 +159,12 @@ func (w lintStringFormatRule) parseArgument(argument interface{}, ruleNum int) (
} }
// Report an invalid config, this is specifically the user's fault // Report an invalid config, this is specifically the user's fault
func (w lintStringFormatRule) configError(msg string, ruleNum, option int) { func (lintStringFormatRule) configError(msg string, ruleNum, option int) {
panic(fmt.Sprintf("invalid configuration for string-format: %s [argument %d, option %d]", msg, ruleNum, option)) panic(fmt.Sprintf("invalid configuration for string-format: %s [argument %d, option %d]", msg, ruleNum, option))
} }
// Report a general config parsing failure, this may be the user's fault, but it isn't known for certain // Report a general config parsing failure, this may be the user's fault, but it isn't known for certain
func (w lintStringFormatRule) parseError(msg string, ruleNum, option int) { func (lintStringFormatRule) parseError(msg string, ruleNum, option int) {
panic(fmt.Sprintf("failed to parse configuration for string-format: %s [argument %d, option %d]", msg, ruleNum, option)) panic(fmt.Sprintf("failed to parse configuration for string-format: %s [argument %d, option %d]", msg, ruleNum, option))
} }
@ -197,7 +195,7 @@ func (w lintStringFormatRule) Visit(node ast.Node) ast.Visitor {
} }
// Return the name of a call expression in the form of package.Func or Func // Return the name of a call expression in the form of package.Func or Func
func (w lintStringFormatRule) getCallName(call *ast.CallExpr) (callName string, ok bool) { func (lintStringFormatRule) getCallName(call *ast.CallExpr) (callName string, ok bool) {
if ident, ok := call.Fun.(*ast.Ident); ok { if ident, ok := call.Fun.(*ast.Ident); ok {
// Local function call // Local function call
return ident.Name, true return ident.Name, true
@ -220,14 +218,14 @@ func (w lintStringFormatRule) getCallName(call *ast.CallExpr) (callName string,
// #region Linting logic // #region Linting logic
// Apply a single format rule to a call expression (should be done after verifying the that the call expression matches the rule's scope) // Apply a single format rule to a call expression (should be done after verifying the that the call expression matches the rule's scope)
func (rule stringFormatSubrule) Apply(call *ast.CallExpr) { func (r *stringFormatSubrule) Apply(call *ast.CallExpr) {
if len(call.Args) <= rule.scope.argument { if len(call.Args) <= r.scope.argument {
return return
} }
arg := call.Args[rule.scope.argument] arg := call.Args[r.scope.argument]
var lit *ast.BasicLit var lit *ast.BasicLit
if len(rule.scope.field) > 0 { if len(r.scope.field) > 0 {
// Try finding the scope's Field, treating arg as a composite literal // Try finding the scope's Field, treating arg as a composite literal
composite, ok := arg.(*ast.CompositeLit) composite, ok := arg.(*ast.CompositeLit)
if !ok { if !ok {
@ -239,7 +237,7 @@ func (rule stringFormatSubrule) Apply(call *ast.CallExpr) {
continue continue
} }
key, ok := kv.Key.(*ast.Ident) key, ok := kv.Key.(*ast.Ident)
if !ok || key.Name != rule.scope.field { if !ok || key.Name != r.scope.field {
continue continue
} }
@ -259,21 +257,21 @@ func (rule stringFormatSubrule) Apply(call *ast.CallExpr) {
} }
// Unquote the string literal before linting // Unquote the string literal before linting
unquoted := lit.Value[1 : len(lit.Value)-1] unquoted := lit.Value[1 : len(lit.Value)-1]
rule.lintMessage(unquoted, lit) r.lintMessage(unquoted, lit)
} }
func (rule stringFormatSubrule) lintMessage(s string, node ast.Node) { func (r *stringFormatSubrule) lintMessage(s string, node ast.Node) {
// Fail if the string doesn't match the user's regex // Fail if the string doesn't match the user's regex
if rule.regexp.MatchString(s) { if r.regexp.MatchString(s) {
return return
} }
var failure string var failure string
if len(rule.errorMessage) > 0 { if len(r.errorMessage) > 0 {
failure = rule.errorMessage failure = r.errorMessage
} else { } else {
failure = fmt.Sprintf("string literal doesn't match user defined regex /%s/", rule.regexp.String()) failure = fmt.Sprintf("string literal doesn't match user defined regex /%s/", r.regexp.String())
} }
rule.parent.onFailure(lint.Failure{ r.parent.onFailure(lint.Failure{
Confidence: 1, Confidence: 1,
Failure: failure, Failure: failure,
Node: node, Node: node,

View File

@ -11,7 +11,7 @@ import (
type StringOfIntRule struct{} type StringOfIntRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *StringOfIntRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*StringOfIntRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -28,7 +28,7 @@ func (r *StringOfIntRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failur
} }
// Name returns the rule name. // Name returns the rule name.
func (r *StringOfIntRule) Name() string { func (*StringOfIntRule) Name() string {
return "string-of-int" return "string-of-int"
} }

View File

@ -14,7 +14,7 @@ import (
type StructTagRule struct{} type StructTagRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *StructTagRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*StructTagRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -29,7 +29,7 @@ func (r *StructTagRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure
} }
// Name returns the rule name. // Name returns the rule name.
func (r *StructTagRule) Name() string { func (*StructTagRule) Name() string {
return "struct-tag" return "struct-tag"
} }
@ -148,7 +148,7 @@ func (w lintStructTagRule) checkASN1Tag(t ast.Expr, tag *structtag.Tag) (string,
return "", true return "", true
} }
func (w lintStructTagRule) checkBSONTag(options []string) (string, bool) { func (lintStructTagRule) checkBSONTag(options []string) (string, bool) {
for _, opt := range options { for _, opt := range options {
switch opt { switch opt {
case "inline", "minsize", "omitempty": case "inline", "minsize", "omitempty":
@ -160,7 +160,7 @@ func (w lintStructTagRule) checkBSONTag(options []string) (string, bool) {
return "", true return "", true
} }
func (w lintStructTagRule) checkJSONTag(name string, options []string) (string, bool) { func (lintStructTagRule) checkJSONTag(name string, options []string) (string, bool) {
for _, opt := range options { for _, opt := range options {
switch opt { switch opt {
case "omitempty", "string": case "omitempty", "string":
@ -177,7 +177,7 @@ func (w lintStructTagRule) checkJSONTag(name string, options []string) (string,
return "", true return "", true
} }
func (w lintStructTagRule) checkXMLTag(options []string) (string, bool) { func (lintStructTagRule) checkXMLTag(options []string) (string, bool) {
for _, opt := range options { for _, opt := range options {
switch opt { switch opt {
case "any", "attr", "cdata", "chardata", "comment", "innerxml", "omitempty", "typeattr": case "any", "attr", "cdata", "chardata", "comment", "innerxml", "omitempty", "typeattr":
@ -189,7 +189,7 @@ func (w lintStructTagRule) checkXMLTag(options []string) (string, bool) {
return "", true return "", true
} }
func (w lintStructTagRule) checkYAMLTag(options []string) (string, bool) { func (lintStructTagRule) checkYAMLTag(options []string) (string, bool) {
for _, opt := range options { for _, opt := range options {
switch opt { switch opt {
case "flow", "inline", "omitempty": case "flow", "inline", "omitempty":
@ -201,7 +201,7 @@ func (w lintStructTagRule) checkYAMLTag(options []string) (string, bool) {
return "", true return "", true
} }
func (w lintStructTagRule) typeValueMatch(t ast.Expr, val string) bool { func (lintStructTagRule) typeValueMatch(t ast.Expr, val string) bool {
tID, ok := t.(*ast.Ident) tID, ok := t.(*ast.Ident)
if !ok { if !ok {
return true return true

View File

@ -12,7 +12,7 @@ import (
type SuperfluousElseRule struct{} type SuperfluousElseRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *SuperfluousElseRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*SuperfluousElseRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
failures = append(failures, failure) failures = append(failures, failure)
@ -36,7 +36,7 @@ func (r *SuperfluousElseRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fa
} }
// Name returns the rule name. // Name returns the rule name.
func (r *SuperfluousElseRule) Name() string { func (*SuperfluousElseRule) Name() string {
return "superfluous-else" return "superfluous-else"
} }
@ -82,9 +82,9 @@ func (w lintSuperfluousElse) Visit(node ast.Node) ast.Visitor {
lastStmt := ifStmt.Body.List[len(ifStmt.Body.List)-1] lastStmt := ifStmt.Body.List[len(ifStmt.Body.List)-1]
switch stmt := lastStmt.(type) { switch stmt := lastStmt.(type) {
case *ast.BranchStmt: case *ast.BranchStmt:
token := stmt.Tok.String() tok := stmt.Tok.String()
if token != "fallthrough" { if tok != "fallthrough" {
w.onFailure(newFailure(ifStmt.Else, "if block ends with a "+token+" statement, so drop this else and outdent its block"+extra)) w.onFailure(newFailure(ifStmt.Else, "if block ends with a "+tok+" statement, so drop this else and outdent its block"+extra))
} }
case *ast.ExprStmt: case *ast.ExprStmt:
if ce, ok := stmt.X.(*ast.CallExpr); ok { // it's a function call if ce, ok := stmt.X.(*ast.CallExpr); ok { // it's a function call

View File

@ -13,7 +13,7 @@ import (
type TimeNamingRule struct{} type TimeNamingRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *TimeNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*TimeNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -28,7 +28,7 @@ func (r *TimeNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure
} }
// Name returns the rule name. // Name returns the rule name.
func (r *TimeNamingRule) Name() string { func (*TimeNamingRule) Name() string {
return "time-naming" return "time-naming"
} }

View File

@ -10,7 +10,7 @@ import (
type UnconditionalRecursionRule struct{} type UnconditionalRecursionRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *UnconditionalRecursionRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*UnconditionalRecursionRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -23,7 +23,7 @@ func (r *UnconditionalRecursionRule) Apply(file *lint.File, _ lint.Arguments) []
} }
// Name returns the rule name. // Name returns the rule name.
func (r *UnconditionalRecursionRule) Name() string { func (*UnconditionalRecursionRule) Name() string {
return "unconditional-recursion" return "unconditional-recursion"
} }
@ -151,7 +151,7 @@ var exitFunctions = map[string]map[string]bool{
}, },
} }
func (w *lintUnconditionalRecursionRule) hasControlExit(node ast.Node) bool { func (lintUnconditionalRecursionRule) hasControlExit(node ast.Node) bool {
// isExit returns true if the given node makes control exit the function // isExit returns true if the given node makes control exit the function
isExit := func(node ast.Node) bool { isExit := func(node ast.Node) bool {
switch n := node.(type) { switch n := node.(type) {

View File

@ -12,7 +12,7 @@ import (
type UnexportedNamingRule struct{} type UnexportedNamingRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *UnexportedNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*UnexportedNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
failures = append(failures, failure) failures = append(failures, failure)
@ -25,7 +25,7 @@ func (r *UnexportedNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.F
} }
// Name returns the rule name. // Name returns the rule name.
func (r *UnexportedNamingRule) Name() string { func (*UnexportedNamingRule) Name() string {
return "unexported-naming" return "unexported-naming"
} }

View File

@ -12,7 +12,7 @@ import (
type UnexportedReturnRule struct{} type UnexportedReturnRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *UnexportedReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*UnexportedReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
fileAst := file.AST fileAst := file.AST
@ -31,7 +31,7 @@ func (r *UnexportedReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.F
} }
// Name returns the rule name. // Name returns the rule name.
func (r *UnexportedReturnRule) Name() string { func (*UnexportedReturnRule) Name() string {
return "unexported-return" return "unexported-return"
} }
@ -82,24 +82,24 @@ func (w lintUnexportedReturn) Visit(n ast.Node) ast.Visitor {
// It is imprecise, and will err on the side of returning true, // It is imprecise, and will err on the side of returning true,
// such as for composite types. // such as for composite types.
func exportedType(typ types.Type) bool { func exportedType(typ types.Type) bool {
switch T := typ.(type) { switch t := typ.(type) {
case *types.Named: case *types.Named:
obj := T.Obj() obj := t.Obj()
switch { switch {
// Builtin types have no package. // Builtin types have no package.
case obj.Pkg() == nil: case obj.Pkg() == nil:
case obj.Exported(): case obj.Exported():
default: default:
_, ok := T.Underlying().(*types.Interface) _, ok := t.Underlying().(*types.Interface)
return ok return ok
} }
return true return true
case *types.Map: case *types.Map:
return exportedType(T.Key()) && exportedType(T.Elem()) return exportedType(t.Key()) && exportedType(t.Elem())
case interface { case interface {
Elem() types.Type Elem() types.Type
}: // array, slice, pointer, chan }: // array, slice, pointer, chan
return exportedType(T.Elem()) return exportedType(t.Elem())
} }
// Be conservative about other types, such as struct, interface, etc. // Be conservative about other types, such as struct, interface, etc.
return true return true

View File

@ -55,7 +55,7 @@ func (r *UnhandledErrorRule) Apply(file *lint.File, args lint.Arguments) []lint.
} }
// Name returns the rule name. // Name returns the rule name.
func (r *UnhandledErrorRule) Name() string { func (*UnhandledErrorRule) Name() string {
return "unhandled-error" return "unhandled-error"
} }

View File

@ -11,7 +11,7 @@ import (
type UnnecessaryStmtRule struct{} type UnnecessaryStmtRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *UnnecessaryStmtRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*UnnecessaryStmtRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
failures = append(failures, failure) failures = append(failures, failure)
@ -23,7 +23,7 @@ func (r *UnnecessaryStmtRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fa
} }
// Name returns the rule name. // Name returns the rule name.
func (r *UnnecessaryStmtRule) Name() string { func (*UnnecessaryStmtRule) Name() string {
return "unnecessary-stmt" return "unnecessary-stmt"
} }

View File

@ -10,7 +10,7 @@ import (
type UnreachableCodeRule struct{} type UnreachableCodeRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *UnreachableCodeRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*UnreachableCodeRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
failures = append(failures, failure) failures = append(failures, failure)
@ -34,7 +34,7 @@ func (r *UnreachableCodeRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fa
} }
// Name returns the rule name. // Name returns the rule name.
func (r *UnreachableCodeRule) Name() string { func (*UnreachableCodeRule) Name() string {
return "unreachable-code" return "unreachable-code"
} }

View File

@ -11,7 +11,7 @@ import (
type UnusedParamRule struct{} type UnusedParamRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *UnusedParamRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*UnusedParamRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -26,7 +26,7 @@ func (r *UnusedParamRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failur
} }
// Name returns the rule name. // Name returns the rule name.
func (r *UnusedParamRule) Name() string { func (*UnusedParamRule) Name() string {
return "unused-parameter" return "unused-parameter"
} }

View File

@ -10,7 +10,7 @@ import (
type UseAnyRule struct{} type UseAnyRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *UseAnyRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*UseAnyRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
walker := lintUseAny{ walker := lintUseAny{
@ -25,7 +25,7 @@ func (r *UseAnyRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
} }
// Name returns the rule name. // Name returns the rule name.
func (r *UseAnyRule) Name() string { func (*UseAnyRule) Name() string {
return "use-any" return "use-any"
} }

View File

@ -11,7 +11,7 @@ import (
type UselessBreak struct{} type UselessBreak struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *UselessBreak) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*UselessBreak) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -25,7 +25,7 @@ func (r *UselessBreak) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
} }
// Name returns the rule name. // Name returns the rule name.
func (r *UselessBreak) Name() string { func (*UselessBreak) Name() string {
return "useless-break" return "useless-break"
} }

View File

@ -13,8 +13,6 @@ import (
"github.com/mgechev/revive/lint" "github.com/mgechev/revive/lint"
) )
const styleGuideBase = "https://golang.org/wiki/CodeReviewComments"
// isBlank returns whether id is the blank identifier "_". // isBlank returns whether id is the blank identifier "_".
// If id == nil, the answer is false. // If id == nil, the answer is false.
func isBlank(id *ast.Ident) bool { return id != nil && id.Name == "_" } func isBlank(id *ast.Ident) bool { return id != nil && id.Name == "_" }
@ -82,10 +80,10 @@ var zeroLiteral = map[string]bool{
"0i": true, "0i": true,
} }
func validType(T types.Type) bool { func validType(t types.Type) bool {
return T != nil && return t != nil &&
T != types.Typ[types.Invalid] && t != types.Typ[types.Invalid] &&
!strings.Contains(T.String(), "invalid type") // good but not foolproof !strings.Contains(t.String(), "invalid type") // good but not foolproof
} }
// isPkgDot checks if the expression is <pkg>.<name> // isPkgDot checks if the expression is <pkg>.<name>

View File

@ -13,7 +13,7 @@ import (
type VarDeclarationsRule struct{} type VarDeclarationsRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *VarDeclarationsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*VarDeclarationsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
fileAst := file.AST fileAst := file.AST
@ -32,7 +32,7 @@ func (r *VarDeclarationsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fa
} }
// Name returns the rule name. // Name returns the rule name.
func (r *VarDeclarationsRule) Name() string { func (*VarDeclarationsRule) Name() string {
return "var-declaration" return "var-declaration"
} }

View File

@ -67,7 +67,7 @@ func (r *VarNamingRule) Apply(file *lint.File, arguments lint.Arguments) []lint.
} }
// Name returns the rule name. // Name returns the rule name.
func (r *VarNamingRule) Name() string { func (*VarNamingRule) Name() string {
return "var-naming" return "var-naming"
} }
@ -133,13 +133,11 @@ func check(id *ast.Ident, thing string, w *lintNames) {
} }
type lintNames struct { type lintNames struct {
file *lint.File file *lint.File
fileAst *ast.File fileAst *ast.File
lastGen *ast.GenDecl onFailure func(lint.Failure)
genDeclMissingComments map[*ast.GenDecl]bool whitelist []string
onFailure func(lint.Failure) blacklist []string
whitelist []string
blacklist []string
} }
func (w *lintNames) Visit(n ast.Node) ast.Visitor { func (w *lintNames) Visit(n ast.Node) ast.Visitor {

View File

@ -10,7 +10,7 @@ import (
type WaitGroupByValueRule struct{} type WaitGroupByValueRule struct{}
// Apply applies the rule to given file. // Apply applies the rule to given file.
func (r *WaitGroupByValueRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { func (*WaitGroupByValueRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure var failures []lint.Failure
onFailure := func(failure lint.Failure) { onFailure := func(failure lint.Failure) {
@ -23,7 +23,7 @@ func (r *WaitGroupByValueRule) Apply(file *lint.File, _ lint.Arguments) []lint.F
} }
// Name returns the rule name. // Name returns the rule name.
func (r *WaitGroupByValueRule) Name() string { func (*WaitGroupByValueRule) Name() string {
return "waitgroup-by-value" return "waitgroup-by-value"
} }

View File

@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"go/ast" "go/ast"
"go/parser" "go/parser"
"go/printer"
"go/token" "go/token"
"go/types" "go/types"
"io/ioutil" "io/ioutil"
@ -200,14 +199,6 @@ func extractReplacement(line string) (string, bool) {
return line[a+len(start) : b], true return line[a+len(start) : b], true
} }
func render(fset *token.FileSet, x interface{}) string {
var buf bytes.Buffer
if err := printer.Fprint(&buf, fset, x); err != nil {
panic(err)
}
return buf.String()
}
func srcLine(src []byte, p token.Position) string { func srcLine(src []byte, p token.Position) string {
// Run to end of line in both directions if not at line start/end. // Run to end of line in both directions if not at line start/end.
lo, hi := p.Offset, p.Offset+1 lo, hi := p.Offset, p.Offset+1
@ -288,16 +279,16 @@ func TestLintName(t *testing.T) { //revive:disable-line:exported
// It is imprecise, and will err on the side of returning true, // It is imprecise, and will err on the side of returning true,
// such as for composite types. // such as for composite types.
func exportedType(typ types.Type) bool { func exportedType(typ types.Type) bool {
switch T := typ.(type) { switch t := typ.(type) {
case *types.Named: case *types.Named:
// Builtin types have no package. // Builtin types have no package.
return T.Obj().Pkg() == nil || T.Obj().Exported() return t.Obj().Pkg() == nil || t.Obj().Exported()
case *types.Map: case *types.Map:
return exportedType(T.Key()) && exportedType(T.Elem()) return exportedType(t.Key()) && exportedType(t.Elem())
case interface { case interface {
Elem() types.Type Elem() types.Type
}: // array, slice, pointer, chan }: // array, slice, pointer, chan
return exportedType(T.Elem()) return exportedType(t.Elem())
} }
// Be conservative about other types, such as struct, interface, etc. // Be conservative about other types, such as struct, interface, etc.
return true return true