Skip to content

Commit

Permalink
dev: option to disable nolint directive check
Browse files Browse the repository at this point in the history
closes #78
  • Loading branch information
butuzov committed Jan 21, 2024
1 parent 8e544a0 commit 7148f28
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
20 changes: 14 additions & 6 deletions analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ type validator interface {
}

type analyzer struct {
once sync.Once
mu sync.RWMutex
handler validator
err error
once sync.Once
mu sync.RWMutex
handler validator
err error
diabledNolint bool

found []analysis.Diagnostic
}
Expand Down Expand Up @@ -61,8 +62,7 @@ func (a *analyzer) run(pass *analysis.Pass) (interface{}, error) {
}

// 003. Is it allowed to be checked?
// TODO(butuzov): add inline comment
if hasDisallowDirective(f.Doc) {
if !a.diabledNolint && hasDisallowDirective(f.Doc) {
return
}

Expand Down Expand Up @@ -112,6 +112,13 @@ func (a *analyzer) readConfiguration(fs *flag.FlagSet) {
return
}

// First: checking nonolint directive
val := fs.Lookup("nonolint")
if val != nil {
a.diabledNolint = fs.Lookup("nonolint").Value.String() == "true"
}

// Second: validators implementation next
if validatorImpl, ok := cnf.(validator); ok {
a.handler = validatorImpl
return
Expand All @@ -136,6 +143,7 @@ func flags() flag.FlagSet {
set := flag.NewFlagSet("", flag.PanicOnError)
set.String("allow", "", "accept-list of the comma-separated interfaces")
set.String("reject", "", "reject-list of the comma-separated interfaces")
set.Bool("nonolint", false, "disable nolint checks")
return *set
}

Expand Down
17 changes: 17 additions & 0 deletions analyzer/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ func TestAll(t *testing.T) {
},
})

tests = append(tests, testCase{
name: "Disallow Directives 2",
mask: []string{"disallow_directive_ok.go", "go.*"},
meta: map[string]string{
"reject": types.NameEmpty,
"nonolint": "true",
},
want: []string{
"dissAllowDirective1 returns interface (interface{})",
"dissAllowDirective2 returns interface (interface{})",
"dissAllowDirective3 returns interface (interface{})",
"dissAllowDirective4 returns interface (interface{})",
"dissAllowDirective5 returns interface (interface{})",
"dissAllowDirective6 returns interface (interface{})",
},
})

tests = append(tests, testCase{
name: "Error/allow",
mask: []string{"errors.go", "go.*"},
Expand Down

0 comments on commit 7148f28

Please sign in to comment.