Skip to content

Commit

Permalink
Remove the -t flag (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch committed Jun 17, 2023
1 parent 0ab2566 commit a9cb750
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ gochecknoglobals [package]
gochecknoglobals ./...
```

By default, test files will not be checked but can be included by adding the
`-t` flag.
By default, test files are checked but can be excluded by adding the
`-test=false` flag.

```
gochecknoglobals -t [package]
gochecknoglobals -test=false [package]
```
14 changes: 0 additions & 14 deletions checknoglobals/check_no_globals.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package checknoglobals

import (
"flag"
"fmt"
"go/ast"
"go/token"
Expand Down Expand Up @@ -37,18 +36,10 @@ func Analyzer() *analysis.Analyzer {
Name: "gochecknoglobals",
Doc: Doc,
Run: checkNoGlobals,
Flags: flags(),
RunDespiteErrors: true,
}
}

func flags() flag.FlagSet {
flags := flag.NewFlagSet("", flag.ExitOnError)
flags.Bool("t", false, "Include tests")

return *flags
}

func isAllowed(cm ast.CommentMap, v ast.Node, ti *types.Info) bool {
switch i := v.(type) {
case *ast.GenDecl:
Expand Down Expand Up @@ -138,16 +129,11 @@ func hasEmbedComment(cm ast.CommentMap, n ast.Node) bool {
}

func checkNoGlobals(pass *analysis.Pass) (interface{}, error) {
includeTests := pass.Analyzer.Flags.Lookup("t").Value.(flag.Getter).Get().(bool)

for _, file := range pass.Files {
filename := pass.Fset.Position(file.Pos()).Filename
if !strings.HasSuffix(filename, ".go") {
continue
}
if !includeTests && strings.HasSuffix(filename, "_test.go") {
continue
}

fileCommentMap := ast.NewCommentMap(pass.Fset, file, file.Comments)

Expand Down

0 comments on commit a9cb750

Please sign in to comment.