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:
parent
31fbdb1833
commit
04728cf0de
@ -122,7 +122,7 @@ func GetLintingRules(config *lint.Config, extraRules []lint.Rule) ([]lint.Rule,
|
||||
|
||||
var lintingRules []lint.Rule
|
||||
for name, ruleConfig := range config.Rules {
|
||||
rule, ok := rulesMap[name]
|
||||
r, ok := rulesMap[name]
|
||||
if !ok {
|
||||
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
|
||||
}
|
||||
|
||||
lintingRules = append(lintingRules, rule)
|
||||
lintingRules = append(lintingRules, r)
|
||||
}
|
||||
|
||||
return lintingRules, nil
|
||||
@ -155,8 +155,8 @@ func normalizeConfig(config *lint.Config) {
|
||||
}
|
||||
if config.EnableAllRules {
|
||||
// Add to the configuration all rules not yet present in it
|
||||
for _, rule := range allRules {
|
||||
ruleName := rule.Name()
|
||||
for _, r := range allRules {
|
||||
ruleName := r.Name()
|
||||
_, alreadyInConf := config.Rules[ruleName]
|
||||
if alreadyInConf {
|
||||
continue
|
||||
@ -207,15 +207,15 @@ func GetConfig(configPath string) (*lint.Config, error) {
|
||||
// GetFormatter yields the formatter for lint failures
|
||||
func GetFormatter(formatterName string) (lint.Formatter, error) {
|
||||
formatters := getFormatters()
|
||||
formatter := formatters["default"]
|
||||
fmtr := formatters["default"]
|
||||
if formatterName != "" {
|
||||
f, ok := formatters[formatterName]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unknown formatter %v", formatterName)
|
||||
}
|
||||
formatter = f
|
||||
fmtr = f
|
||||
}
|
||||
return formatter, nil
|
||||
return fmtr, nil
|
||||
}
|
||||
|
||||
func defaultConfig() *lint.Config {
|
||||
|
@ -15,7 +15,7 @@ type Checkstyle struct {
|
||||
}
|
||||
|
||||
// Name returns the name of the formatter
|
||||
func (f *Checkstyle) Name() string {
|
||||
func (*Checkstyle) Name() string {
|
||||
return "checkstyle"
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ type issue struct {
|
||||
}
|
||||
|
||||
// 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{}
|
||||
for failure := range failures {
|
||||
buf := new(bytes.Buffer)
|
||||
|
@ -13,12 +13,12 @@ type Default struct {
|
||||
}
|
||||
|
||||
// Name returns the name of the formatter
|
||||
func (f *Default) Name() string {
|
||||
func (*Default) Name() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
// 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 {
|
||||
fmt.Printf("%v: %s\n", failure.Position.Start, failure.Failure)
|
||||
}
|
||||
|
@ -10,16 +10,6 @@ import (
|
||||
"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 {
|
||||
return color.RedString("✘")
|
||||
}
|
||||
@ -35,7 +25,7 @@ type Friendly struct {
|
||||
}
|
||||
|
||||
// Name returns the name of the formatter
|
||||
func (f *Friendly) Name() string {
|
||||
func (*Friendly) Name() string {
|
||||
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)}}))
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@ -87,7 +77,7 @@ type statEntry struct {
|
||||
failures int
|
||||
}
|
||||
|
||||
func (f *Friendly) printSummary(errors, warnings int) {
|
||||
func (*Friendly) printSummary(errors, warnings int) {
|
||||
emoji := getWarningEmoji()
|
||||
if errors > 0 {
|
||||
emoji = getErrorEmoji()
|
||||
@ -136,7 +126,7 @@ func (f *Friendly) printStatistics(header string, stats map[string]int) {
|
||||
fmt.Println(f.table(formatted))
|
||||
}
|
||||
|
||||
func (f *Friendly) table(rows [][]string) string {
|
||||
func (*Friendly) table(rows [][]string) string {
|
||||
buf := new(bytes.Buffer)
|
||||
table := tablewriter.NewWriter(buf)
|
||||
table.SetBorder(false)
|
||||
|
@ -13,7 +13,7 @@ type JSON struct {
|
||||
}
|
||||
|
||||
// Name returns the name of the formatter
|
||||
func (f *JSON) Name() string {
|
||||
func (*JSON) Name() string {
|
||||
return "json"
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ type jsonObject struct {
|
||||
}
|
||||
|
||||
// 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
|
||||
for failure := range failures {
|
||||
obj := jsonObject{}
|
||||
|
@ -14,12 +14,12 @@ type NDJSON struct {
|
||||
}
|
||||
|
||||
// Name returns the name of the formatter
|
||||
func (f *NDJSON) Name() string {
|
||||
func (*NDJSON) Name() string {
|
||||
return "ndjson"
|
||||
}
|
||||
|
||||
// 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)
|
||||
for failure := range failures {
|
||||
obj := jsonObject{}
|
||||
|
@ -13,12 +13,12 @@ type Plain struct {
|
||||
}
|
||||
|
||||
// Name returns the name of the formatter
|
||||
func (f *Plain) Name() string {
|
||||
func (*Plain) Name() string {
|
||||
return "plain"
|
||||
}
|
||||
|
||||
// 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 {
|
||||
fmt.Printf("%v: %s %s\n", failure.Position.Start, failure.Failure, "https://revive.run/r#"+failure.RuleName)
|
||||
}
|
||||
|
@ -16,14 +16,14 @@ type Sarif struct {
|
||||
}
|
||||
|
||||
// Name returns the name of the formatter
|
||||
func (f *Sarif) Name() string {
|
||||
func (*Sarif) Name() string {
|
||||
return "sarif"
|
||||
}
|
||||
|
||||
const reviveSite = "https://revive.run"
|
||||
|
||||
// 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)
|
||||
|
||||
for failure := range failures {
|
||||
|
@ -16,7 +16,7 @@ type Stylish struct {
|
||||
}
|
||||
|
||||
// Name returns the name of the formatter
|
||||
func (f *Stylish) Name() string {
|
||||
func (*Stylish) Name() string {
|
||||
return "stylish"
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ func formatFailure(failure lint.Failure, severity lint.Severity) []string {
|
||||
}
|
||||
|
||||
// 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
|
||||
totalErrors := 0
|
||||
total := 0
|
||||
|
@ -14,12 +14,12 @@ type Unix struct {
|
||||
}
|
||||
|
||||
// Name returns the name of the formatter
|
||||
func (f *Unix) Name() string {
|
||||
func (*Unix) Name() string {
|
||||
return "unix"
|
||||
}
|
||||
|
||||
// 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 {
|
||||
fmt.Printf("%v: [%s] %s\n", failure.Position.Start, failure.RuleName, failure.Failure)
|
||||
}
|
||||
|
@ -249,7 +249,7 @@ func (f *File) disabledIntervals(rules []Rule, mustSpecifyDisableReason bool, fa
|
||||
return getEnabledDisabledIntervals()
|
||||
}
|
||||
|
||||
func (f *File) filterFailures(failures []Failure, disabledIntervals disabledIntervalsMap) []Failure {
|
||||
func (File) filterFailures(failures []Failure, disabledIntervals disabledIntervalsMap) []Failure {
|
||||
result := []Failure{}
|
||||
for _, failure := range failures {
|
||||
fStart := failure.Position.Start.Line
|
||||
|
@ -136,7 +136,7 @@ func addInvalidFileFailure(filename, errStr string, failures chan Failure) {
|
||||
// errPosRegexp matches with an NewFile error message
|
||||
// i.e. : corrupted.go:10:4: expected '}', found 'EOF
|
||||
// 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
|
||||
func getPositionInvalidFile(filename, s string) FailurePosition {
|
||||
|
@ -28,7 +28,7 @@ func New(
|
||||
maxOpenFiles int,
|
||||
extraRules ...ExtraRule,
|
||||
) (*Revive, error) {
|
||||
log, err := logging.GetLogger()
|
||||
logger, err := logging.GetLogger()
|
||||
if err != nil {
|
||||
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")
|
||||
}
|
||||
|
||||
log.Println("Config loaded")
|
||||
logger.Println("Config loaded")
|
||||
|
||||
return &Revive{
|
||||
logger: log,
|
||||
logger: logger,
|
||||
config: conf,
|
||||
lintingRules: lintingRules,
|
||||
maxOpenFiles: maxOpenFiles,
|
||||
|
@ -39,11 +39,11 @@ func TestReviveCreateInstance(t *testing.T) {
|
||||
type mockRule struct {
|
||||
}
|
||||
|
||||
func (r *mockRule) Name() string {
|
||||
func (*mockRule) Name() string {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ func (r *AddConstantRule) Apply(file *lint.File, arguments lint.Arguments) []lin
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *AddConstantRule) Name() string {
|
||||
func (*AddConstantRule) Name() string {
|
||||
return "add-constant"
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ func (r *ArgumentsLimitRule) Apply(file *lint.File, arguments lint.Arguments) []
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *ArgumentsLimitRule) Name() string {
|
||||
func (*ArgumentsLimitRule) Name() string {
|
||||
return "argument-limit"
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
type AtomicRule struct{}
|
||||
|
||||
// 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
|
||||
walker := atomic{
|
||||
pkgTypesInfo: file.Pkg.TypesInfo(),
|
||||
@ -27,7 +27,7 @@ func (r *AtomicRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *AtomicRule) Name() string {
|
||||
func (*AtomicRule) Name() string {
|
||||
return "atomic"
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ func (r *BannedCharsRule) Apply(file *lint.File, arguments lint.Arguments) []lin
|
||||
}
|
||||
|
||||
// Name returns the rule name
|
||||
func (r *BannedCharsRule) Name() string {
|
||||
func (*BannedCharsRule) Name() string {
|
||||
return bannedCharsRuleName
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
type BareReturnRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
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.
|
||||
func (r *BareReturnRule) Name() string {
|
||||
func (*BareReturnRule) Name() string {
|
||||
return "bare-return"
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
type BlankImportsRule struct{}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *BlankImportsRule) Name() string {
|
||||
func (*BlankImportsRule) Name() string {
|
||||
return "blank-imports"
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ func (r *BlankImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failu
|
||||
return failures
|
||||
}
|
||||
|
||||
func (r *BlankImportsRule) fileHasValidEmbedComment(fileAst *ast.File) bool {
|
||||
func (*BlankImportsRule) fileHasValidEmbedComment(fileAst *ast.File) bool {
|
||||
for _, commentGroup := range fileAst.Comments {
|
||||
for _, comment := range commentGroup.List {
|
||||
if strings.HasPrefix(comment.Text, "//go:embed ") {
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
type BoolLiteralRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
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.
|
||||
func (r *BoolLiteralRule) Name() string {
|
||||
func (*BoolLiteralRule) Name() string {
|
||||
return "bool-literal-in-expr"
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
type CallToGCRule struct{}
|
||||
|
||||
// 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
|
||||
onFailure := func(failure lint.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.
|
||||
func (r *CallToGCRule) Name() string {
|
||||
func (*CallToGCRule) Name() string {
|
||||
return "call-to-gc"
|
||||
}
|
||||
|
||||
|
@ -44,13 +44,13 @@ func (r *CognitiveComplexityRule) Apply(file *lint.File, arguments lint.Argument
|
||||
},
|
||||
}
|
||||
|
||||
linter.lint()
|
||||
linter.lintCognitiveComplexity()
|
||||
|
||||
return failures
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *CognitiveComplexityRule) Name() string {
|
||||
func (*CognitiveComplexityRule) Name() string {
|
||||
return "cognitive-complexity"
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ type cognitiveComplexityLinter struct {
|
||||
onFailure func(lint.Failure)
|
||||
}
|
||||
|
||||
func (w cognitiveComplexityLinter) lint() {
|
||||
func (w cognitiveComplexityLinter) lintCognitiveComplexity() {
|
||||
f := w.file
|
||||
for _, decl := range f.AST.Decls {
|
||||
if fn, ok := decl.(*ast.FuncDecl); ok && fn.Body != nil {
|
||||
|
@ -48,7 +48,7 @@ var allPkgs = packages{pkgs: make([]pkgMethods, 1)}
|
||||
type ConfusingNamingRule struct{}
|
||||
|
||||
// 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
|
||||
fileAst := file.AST
|
||||
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.
|
||||
func (r *ConfusingNamingRule) Name() string {
|
||||
func (*ConfusingNamingRule) Name() string {
|
||||
return "confusing-naming"
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
type ConfusingResultsRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
fileAst := file.AST
|
||||
@ -26,7 +26,7 @@ func (r *ConfusingResultsRule) Apply(file *lint.File, _ lint.Arguments) []lint.F
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *ConfusingResultsRule) Name() string {
|
||||
func (*ConfusingResultsRule) Name() string {
|
||||
return "confusing-results"
|
||||
}
|
||||
|
||||
@ -60,7 +60,6 @@ func (w lintConfusingResults) Visit(n ast.Node) ast.Visitor {
|
||||
break
|
||||
}
|
||||
lastType = t.Name
|
||||
|
||||
}
|
||||
|
||||
return w
|
||||
|
@ -25,7 +25,7 @@ func (r *ConstantLogicalExprRule) Apply(file *lint.File, _ lint.Arguments) []lin
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *ConstantLogicalExprRule) Name() string {
|
||||
func (*ConstantLogicalExprRule) Name() string {
|
||||
return "constant-logical-expr"
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,6 @@ type ContextAsArgumentRule struct {
|
||||
|
||||
// Apply applies the rule to given file.
|
||||
func (r *ContextAsArgumentRule) Apply(file *lint.File, args lint.Arguments) []lint.Failure {
|
||||
|
||||
r.Lock()
|
||||
if r.allowTypesLUT == nil {
|
||||
r.allowTypesLUT = getAllowTypesFromArguments(args)
|
||||
@ -40,7 +39,7 @@ func (r *ContextAsArgumentRule) Apply(file *lint.File, args lint.Arguments) []li
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *ContextAsArgumentRule) Name() string {
|
||||
func (*ContextAsArgumentRule) Name() string {
|
||||
return "context-as-argument"
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
type ContextKeysType struct{}
|
||||
|
||||
// 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
|
||||
|
||||
fileAst := file.AST
|
||||
@ -31,7 +31,7 @@ func (r *ContextKeysType) Apply(file *lint.File, _ lint.Arguments) []lint.Failur
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *ContextKeysType) Name() string {
|
||||
func (*ContextKeysType) Name() string {
|
||||
return "context-keys-type"
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ func (r *CyclomaticRule) Apply(file *lint.File, arguments lint.Arguments) []lint
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *CyclomaticRule) Name() string {
|
||||
func (*CyclomaticRule) Name() string {
|
||||
return "cyclomatic"
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
type DeepExitRule struct{}
|
||||
|
||||
// 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
|
||||
onFailure := func(failure lint.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.
|
||||
func (r *DeepExitRule) Name() string {
|
||||
func (*DeepExitRule) Name() string {
|
||||
return "deep-exit"
|
||||
}
|
||||
|
||||
|
@ -38,11 +38,11 @@ func (r *DeferRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Fail
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *DeferRule) Name() string {
|
||||
func (*DeferRule) Name() string {
|
||||
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 {
|
||||
allow := map[string]bool{
|
||||
"loop": true,
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
type DotImportsRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
fileAst := file.AST
|
||||
@ -28,7 +28,7 @@ func (r *DotImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *DotImportsRule) Name() string {
|
||||
func (*DotImportsRule) Name() string {
|
||||
return "dot-imports"
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
type DuplicatedImportsRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
impPaths := map[string]struct{}{}
|
||||
@ -34,6 +34,6 @@ func (r *DuplicatedImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *DuplicatedImportsRule) Name() string {
|
||||
func (*DuplicatedImportsRule) Name() string {
|
||||
return "duplicated-imports"
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
type EarlyReturnRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
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.
|
||||
func (r *EarlyReturnRule) Name() string {
|
||||
func (*EarlyReturnRule) Name() string {
|
||||
return "early-return"
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
type EmptyBlockRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
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.
|
||||
func (r *EmptyBlockRule) Name() string {
|
||||
func (*EmptyBlockRule) Name() string {
|
||||
return "empty-block"
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
type EmptyLinesRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
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.
|
||||
func (r *EmptyLinesRule) Name() string {
|
||||
func (*EmptyLinesRule) Name() string {
|
||||
return "empty-lines"
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
type ErrorNamingRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
fileAst := file.AST
|
||||
@ -31,7 +31,7 @@ func (r *ErrorNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failur
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *ErrorNamingRule) Name() string {
|
||||
func (*ErrorNamingRule) Name() string {
|
||||
return "error-naming"
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
type ErrorReturnRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
fileAst := file.AST
|
||||
@ -28,7 +28,7 @@ func (r *ErrorReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failur
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *ErrorReturnRule) Name() string {
|
||||
func (*ErrorReturnRule) Name() string {
|
||||
return "error-return"
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
type ErrorStringsRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
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.
|
||||
func (r *ErrorStringsRule) Name() string {
|
||||
func (*ErrorStringsRule) Name() string {
|
||||
return "error-strings"
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
type ErrorfRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
fileAst := file.AST
|
||||
@ -32,7 +32,7 @@ func (r *ErrorfRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *ErrorfRule) Name() string {
|
||||
func (*ErrorfRule) Name() string {
|
||||
return "errorf"
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ func (r *ExportedRule) Apply(file *lint.File, args lint.Arguments) []lint.Failur
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *ExportedRule) Name() string {
|
||||
func (*ExportedRule) Name() string {
|
||||
return "exported"
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ type FileHeaderRule struct {
|
||||
}
|
||||
|
||||
var (
|
||||
multiRegexp = regexp.MustCompile("^/\\*")
|
||||
multiRegexp = 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.
|
||||
func (r *FileHeaderRule) Name() string {
|
||||
func (*FileHeaderRule) Name() string {
|
||||
return "file-header"
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
type FlagParamRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
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.
|
||||
func (r *FlagParamRule) Name() string {
|
||||
func (*FlagParamRule) Name() string {
|
||||
return "flag-parameter"
|
||||
}
|
||||
|
||||
|
@ -47,11 +47,11 @@ func (r *FunctionLength) Apply(file *lint.File, arguments lint.Arguments) []lint
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *FunctionLength) Name() string {
|
||||
func (*FunctionLength) Name() string {
|
||||
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 {
|
||||
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))
|
||||
}
|
||||
|
||||
return
|
||||
return maxStmt, maxLines
|
||||
}
|
||||
|
||||
type lintFuncLength struct {
|
||||
|
@ -50,7 +50,7 @@ func (r *FunctionResultsLimitRule) Apply(file *lint.File, arguments lint.Argumen
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *FunctionResultsLimitRule) Name() string {
|
||||
func (*FunctionResultsLimitRule) Name() string {
|
||||
return "function-result-limit"
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
type GetReturnRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
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.
|
||||
func (r *GetReturnRule) Name() string {
|
||||
func (*GetReturnRule) Name() string {
|
||||
return "get-return"
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
type IdenticalBranchesRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
onFailure := func(failure lint.Failure) {
|
||||
@ -24,7 +24,7 @@ func (r *IdenticalBranchesRule) Apply(file *lint.File, _ lint.Arguments) []lint.
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *IdenticalBranchesRule) Name() string {
|
||||
func (*IdenticalBranchesRule) Name() string {
|
||||
return "identical-branches"
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ func (w *lintIdenticalBranches) Visit(node ast.Node) ast.Visitor {
|
||||
return w
|
||||
}
|
||||
|
||||
func (w *lintIdenticalBranches) identicalBranches(branches []*ast.BlockStmt) bool {
|
||||
func (lintIdenticalBranches) identicalBranches(branches []*ast.BlockStmt) bool {
|
||||
if len(branches) < 2 {
|
||||
return false
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
type IfReturnRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
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.
|
||||
func (r *IfReturnRule) Name() string {
|
||||
func (*IfReturnRule) Name() string {
|
||||
return "if-return"
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
type ImportShadowingRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
importNames := map[string]struct{}{}
|
||||
@ -37,7 +37,7 @@ func (r *ImportShadowingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fa
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *ImportShadowingRule) Name() string {
|
||||
func (*ImportShadowingRule) Name() string {
|
||||
return "import-shadowing"
|
||||
}
|
||||
|
||||
|
@ -59,6 +59,6 @@ func (r *ImportsBlacklistRule) Apply(file *lint.File, arguments lint.Arguments)
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *ImportsBlacklistRule) Name() string {
|
||||
func (*ImportsBlacklistRule) Name() string {
|
||||
return "imports-blacklist"
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
type IncrementDecrementRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
fileAst := file.AST
|
||||
@ -29,13 +29,12 @@ func (r *IncrementDecrementRule) Apply(file *lint.File, _ lint.Arguments) []lint
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *IncrementDecrementRule) Name() string {
|
||||
func (*IncrementDecrementRule) Name() string {
|
||||
return "increment-decrement"
|
||||
}
|
||||
|
||||
type lintIncrementDecrement struct {
|
||||
file *lint.File
|
||||
fileAst *ast.File
|
||||
onFailure func(lint.Failure)
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
type IndentErrorFlowRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
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.
|
||||
func (r *IndentErrorFlowRule) Name() string {
|
||||
func (*IndentErrorFlowRule) Name() string {
|
||||
return "indent-error-flow"
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ func (r *LineLengthLimitRule) Apply(file *lint.File, arguments lint.Arguments) [
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *LineLengthLimitRule) Name() string {
|
||||
func (*LineLengthLimitRule) Name() string {
|
||||
return "line-length-limit"
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ func (r *MaxPublicStructsRule) Apply(file *lint.File, arguments lint.Arguments)
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *MaxPublicStructsRule) Name() string {
|
||||
func (*MaxPublicStructsRule) Name() string {
|
||||
return "max-public-structs"
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
type ModifiesParamRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
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.
|
||||
func (r *ModifiesParamRule) Name() string {
|
||||
func (*ModifiesParamRule) Name() string {
|
||||
return "modifies-parameter"
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
type ModifiesValRecRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
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.
|
||||
func (r *ModifiesValRecRule) Name() string {
|
||||
func (*ModifiesValRecRule) Name() string {
|
||||
return "modifies-value-receiver"
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
type NestedStructs struct{}
|
||||
|
||||
// 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
|
||||
|
||||
walker := &lintNestedStructs{
|
||||
@ -26,7 +26,7 @@ func (r *NestedStructs) Apply(file *lint.File, _ lint.Arguments) []lint.Failure
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *NestedStructs) Name() string {
|
||||
func (*NestedStructs) Name() string {
|
||||
return "nested-structs"
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
type OptimizeOperandsOrderRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
onFailure := func(failure lint.Failure) {
|
||||
@ -26,7 +26,7 @@ func (r *OptimizeOperandsOrderRule) Apply(file *lint.File, _ lint.Arguments) []l
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *OptimizeOperandsOrderRule) Name() string {
|
||||
func (*OptimizeOperandsOrderRule) Name() string {
|
||||
return "optimize-operands-order"
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ import (
|
||||
type PackageCommentsRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
if file.IsTest() {
|
||||
@ -35,7 +35,7 @@ func (r *PackageCommentsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fa
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *PackageCommentsRule) Name() string {
|
||||
func (*PackageCommentsRule) Name() string {
|
||||
return "package-comments"
|
||||
}
|
||||
|
||||
@ -50,7 +50,6 @@ func (l *lintPackageComments) Visit(_ ast.Node) ast.Visitor {
|
||||
return nil
|
||||
}
|
||||
|
||||
const ref = styleGuideBase + "#package-comments"
|
||||
prefix := "Package " + l.fileAst.Name.Name + " "
|
||||
|
||||
// Look for a detached package comment.
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
type RangeValAddress struct{}
|
||||
|
||||
// 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
|
||||
|
||||
walker := rangeValAddress{
|
||||
@ -30,7 +30,7 @@ func (r *RangeValAddress) Apply(file *lint.File, _ lint.Arguments) []lint.Failur
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *RangeValAddress) Name() string {
|
||||
func (*RangeValAddress) Name() string {
|
||||
return "range-val-address"
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
type RangeValInClosureRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
walker := rangeValInClosure{
|
||||
@ -26,7 +26,7 @@ func (r *RangeValInClosureRule) Apply(file *lint.File, _ lint.Arguments) []lint.
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *RangeValInClosureRule) Name() string {
|
||||
func (*RangeValInClosureRule) Name() string {
|
||||
return "range-val-in-closure"
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
type RangeRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
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.
|
||||
func (r *RangeRule) Name() string {
|
||||
func (*RangeRule) Name() string {
|
||||
return "range"
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
type ReceiverNamingRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
fileAst := file.AST
|
||||
@ -28,7 +28,7 @@ func (r *ReceiverNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fai
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *ReceiverNamingRule) Name() string {
|
||||
func (*ReceiverNamingRule) Name() string {
|
||||
return "receiver-naming"
|
||||
}
|
||||
|
||||
@ -47,7 +47,6 @@ func (w lintReceiverName) Visit(n ast.Node) ast.Visitor {
|
||||
return w
|
||||
}
|
||||
name := names[0].Name
|
||||
const ref = styleGuideBase + "#receiver-names"
|
||||
if name == "_" {
|
||||
w.onFailure(lint.Failure{
|
||||
Node: n,
|
||||
|
@ -61,7 +61,7 @@ var builtInTypes = map[string]bool{
|
||||
type RedefinesBuiltinIDRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
onFailure := func(failure lint.Failure) {
|
||||
@ -76,7 +76,7 @@ func (r *RedefinesBuiltinIDRule) Apply(file *lint.File, _ lint.Arguments) []lint
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *RedefinesBuiltinIDRule) Name() string {
|
||||
func (*RedefinesBuiltinIDRule) Name() string {
|
||||
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] {
|
||||
return true, "function"
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
type StringFormatRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
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.
|
||||
func (r *StringFormatRule) Name() string {
|
||||
func (*StringFormatRule) Name() string {
|
||||
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
|
||||
func (r *StringFormatRule) ParseArgumentsTest(arguments lint.Arguments) *string {
|
||||
func (StringFormatRule) ParseArgumentsTest(arguments lint.Arguments) *string {
|
||||
w := lintStringFormatRule{}
|
||||
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)
|
||||
@ -61,9 +61,7 @@ func (r *StringFormatRule) ParseArgumentsTest(arguments lint.Arguments) *string
|
||||
|
||||
type lintStringFormatRule struct {
|
||||
onFailure func(lint.Failure)
|
||||
|
||||
rules []stringFormatSubrule
|
||||
stringDeclarations map[string]string
|
||||
}
|
||||
|
||||
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
|
||||
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))
|
||||
}
|
||||
|
||||
// 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))
|
||||
}
|
||||
|
||||
@ -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
|
||||
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 {
|
||||
// Local function call
|
||||
return ident.Name, true
|
||||
@ -220,14 +218,14 @@ func (w lintStringFormatRule) getCallName(call *ast.CallExpr) (callName string,
|
||||
// #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)
|
||||
func (rule stringFormatSubrule) Apply(call *ast.CallExpr) {
|
||||
if len(call.Args) <= rule.scope.argument {
|
||||
func (r *stringFormatSubrule) Apply(call *ast.CallExpr) {
|
||||
if len(call.Args) <= r.scope.argument {
|
||||
return
|
||||
}
|
||||
|
||||
arg := call.Args[rule.scope.argument]
|
||||
arg := call.Args[r.scope.argument]
|
||||
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
|
||||
composite, ok := arg.(*ast.CompositeLit)
|
||||
if !ok {
|
||||
@ -239,7 +237,7 @@ func (rule stringFormatSubrule) Apply(call *ast.CallExpr) {
|
||||
continue
|
||||
}
|
||||
key, ok := kv.Key.(*ast.Ident)
|
||||
if !ok || key.Name != rule.scope.field {
|
||||
if !ok || key.Name != r.scope.field {
|
||||
continue
|
||||
}
|
||||
|
||||
@ -259,21 +257,21 @@ func (rule stringFormatSubrule) Apply(call *ast.CallExpr) {
|
||||
}
|
||||
// Unquote the string literal before linting
|
||||
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
|
||||
if rule.regexp.MatchString(s) {
|
||||
if r.regexp.MatchString(s) {
|
||||
return
|
||||
}
|
||||
var failure string
|
||||
if len(rule.errorMessage) > 0 {
|
||||
failure = rule.errorMessage
|
||||
if len(r.errorMessage) > 0 {
|
||||
failure = r.errorMessage
|
||||
} 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,
|
||||
Failure: failure,
|
||||
Node: node,
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
type StringOfIntRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
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.
|
||||
func (r *StringOfIntRule) Name() string {
|
||||
func (*StringOfIntRule) Name() string {
|
||||
return "string-of-int"
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
type StructTagRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
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.
|
||||
func (r *StructTagRule) Name() string {
|
||||
func (*StructTagRule) Name() string {
|
||||
return "struct-tag"
|
||||
}
|
||||
|
||||
@ -148,7 +148,7 @@ func (w lintStructTagRule) checkASN1Tag(t ast.Expr, tag *structtag.Tag) (string,
|
||||
return "", true
|
||||
}
|
||||
|
||||
func (w lintStructTagRule) checkBSONTag(options []string) (string, bool) {
|
||||
func (lintStructTagRule) checkBSONTag(options []string) (string, bool) {
|
||||
for _, opt := range options {
|
||||
switch opt {
|
||||
case "inline", "minsize", "omitempty":
|
||||
@ -160,7 +160,7 @@ func (w lintStructTagRule) checkBSONTag(options []string) (string, bool) {
|
||||
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 {
|
||||
switch opt {
|
||||
case "omitempty", "string":
|
||||
@ -177,7 +177,7 @@ func (w lintStructTagRule) checkJSONTag(name string, options []string) (string,
|
||||
return "", true
|
||||
}
|
||||
|
||||
func (w lintStructTagRule) checkXMLTag(options []string) (string, bool) {
|
||||
func (lintStructTagRule) checkXMLTag(options []string) (string, bool) {
|
||||
for _, opt := range options {
|
||||
switch opt {
|
||||
case "any", "attr", "cdata", "chardata", "comment", "innerxml", "omitempty", "typeattr":
|
||||
@ -189,7 +189,7 @@ func (w lintStructTagRule) checkXMLTag(options []string) (string, bool) {
|
||||
return "", true
|
||||
}
|
||||
|
||||
func (w lintStructTagRule) checkYAMLTag(options []string) (string, bool) {
|
||||
func (lintStructTagRule) checkYAMLTag(options []string) (string, bool) {
|
||||
for _, opt := range options {
|
||||
switch opt {
|
||||
case "flow", "inline", "omitempty":
|
||||
@ -201,7 +201,7 @@ func (w lintStructTagRule) checkYAMLTag(options []string) (string, bool) {
|
||||
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)
|
||||
if !ok {
|
||||
return true
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
type SuperfluousElseRule struct{}
|
||||
|
||||
// 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
|
||||
onFailure := func(failure lint.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.
|
||||
func (r *SuperfluousElseRule) Name() string {
|
||||
func (*SuperfluousElseRule) Name() string {
|
||||
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]
|
||||
switch stmt := lastStmt.(type) {
|
||||
case *ast.BranchStmt:
|
||||
token := stmt.Tok.String()
|
||||
if token != "fallthrough" {
|
||||
w.onFailure(newFailure(ifStmt.Else, "if block ends with a "+token+" statement, so drop this else and outdent its block"+extra))
|
||||
tok := stmt.Tok.String()
|
||||
if tok != "fallthrough" {
|
||||
w.onFailure(newFailure(ifStmt.Else, "if block ends with a "+tok+" statement, so drop this else and outdent its block"+extra))
|
||||
}
|
||||
case *ast.ExprStmt:
|
||||
if ce, ok := stmt.X.(*ast.CallExpr); ok { // it's a function call
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
type TimeNamingRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
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.
|
||||
func (r *TimeNamingRule) Name() string {
|
||||
func (*TimeNamingRule) Name() string {
|
||||
return "time-naming"
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
type UnconditionalRecursionRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
onFailure := func(failure lint.Failure) {
|
||||
@ -23,7 +23,7 @@ func (r *UnconditionalRecursionRule) Apply(file *lint.File, _ lint.Arguments) []
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *UnconditionalRecursionRule) Name() string {
|
||||
func (*UnconditionalRecursionRule) Name() string {
|
||||
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 := func(node ast.Node) bool {
|
||||
switch n := node.(type) {
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
type UnexportedNamingRule struct{}
|
||||
|
||||
// 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
|
||||
onFailure := func(failure lint.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.
|
||||
func (r *UnexportedNamingRule) Name() string {
|
||||
func (*UnexportedNamingRule) Name() string {
|
||||
return "unexported-naming"
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
type UnexportedReturnRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
fileAst := file.AST
|
||||
@ -31,7 +31,7 @@ func (r *UnexportedReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.F
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *UnexportedReturnRule) Name() string {
|
||||
func (*UnexportedReturnRule) Name() string {
|
||||
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,
|
||||
// such as for composite types.
|
||||
func exportedType(typ types.Type) bool {
|
||||
switch T := typ.(type) {
|
||||
switch t := typ.(type) {
|
||||
case *types.Named:
|
||||
obj := T.Obj()
|
||||
obj := t.Obj()
|
||||
switch {
|
||||
// Builtin types have no package.
|
||||
case obj.Pkg() == nil:
|
||||
case obj.Exported():
|
||||
default:
|
||||
_, ok := T.Underlying().(*types.Interface)
|
||||
_, ok := t.Underlying().(*types.Interface)
|
||||
return ok
|
||||
}
|
||||
return true
|
||||
case *types.Map:
|
||||
return exportedType(T.Key()) && exportedType(T.Elem())
|
||||
return exportedType(t.Key()) && exportedType(t.Elem())
|
||||
case interface {
|
||||
Elem() types.Type
|
||||
}: // array, slice, pointer, chan
|
||||
return exportedType(T.Elem())
|
||||
return exportedType(t.Elem())
|
||||
}
|
||||
// Be conservative about other types, such as struct, interface, etc.
|
||||
return true
|
||||
|
@ -55,7 +55,7 @@ func (r *UnhandledErrorRule) Apply(file *lint.File, args lint.Arguments) []lint.
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *UnhandledErrorRule) Name() string {
|
||||
func (*UnhandledErrorRule) Name() string {
|
||||
return "unhandled-error"
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
type UnnecessaryStmtRule struct{}
|
||||
|
||||
// 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
|
||||
onFailure := func(failure lint.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.
|
||||
func (r *UnnecessaryStmtRule) Name() string {
|
||||
func (*UnnecessaryStmtRule) Name() string {
|
||||
return "unnecessary-stmt"
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
type UnreachableCodeRule struct{}
|
||||
|
||||
// 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
|
||||
onFailure := func(failure lint.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.
|
||||
func (r *UnreachableCodeRule) Name() string {
|
||||
func (*UnreachableCodeRule) Name() string {
|
||||
return "unreachable-code"
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
type UnusedParamRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
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.
|
||||
func (r *UnusedParamRule) Name() string {
|
||||
func (*UnusedParamRule) Name() string {
|
||||
return "unused-parameter"
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
type UseAnyRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
walker := lintUseAny{
|
||||
@ -25,7 +25,7 @@ func (r *UseAnyRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *UseAnyRule) Name() string {
|
||||
func (*UseAnyRule) Name() string {
|
||||
return "use-any"
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
type UselessBreak struct{}
|
||||
|
||||
// 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
|
||||
|
||||
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.
|
||||
func (r *UselessBreak) Name() string {
|
||||
func (*UselessBreak) Name() string {
|
||||
return "useless-break"
|
||||
}
|
||||
|
||||
|
@ -13,8 +13,6 @@ import (
|
||||
"github.com/mgechev/revive/lint"
|
||||
)
|
||||
|
||||
const styleGuideBase = "https://golang.org/wiki/CodeReviewComments"
|
||||
|
||||
// isBlank returns whether id is the blank identifier "_".
|
||||
// If id == nil, the answer is false.
|
||||
func isBlank(id *ast.Ident) bool { return id != nil && id.Name == "_" }
|
||||
@ -82,10 +80,10 @@ var zeroLiteral = map[string]bool{
|
||||
"0i": true,
|
||||
}
|
||||
|
||||
func validType(T types.Type) bool {
|
||||
return T != nil &&
|
||||
T != types.Typ[types.Invalid] &&
|
||||
!strings.Contains(T.String(), "invalid type") // good but not foolproof
|
||||
func validType(t types.Type) bool {
|
||||
return t != nil &&
|
||||
t != types.Typ[types.Invalid] &&
|
||||
!strings.Contains(t.String(), "invalid type") // good but not foolproof
|
||||
}
|
||||
|
||||
// isPkgDot checks if the expression is <pkg>.<name>
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
type VarDeclarationsRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
fileAst := file.AST
|
||||
@ -32,7 +32,7 @@ func (r *VarDeclarationsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Fa
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *VarDeclarationsRule) Name() string {
|
||||
func (*VarDeclarationsRule) Name() string {
|
||||
return "var-declaration"
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ func (r *VarNamingRule) Apply(file *lint.File, arguments lint.Arguments) []lint.
|
||||
}
|
||||
|
||||
// Name returns the rule name.
|
||||
func (r *VarNamingRule) Name() string {
|
||||
func (*VarNamingRule) Name() string {
|
||||
return "var-naming"
|
||||
}
|
||||
|
||||
@ -135,8 +135,6 @@ func check(id *ast.Ident, thing string, w *lintNames) {
|
||||
type lintNames struct {
|
||||
file *lint.File
|
||||
fileAst *ast.File
|
||||
lastGen *ast.GenDecl
|
||||
genDeclMissingComments map[*ast.GenDecl]bool
|
||||
onFailure func(lint.Failure)
|
||||
whitelist []string
|
||||
blacklist []string
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
type WaitGroupByValueRule struct{}
|
||||
|
||||
// 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
|
||||
|
||||
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.
|
||||
func (r *WaitGroupByValueRule) Name() string {
|
||||
func (*WaitGroupByValueRule) Name() string {
|
||||
return "waitgroup-by-value"
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/printer"
|
||||
"go/token"
|
||||
"go/types"
|
||||
"io/ioutil"
|
||||
@ -200,14 +199,6 @@ func extractReplacement(line string) (string, bool) {
|
||||
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 {
|
||||
// Run to end of line in both directions if not at line start/end.
|
||||
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,
|
||||
// such as for composite types.
|
||||
func exportedType(typ types.Type) bool {
|
||||
switch T := typ.(type) {
|
||||
switch t := typ.(type) {
|
||||
case *types.Named:
|
||||
// Builtin types have no package.
|
||||
return T.Obj().Pkg() == nil || T.Obj().Exported()
|
||||
return t.Obj().Pkg() == nil || t.Obj().Exported()
|
||||
case *types.Map:
|
||||
return exportedType(T.Key()) && exportedType(T.Elem())
|
||||
return exportedType(t.Key()) && exportedType(t.Elem())
|
||||
case interface {
|
||||
Elem() types.Type
|
||||
}: // array, slice, pointer, chan
|
||||
return exportedType(T.Elem())
|
||||
return exportedType(t.Elem())
|
||||
}
|
||||
// Be conservative about other types, such as struct, interface, etc.
|
||||
return true
|
||||
|
Loading…
x
Reference in New Issue
Block a user