Skip to content
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

Add tagliatelle linter to check struct tags #276

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion go/lint-project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,13 @@ linters-settings:
forbidigo:
forbid:
- '^panic$'
tagliatelle:
case:
rules:
json: goCamel
EOF

enabled="-E=asciicheck,bidichk,bodyclose,durationcheck,exhaustive,exportloopref,forbidigo,forcetypeassert,gosec,misspell,nolintlint,rowserrcheck,sqlclosecheck,unused,wastedassign"
enabled="-E=asciicheck,bidichk,bodyclose,durationcheck,exhaustive,exportloopref,forbidigo,forcetypeassert,gosec,misspell,nolintlint,rowserrcheck,sqlclosecheck,tagliatelle,unused,wastedassign"
if [ -n "$GOLANGCI_LINTERS" ];
then
enabled="$enabled"",$GOLANGCI_LINTERS"
Expand Down
28 changes: 28 additions & 0 deletions tests/go/tagliatelle_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package go_test

import (
"testing"
)

func TestTagliatelleLinter(t *testing.T) {
// These should pass the linter
type foo struct {
Field1 string `json:"field1"`
Field2 string `json:"fieldOne"`
Field3 string `json:"fieldONE"`

Check failure on line 12 in tests/go/tagliatelle_test.go

View workflow job for this annotation

GitHub Actions / Go Build (ubuntu-latest)

json(goCamel): got 'fieldONE' want 'fieldOne' (tagliatelle)
}

// These should not pass without comments to disable
type bar struct {
Field1 string `json:"Field1"` //nolint:tagliatelle
Field2 string `json:"field_1"` //nolint:tagliatelle
Field3 string `json:"FieldOne"` //nolint:tagliatelle
Field4 string `json:"FIELD1"` //nolint:tagliatelle
}

f := &foo{}
b := &bar{}

f.Field1 = "foo"
b.Field1 = "bar"
}
Loading