-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
- Loading branch information
Showing
9 changed files
with
126 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,29 @@ | ||
package golinters | ||
|
||
import ( | ||
"github.com/junk1tm/musttag" | ||
"golang.org/x/tools/go/analysis" | ||
|
||
"github.com/golangci/golangci-lint/pkg/config" | ||
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis" | ||
) | ||
|
||
func NewMustTag(setting *config.MustTagSettings) *goanalysis.Linter { | ||
var funcs []musttag.Func | ||
|
||
if setting != nil { | ||
for _, fn := range setting.Functions { | ||
funcs = append(funcs, musttag.Func{ | ||
Name: fn.Name, | ||
Tag: fn.Tag, | ||
ArgPos: fn.ArgPos, | ||
}) | ||
} | ||
} | ||
|
||
a := musttag.New(funcs...) | ||
|
||
return goanalysis. | ||
NewLinter(a.Name, a.Doc, []*analysis.Analyzer{a}, nil). | ||
WithLoadMode(goanalysis.LoadModeTypesInfo) | ||
} |
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,9 @@ | ||
linters-settings: | ||
musttag: | ||
functions: | ||
- name: encoding/asn1.Marshal | ||
tag: asn1 | ||
arg-pos: 0 | ||
- name: encoding/asn1.Unmarshal | ||
tag: asn1 | ||
arg-pos: 1 |
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,27 @@ | ||
//golangcitest:args -Emusttag | ||
package testdata | ||
|
||
import ( | ||
"encoding/asn1" | ||
"encoding/json" | ||
) | ||
|
||
// builtin functions: | ||
func musttagJSON() { | ||
var user struct { // want `exported fields should be annotated with the "json" tag` | ||
Name string | ||
Email string `json:"email"` | ||
} | ||
json.Marshal(user) | ||
json.Unmarshal(nil, &user) | ||
} | ||
|
||
// custom functions from config: | ||
func musttagASN1() { | ||
var user struct { | ||
Name string | ||
Email string `asn1:"email"` | ||
} | ||
asn1.Marshal(user) | ||
asn1.Unmarshal(nil, &user) | ||
} |
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,28 @@ | ||
//golangcitest:args -Emusttag | ||
//golangcitest:config_path testdata/configs/musttag.yml | ||
package testdata | ||
|
||
import ( | ||
"encoding/asn1" | ||
"encoding/json" | ||
) | ||
|
||
// builtin functions: | ||
func musttagJSONCustom() { | ||
var user struct { // want `exported fields should be annotated with the "json" tag` | ||
Name string | ||
Email string `json:"email"` | ||
} | ||
json.Marshal(user) | ||
json.Unmarshal(nil, &user) | ||
} | ||
|
||
// custom functions from config: | ||
func musttagASN1Custom() { | ||
var user struct { // want `exported fields should be annotated with the "asn1" tag` | ||
Name string | ||
Email string `asn1:"email"` | ||
} | ||
asn1.Marshal(user) | ||
asn1.Unmarshal(nil, &user) | ||
} |