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

build(deps): bump github.com/ldez/tagliatelle from 0.5.0 to 0.6.0 #5164

Merged
Show file tree
Hide file tree
Changes from 2 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
50 changes: 45 additions & 5 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3285,14 +3285,24 @@ linters-settings:
tagliatelle:
# Check the struct tag name case.
case:
# Use the struct field name to check the name of the struct tag.
# Default: false
use-field-name: true
# `camel` is used for `json` and `yaml`, and `header` is used for `header` (can be overridden)
# Default: {}
rules:
# Any struct tag type can be used.
# Support string case: `camel`, `pascal`, `kebab`, `snake`, `upperSnake`, `goCamel`, `goPascal`, `goKebab`, `goSnake`, `upper`, `lower`, `header`
# Define the association between tag name and case.
# Any struct tag name can be used.
# Support string cases:
ldez marked this conversation as resolved.
Show resolved Hide resolved
# - `camel`
# - `pascal`
# - `kebab`
# - `snake`
# - `upperSnake`
# - `goCamel`
# - `goPascal`
# - `goKebab`
# - `goSnake`
# - `upper`
# - `lower`
# - `header`
json: camel
yaml: camel
xml: camel
Expand All @@ -3302,6 +3312,36 @@ linters-settings:
mapstructure: kebab
env: upperSnake
envconfig: upperSnake
whatever: snake
# Use the struct field name to check the name of the struct tag.
# Default: false
use-field-name: true
# The field names to ignore.
# Default: []
ignored-fields:
- Bar
- Foo
# Overrides the default/root configuration.
# Default: []
overrides:
-
# The package path. (uses `/` only as separator)
ldez marked this conversation as resolved.
Show resolved Hide resolved
# Required.
pkg: foo/bar
# Default: empty or the same as the default/root configuration.
rules:
json: snake
xml: pascal
# Default: false (WARNING: it doesn't follow the default/root configuration)
use-field-name: true
# The field names to ignore.
# Default: [] or the same as the default/root configuration.
ignored-fields:
- Bar
- Foo
# Ignore the package (take the precedence over all other configuration).
ldez marked this conversation as resolved.
Show resolved Hide resolved
# Default: false
ignore: true

tenv:
# The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures.
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ require (
github.com/kyoh86/exportloopref v0.1.11
github.com/lasiar/canonicalheader v1.1.2
github.com/ldez/gomoddirectives v0.2.4
github.com/ldez/tagliatelle v0.5.0
github.com/ldez/tagliatelle v0.6.0
github.com/leonklingele/grouper v1.1.2
github.com/macabu/inamedparam v0.1.3
github.com/maratori/testableexamples v1.0.0
Expand Down Expand Up @@ -158,6 +158,8 @@ require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/gostaticanalysis/analysisutil v0.7.1 // indirect
github.com/gostaticanalysis/comment v1.4.2 // indirect
github.com/hashicorp/go-immutable-radix/v2 v2.1.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
Expand Down
10 changes: 8 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 66 additions & 14 deletions jsonschema/golangci.next.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,22 @@
"opaque"
]
},
"tagliatelle-cases": {
"enum": [
"camel",
"pascal",
"kebab",
"snake",
"goCamel",
"goPascal",
"goKebab",
"goSnake",
"upper",
"upperSnake",
"lower",
"header"
]
},
"linters": {
"$comment": "anyOf with enum is used to allow auto completion of non-custom linters",
"description": "Linters usable.",
Expand Down Expand Up @@ -2894,24 +2910,60 @@
"type": "boolean",
"default": false
},
"ignored-fields": {
"description": "The field names to ignore.",
"type": "array",
"items": {
"type": "string",
"examples": ["example"]
}
},
"rules": {
"type": "object",
"patternProperties": {
"^.+$": {
"enum": [
"camel",
"pascal",
"kebab",
"snake",
"goCamel",
"goPascal",
"goKebab",
"goSnake",
"upper",
"upperSnake",
"lower",
"header"
]
"$ref": "#/definitions/tagliatelle-cases"
}
}
},
"overrides": {
"description": "Overrides the default/root configuration.",
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"required": ["pkg"],
"properties": {
"pkg": {
"description": "A package path.",
"type": "string"
},
"use-field-name": {
"description": "Use the struct field name to check the name of the struct tag.",
"type": "boolean",
"default": false
},
"ignored-fields": {
"description": "The field names to ignore.",
"type": "array",
"items": {
"type": "string",
"examples": ["example"]
}
},
"ignore": {
"description": "Ignore the package (it takes the precedence over all other configuration).",
"type": "boolean",
"default": false
},
"rules": {
"type": "object",
"patternProperties": {
"^.+$": {
"$ref": "#/definitions/tagliatelle-cases"
}
}
}
}
}
}
Expand Down
22 changes: 18 additions & 4 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,10 +870,24 @@ type TagAlignSettings struct {
}

