-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add decorder linter #2453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add decorder linter #2453
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e3e1184
add decorder linter
bosix 9e5155b
Resolve conflicts of golangci-lint base repo
bosix be7a182
disable rules of decorder by default
bosix e0ad1df
disable rules of decorder when no config is given
bosix cc587f8
add import to decorder test to prevent side effects
bosix 29302cb
review: compatibility with go1.16
ldez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,19 @@ | ||
// args: -Edecorder | ||
//config_path: testdata/configs/decorder.yml | ||
package testdata | ||
|
||
const ( | ||
decoc = 1 | ||
ldez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 hidden or 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,18 @@ | ||
// args: -Edecorder | ||
package testdata | ||
|
||
const ( | ||
decoh = 1 | ||
decoi = 1 | ||
) | ||
|
||
var decoj = 1 | ||
var decok = 1 | ||
|
||
type decol int | ||
|
||
func decom() { | ||
const decon = 1 | ||
} | ||
|
||
func init() {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.