forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package golinters | ||
|
||
import ( | ||
"strings" | ||
|
||
"gitlab.com/bosi/decorder" | ||
"golang.org/x/tools/go/analysis" | ||
|
||
"github.com/golangci/golangci-lint/pkg/config" | ||
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis" | ||
) | ||
|
||
func NewDecorder(settings *config.DecorderSettings) *goanalysis.Linter { | ||
a := decorder.Analyzer | ||
|
||
analyzers := []*analysis.Analyzer{a} | ||
|
||
// disable all rules/checks by default | ||
cfg := map[string]interface{}{ | ||
"disable-dec-num-check": true, | ||
"disable-dec-order-check": true, | ||
"disable-init-func-first-check": true, | ||
} | ||
|
||
if settings != nil { | ||
cfg["dec-order"] = strings.Join(settings.DecOrder, ",") | ||
cfg["disable-dec-num-check"] = settings.DisableDecNumCheck | ||
cfg["disable-dec-order-check"] = settings.DisableDecOrderCheck | ||
cfg["disable-init-func-first-check"] = settings.DisableInitFuncFirstCheck | ||
} | ||
|
||
return goanalysis.NewLinter( | ||
a.Name, | ||
a.Doc, | ||
analyzers, | ||
map[string]map[string]interface{}{a.Name: cfg}, | ||
).WithLoadMode(goanalysis.LoadModeSyntax) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
linters-settings: | ||
decorder: | ||
dec-order: | ||
- type | ||
- const | ||
- var | ||
- func | ||
disable-dec-order-check: false | ||
disable-init-func-first-check: false | ||
disable-dec-num-check: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// args: -Edecorder | ||
// config_path: testdata/configs/decorder.yml | ||
package testdata | ||
|
||
import "math" | ||
|
||
const ( | ||
decoc = math.MaxInt64 | ||
decod = 1 | ||
) | ||
|
||
var decoa = 1 | ||
var decob = 1 // ERROR "multiple \"var\" declarations are not allowed; use parentheses instead" | ||
|
||
type decoe int // ERROR "type must not be placed after const" | ||
|
||
func decof() { | ||
const decog = 1 | ||
} | ||
|
||
func init() {} // ERROR "init func must be the first function in file" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// args: -Edecorder | ||
package testdata | ||
|
||
import "math" | ||
|
||
const ( | ||
decoh = math.MaxInt64 | ||
decoi = 1 | ||
) | ||
|
||
var decoj = 1 | ||
var decok = 1 | ||
|
||
type decol int | ||
|
||
func decom() { | ||
const decon = 1 | ||
} | ||
|
||
func init() {} |