type TagliatelleSettings struct {
Case struct {
Rules map[string]string
UseFieldName bool `mapstructure:"use-field-name"`
}
Case TagliatelleCase
}

type TagliatelleCase struct {
TagliatelleBase `mapstructure:",squash"`
Overrides []TagliatelleOverrides
}

type TagliatelleOverrides struct {
TagliatelleBase `mapstructure:",squash"`
Package string `mapstructure:"pkg"`
Ignore bool `mapstructure:"ignore"`
}

type TagliatelleBase struct {
Rules map[string]string `mapstructure:"rules"`
UseFieldName bool `mapstructure:"use-field-name"`
IgnoredFields []string `mapstructure:"ignored-fields"`
}

type TestifylintSettings struct {
Expand Down
26 changes: 21 additions & 5 deletions pkg/golinters/tagliatelle/tagliatelle.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,34 @@ import (

func New(settings *config.TagliatelleSettings) *goanalysis.Linter {
cfg := tagliatelle.Config{
Rules: map[string]string{
"json": "camel",
"yaml": "camel",
"header": "header",
Base: tagliatelle.Base{
Rules: map[string]string{
"json": "camel",
"yaml": "camel",
"header": "header",
},
},
}

if settings != nil {
for k, v := range settings.Case.Rules {
cfg.Rules[k] = v
}

cfg.UseFieldName = settings.Case.UseFieldName
cfg.IgnoredFields = settings.Case.IgnoredFields

for _, override := range settings.Case.Overrides {
cfg.Overrides = append(cfg.Overrides, tagliatelle.Overrides{
Base: tagliatelle.Base{
Rules: override.Rules,
UseFieldName: override.UseFieldName,
IgnoredFields: override.IgnoredFields,
Ignore: override.Ignore,
},
Package: override.Package,
})
}
}

a := tagliatelle.New(cfg)
Expand All @@ -31,5 +47,5 @@ func New(settings *config.TagliatelleSettings) *goanalysis.Linter {
a.Doc,
[]*analysis.Analyzer{a},
nil,
).WithLoadMode(goanalysis.LoadModeSyntax)
).WithLoadMode(goanalysis.LoadModeTypesInfo)
}
34 changes: 34 additions & 0 deletions pkg/golinters/tagliatelle/testdata/tagliatelle_ignored_fields.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//golangcitest:args -Etagliatelle
//golangcitest:config_path testdata/tagliatelle_ignored_fields.yml
package testdata

import "time"

type TglFoo struct {
ID string `json:"ID"` // want `json\(camel\): got 'ID' want 'id'`
UserID string `json:"UserID"` // want `json\(camel\): got 'UserID' want 'userId'`
Name string `json:"name"`
Value time.Duration `json:"value,omitempty"`
Bar TglBar `json:"bar"`
Bur `json:"bur"`
}

type TglBar struct {
Name string `json:"-"`
Value string `json:"value"`
CommonServiceFooItem *TglBir `json:"CommonServiceItem,omitempty"`
}

type TglBir struct {
Name string `json:"-"`
Value string `json:"value"`
ReplaceAllowList []string `mapstructure:"replace-allow-list"`
}

type Bur struct {
Name string
Value string `yaml:"Value"` // want `yaml\(camel\): got 'Value' want 'value'`
More string `json:"-"`
Also string `json:"also,omitempty"`
ReqPerS string `avro:"req_per_s"`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
linters-settings:
tagliatelle:
case:
ignored-fields:
- CommonServiceFooItem


1 change: 1 addition & 0 deletions pkg/lint/lintersdb/builder_linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
linter.NewConfig(tagliatelle.New(&cfg.LintersSettings.Tagliatelle)).
WithSince("v1.40.0").
WithPresets(linter.PresetStyle).
WithLoadForGoAnalysis().
WithURL("https://github.com/ldez/tagliatelle"),

linter.NewConfig(tenv.New(&cfg.LintersSettings.Tenv)).
Expand Down
Loading