From 5ccebe86c2071d61a4c3b1cf85916924c3167a4b Mon Sep 17 00:00:00 2001 From: chavacava Date: Sat, 23 Sep 2023 10:41:34 +0200 Subject: [PATCH] Code cleaunp (#905) * fix minor lint issue * fix package comments * fix comments * removes extra empty lines * fix import alias name --- cli/main.go | 1 + config/config.go | 1 + formatter/checkstyle.go | 4 ++-- formatter/doc.go | 2 ++ lint/config.go | 1 + lint/doc.go | 2 ++ logging/logger.go | 1 + main.go | 1 + revivelib/core.go | 1 + rule/comment-spacings.go | 4 +++- rule/confusing-naming.go | 1 - rule/defer.go | 2 +- rule/doc.go | 2 ++ rule/struct-tag.go | 2 +- test/comment-spacings_test.go | 1 - test/doc.go | 2 ++ test/utils.go | 2 +- 17 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 formatter/doc.go create mode 100644 lint/doc.go create mode 100644 rule/doc.go create mode 100644 test/doc.go diff --git a/cli/main.go b/cli/main.go index a07e31b5d..190f1e93e 100644 --- a/cli/main.go +++ b/cli/main.go @@ -1,3 +1,4 @@ +// Package cli implements the revive command line application. package cli import ( diff --git a/config/config.go b/config/config.go index 1ebd9c4ac..c4ba0e7b4 100644 --- a/config/config.go +++ b/config/config.go @@ -1,3 +1,4 @@ +// Package config implements revive's configuration data structures and related methods package config import ( diff --git a/formatter/checkstyle.go b/formatter/checkstyle.go index 33a3b2ca1..f45b63c92 100644 --- a/formatter/checkstyle.go +++ b/formatter/checkstyle.go @@ -3,7 +3,7 @@ package formatter import ( "bytes" "encoding/xml" - plainTemplate "text/template" + plain "text/template" "github.com/mgechev/revive/lint" ) @@ -50,7 +50,7 @@ func (*Checkstyle) Format(failures <-chan lint.Failure, config lint.Config) (str issues[fn] = append(issues[fn], iss) } - t, err := plainTemplate.New("revive").Parse(checkstyleTemplate) + t, err := plain.New("revive").Parse(checkstyleTemplate) if err != nil { return "", err } diff --git a/formatter/doc.go b/formatter/doc.go new file mode 100644 index 000000000..bb89f20ea --- /dev/null +++ b/formatter/doc.go @@ -0,0 +1,2 @@ +// Package formatter implements the linter output formatters. +package formatter diff --git a/lint/config.go b/lint/config.go index 9b26d5841..b0ccd8728 100644 --- a/lint/config.go +++ b/lint/config.go @@ -3,6 +3,7 @@ package lint // Arguments is type used for the arguments of a rule. type Arguments = []interface{} +// FileFilters is type used for modeling file filters to apply to rules. type FileFilters = []*FileFilter // RuleConfig is type used for the rule configuration. diff --git a/lint/doc.go b/lint/doc.go new file mode 100644 index 000000000..7048adf4b --- /dev/null +++ b/lint/doc.go @@ -0,0 +1,2 @@ +// Package lint implements the linting machinery. +package lint diff --git a/logging/logger.go b/logging/logger.go index 9d603a4ef..24305b968 100644 --- a/logging/logger.go +++ b/logging/logger.go @@ -1,3 +1,4 @@ +// Package logging provides a logger and related methods. package logging import ( diff --git a/main.go b/main.go index 50694cbd9..5167ec6de 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,4 @@ +// Package main is the build entry point of revive. package main import "github.com/mgechev/revive/cli" diff --git a/revivelib/core.go b/revivelib/core.go index a275e9e90..ab2eca74b 100644 --- a/revivelib/core.go +++ b/revivelib/core.go @@ -1,3 +1,4 @@ +// Package revivelib provides revive's linting functionality as a lib. package revivelib import ( diff --git a/rule/comment-spacings.go b/rule/comment-spacings.go index 0d75c55f3..2b8240ca5 100644 --- a/rule/comment-spacings.go +++ b/rule/comment-spacings.go @@ -8,7 +8,7 @@ import ( "github.com/mgechev/revive/lint" ) -// CommentSpacings Rule check the whether there is a space between +// CommentSpacingsRule check the whether there is a space between // the comment symbol( // ) and the start of the comment text type CommentSpacingsRule struct { allowList []string @@ -36,6 +36,7 @@ func (r *CommentSpacingsRule) configure(arguments lint.Arguments) { } } +// Apply the rule. func (r *CommentSpacingsRule) Apply(file *lint.File, args lint.Arguments) []lint.Failure { r.configure(args) @@ -74,6 +75,7 @@ func (r *CommentSpacingsRule) Apply(file *lint.File, args lint.Arguments) []lint return failures } +// Name yields this rule name. func (*CommentSpacingsRule) Name() string { return "comment-spacings" } diff --git a/rule/confusing-naming.go b/rule/confusing-naming.go index 8b1c3eac4..daaf51c81 100644 --- a/rule/confusing-naming.go +++ b/rule/confusing-naming.go @@ -71,7 +71,6 @@ func (*ConfusingNamingRule) Name() string { // checkMethodName checks if a given method/function name is similar (just case differences) to other method/function of the same struct/file. func checkMethodName(holder string, id *ast.Ident, w *lintConfusingNames) { - if id.Name == "init" && holder == defaultStructName { // ignore init functions return diff --git a/rule/defer.go b/rule/defer.go index f3ea17920..31c54b471 100644 --- a/rule/defer.go +++ b/rule/defer.go @@ -144,8 +144,8 @@ func (w lintDeferRule) Visit(node ast.Node) ast.Visitor { w.newFailure("be careful when deferring calls to methods without pointer receiver", fn, 0.8, "bad practice", "method-call") } } - } + return nil } diff --git a/rule/doc.go b/rule/doc.go new file mode 100644 index 000000000..55bf6caa6 --- /dev/null +++ b/rule/doc.go @@ -0,0 +1,2 @@ +// Package rule implements revive's linting rules. +package rule diff --git a/rule/struct-tag.go b/rule/struct-tag.go index d1c8056aa..f6ee47a73 100644 --- a/rule/struct-tag.go +++ b/rule/struct-tag.go @@ -140,7 +140,7 @@ func (lintStructTagRule) getTagName(tag *structtag.Tag) string { return strings.TrimPrefix(option, "name=") } } - return "" //protobuf tag lacks 'name' option + return "" // protobuf tag lacks 'name' option default: return tag.Name } diff --git a/test/comment-spacings_test.go b/test/comment-spacings_test.go index d5685021b..d94fe37e4 100644 --- a/test/comment-spacings_test.go +++ b/test/comment-spacings_test.go @@ -8,7 +8,6 @@ import ( ) func TestCommentSpacings(t *testing.T) { - testRule(t, "comment-spacings", &rule.CommentSpacingsRule{}, &lint.RuleConfig{ Arguments: []interface{}{"myOwnDirective"}}, ) diff --git a/test/doc.go b/test/doc.go new file mode 100644 index 000000000..cef03c554 --- /dev/null +++ b/test/doc.go @@ -0,0 +1,2 @@ +// Package test implements rule tests. +package test diff --git a/test/utils.go b/test/utils.go index 6ebb2052e..0b3b0bd4d 100644 --- a/test/utils.go +++ b/test/utils.go @@ -106,7 +106,7 @@ func assertFailures(t *testing.T, baseDir string, fi os.FileInfo, src []byte, ru copy(failures[i:], failures[i+1:]) failures = failures[:len(failures)-1] - //t.Logf("/%v/ matched at %s:%d", in.Match, fi.Name(), in.Line) + // t.Logf("/%v/ matched at %s:%d", in.Match, fi.Name(), in.Line) ok = true break }