Skip to content

Commit

Permalink
Merge pull request #8 from k1LoW/disable
Browse files Browse the repository at this point in the history
Support `-disable` option
  • Loading branch information
k1LoW committed Sep 11, 2023
2 parents 8cec140 + 692d2c9 commit a6df0a0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion analyzer/effective/ifacenames/ifacenames.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ const (
msg = "by convention, one-method interfaces are named by the method name plus an -er suffix or similar modification to construct an agent noun. (ref: https://go.dev/doc/effective_go#interface-names)"
)

var all bool
var (
disable bool
all bool
)

// Analyzer based on https://go.dev/doc/effective_go#interface-names.
var Analyzer = &analysis.Analyzer{
Expand All @@ -33,6 +36,9 @@ var Analyzer = &analysis.Analyzer{
}

func run(pass *analysis.Pass) (any, error) {
if disable {
return nil, nil
}
i, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
if !ok {
return nil, fmt.Errorf("unexpected result type from inspect: %T", pass.ResultOf[inspect.Analyzer])
Expand Down Expand Up @@ -71,5 +77,6 @@ func run(pass *analysis.Pass) (any, error) {
}

func init() {
Analyzer.Flags.BoolVar(&disable, "disable", false, "disable "+name+" analyzer")
Analyzer.Flags.BoolVar(&all, "all", false, "all interface names with the -er suffix are required")
}
9 changes: 9 additions & 0 deletions analyzer/guide/mixedcaps/mixedcaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const (
msg = "Go source code uses MixedCaps or mixedCaps (camel case) rather than underscores (snake case) when writing multi-word names. (ref: https://google.github.io/styleguide/go/guide#mixed-caps)"
)

var disable bool

// Analyzer based on https://google.github.io/styleguide/go/guide#mixed-caps
var Analyzer = &analysis.Analyzer{
Name: name,
Expand All @@ -30,6 +32,9 @@ var Analyzer = &analysis.Analyzer{
}

func run(pass *analysis.Pass) (any, error) {
if disable {
return nil, nil
}
i, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
if !ok {
return nil, fmt.Errorf("unexpected result type from inspect: %T", pass.ResultOf[inspect.Analyzer])
Expand Down Expand Up @@ -61,3 +66,7 @@ func run(pass *analysis.Pass) (any, error) {
r.Report()
return nil, nil
}

func init() {
Analyzer.Flags.BoolVar(&disable, "disable", false, "disable "+name+" analyzer")
}

0 comments on commit a6df0a0

Please sign in to comment.