Skip to content

Commit

Permalink
Better package and function naming (#12)
Browse files Browse the repository at this point in the history
Make the exported package name less generic and follow best practices
for function names when viewed in conjunction with the package name.
Also add exported flag names so they can be referenced in other
packages/projects
  • Loading branch information
ashmrtn authored Jun 19, 2023
2 parents 322c4d3 + 4b7a9bc commit ec3c340
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 114 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package main
import (
"golang.org/x/tools/go/analysis/singlechecker"

"github.com/ashmrtn/commentmimic/pkg/analyzer"
"github.com/ashmrtn/commentmimic/pkg/commentmimic"
)

func main() {
a := analyzer.NewCommentMimic()
a := commentmimic.New()
singlechecker.Main(a)
}
22 changes: 15 additions & 7 deletions pkg/analyzer/analyzer.go → pkg/commentmimic/commentmimic.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package analyzer
package commentmimic

import (
"flag"
Expand Down Expand Up @@ -361,6 +361,14 @@ func (m mimic) run(pass *analysis.Pass) (any, error) {
return nil, nil
}

const (
CommentExportedFuncsFlag = "comment-exported"
CommentAllExportedFuncsFlag = "comment-all-exported"
CommentInterfacesFlag = "comment-interfaces"
NoTestCommentsFlag = "no-test-comments"
CommentStructsFlag = "comment-structs"
)

type mimic struct {
commentExportedFuncs bool
commentAllExportedFuncs bool
Expand All @@ -369,41 +377,41 @@ type mimic struct {
noTestComments bool
}

func NewCommentMimic() *analysis.Analyzer {
func New() *analysis.Analyzer {
m := mimic{}

fs := flag.NewFlagSet("CommentMimicFlags", flag.ExitOnError)
fs.BoolVar(
&m.commentExportedFuncs,
"comment-exported",
CommentExportedFuncsFlag,
false,
"require comments on exported functions if their receiver is also exported",
)

fs.BoolVar(
&m.commentAllExportedFuncs,
"comment-all-exported",
CommentAllExportedFuncsFlag,
false,
"require comments on all exported functions",
)

fs.BoolVar(
&m.commentInterfaces,
"comment-interfaces",
CommentInterfacesFlag,
false,
"require comments on all exported interfaces",
)

fs.BoolVar(
&m.noTestComments,
"no-test-comments",
NoTestCommentsFlag,
true,
"don't require comments on tests, benchmarks, examples, and fuzz tests",
)

fs.BoolVar(
&m.commentStructs,
"comment-structs",
CommentStructsFlag,
false,
"require comments on all exported structs",
)
Expand Down
Loading

0 comments on commit ec3c340

Please sign in to comment.