diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 563ed63cf38d..219501298cbe 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -3302,26 +3302,24 @@ linters-settings: strict: true tagliatelle: - # Check the struct tag name case. + # Checks the struct tag name case. case: - # `camel` is used for `json` and `yaml`, and `header` is used for `header` (can be overridden) - # Default: {} + # Defines the association between tag name and case. + # Any struct tag name can be used. + # Supported string cases: + # - `camel` + # - `pascal` + # - `kebab` + # - `snake` + # - `upperSnake` + # - `goCamel` + # - `goPascal` + # - `goKebab` + # - `goSnake` + # - `upper` + # - `lower` + # - `header` rules: - # Define the association between tag name and case. - # Any struct tag name can be used. - # Supported string cases: - # - `camel` - # - `pascal` - # - `kebab` - # - `snake` - # - `upperSnake` - # - `goCamel` - # - `goPascal` - # - `goKebab` - # - `goSnake` - # - `upper` - # - `lower` - # - `header` json: camel yaml: camel xml: camel @@ -3332,7 +3330,38 @@ linters-settings: env: upperSnake envconfig: upperSnake whatever: snake - # Use the struct field name to check the name of the struct tag. + # Defines the association between tag name and case. + # Important: the `extended-rules` overrides `rules`. + # Default: empty + extended-rules: + json: + # Supported string cases: + # - `camel` + # - `pascal` + # - `kebab` + # - `snake` + # - `upperSnake` + # - `goCamel` + # - `goPascal` + # - `goKebab` + # - `goSnake` + # - `header` + # - `lower` + # - `header` + # + # Required + case: camel + # Adds 'AMQP', 'DB', 'GID', 'RTP', 'SIP', 'TS' to initialisms, + # and removes 'LHS', 'RHS' from initialisms. + # Default: false + extra-initialisms: true + # Defines initialism additions and overrides. + # Default: empty + initialism-overrides: + DB: true # add a new initialism + LHS: false # disable a default initialism. + # ... + # Uses the struct field name to check the name of the struct tag. # Default: false use-field-name: true # The field names to ignore. @@ -3345,12 +3374,15 @@ linters-settings: overrides: - # The package path (uses `/` only as a separator). - # Required. + # Required pkg: foo/bar # Default: empty or the same as the default/root configuration. rules: json: snake xml: pascal + # Default: empty or the same as the default/root configuration. + extended-rules: + # Same options as the base `extended-rules`. # Default: false (WARNING: it doesn't follow the default/root configuration) use-field-name: true # The field names to ignore. diff --git a/go.mod b/go.mod index 34d37833da56..12e0b28e5ebd 100644 --- a/go.mod +++ b/go.mod @@ -68,7 +68,7 @@ require ( github.com/lasiar/canonicalheader v1.1.2 github.com/ldez/gomoddirectives v0.6.0 github.com/ldez/grignotin v0.6.0 - github.com/ldez/tagliatelle v0.6.0 + github.com/ldez/tagliatelle v0.7.1 github.com/ldez/usetesting v0.2.2 github.com/leonklingele/grouper v1.1.2 github.com/macabu/inamedparam v0.1.3 diff --git a/go.sum b/go.sum index 8e73b3f7df00..bddf925521b0 100644 --- a/go.sum +++ b/go.sum @@ -355,8 +355,8 @@ github.com/ldez/gomoddirectives v0.6.0 h1:Jyf1ZdTeiIB4dd+2n4qw+g4aI9IJ6JyfOZ8Bit github.com/ldez/gomoddirectives v0.6.0/go.mod h1:TuwOGYoPAoENDWQpe8DMqEm5nIfjrxZXmxX/CExWyZ4= github.com/ldez/grignotin v0.6.0 h1:i++3002hxD5TpVto0iLjLrfz1V+yEJ+BBk4glb3aqC8= github.com/ldez/grignotin v0.6.0/go.mod h1:uaVTr0SoZ1KBii33c47O1M8Jp3OP3YDwhZCmzT9GHEk= -github.com/ldez/tagliatelle v0.6.0 h1:1Muumft/shmQ0x96vA6a/OUgTjamRt8jUlZPLm1ruwA= -github.com/ldez/tagliatelle v0.6.0/go.mod h1:WeZ7TgEqq7fw/0Zj8BuQhh4+4KX1/+g0O11eygvClRA= +github.com/ldez/tagliatelle v0.7.1 h1:bTgKjjc2sQcsgPiT902+aadvMjCeMHrY7ly2XKFORIk= +github.com/ldez/tagliatelle v0.7.1/go.mod h1:3zjxUpsNB2aEZScWiZTHrAXOl1x25t3cRmzfK1mlo2I= github.com/ldez/usetesting v0.2.2 h1:5h/nKjodUOIZNaBSmyktR6VjUY8lVgNoCRBvs2Fdg+g= github.com/ldez/usetesting v0.2.2/go.mod h1:9Tk8OH9NL3Xi7lpvkGRpuY/cOmWmatxwVjRc+TkgLDg= github.com/leonklingele/grouper v1.1.2 h1:o1ARBDLOmmasUaNDesWqWCIFH3u7hoFlM84YrjT3mIY= diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index ea958f9220bb..fa60ba58cf19 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -2952,6 +2952,35 @@ } } }, + "extended-rules": { + "description": "Defines the association between tag name and case.", + "type": "object", + "patternProperties": { + "^.+$": { + "type": "object", + "additionalProperties": false, + "required": ["case"], + "properties": { + "case": { + "$ref": "#/definitions/tagliatelle-cases" + }, + "extra-initialisms": { + "type": "boolean", + "default": false + }, + "initialism-overrides": { + "type": "object", + "patternProperties": { + "^.+$": { + "type": "boolean", + "default": false + } + } + } + } + } + } + }, "overrides": { "description": "Overrides the default/root configuration.", "type": "array", @@ -2989,6 +3018,35 @@ "$ref": "#/definitions/tagliatelle-cases" } } + }, + "extended-rules": { + "description": "Defines the association between tag name and case.", + "type": "object", + "patternProperties": { + "^.+$": { + "type": "object", + "additionalProperties": false, + "required": ["case"], + "properties": { + "case": { + "$ref": "#/definitions/tagliatelle-cases" + }, + "extra-initialisms": { + "type": "boolean", + "default": false + }, + "initialism-overrides": { + "type": "object", + "patternProperties": { + "^.+$": { + "type": "boolean", + "default": false + } + } + } + } + } + } } } } diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 6738399b9147..93f119a00059 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -900,9 +900,16 @@ type TagliatelleOverrides struct { } type TagliatelleBase struct { - Rules map[string]string `mapstructure:"rules"` - UseFieldName bool `mapstructure:"use-field-name"` - IgnoredFields []string `mapstructure:"ignored-fields"` + Rules map[string]string `mapstructure:"rules"` + ExtendedRules map[string]TagliatelleExtendedRule `mapstructure:"extended-rules"` + UseFieldName bool `mapstructure:"use-field-name"` + IgnoredFields []string `mapstructure:"ignored-fields"` +} + +type TagliatelleExtendedRule struct { + Case string + ExtraInitialisms bool + InitialismOverrides map[string]bool } type TestifylintSettings struct { diff --git a/pkg/golinters/tagliatelle/tagliatelle.go b/pkg/golinters/tagliatelle/tagliatelle.go index 9e700b49f16c..08215c3a53fc 100644 --- a/pkg/golinters/tagliatelle/tagliatelle.go +++ b/pkg/golinters/tagliatelle/tagliatelle.go @@ -24,6 +24,7 @@ func New(settings *config.TagliatelleSettings) *goanalysis.Linter { cfg.Rules[k] = v } + cfg.ExtendedRules = toExtendedRules(settings.Case.ExtendedRules) cfg.UseFieldName = settings.Case.UseFieldName cfg.IgnoredFields = settings.Case.IgnoredFields @@ -31,6 +32,7 @@ func New(settings *config.TagliatelleSettings) *goanalysis.Linter { cfg.Overrides = append(cfg.Overrides, tagliatelle.Overrides{ Base: tagliatelle.Base{ Rules: override.Rules, + ExtendedRules: toExtendedRules(override.ExtendedRules), UseFieldName: override.UseFieldName, IgnoredFields: override.IgnoredFields, Ignore: override.Ignore, @@ -49,3 +51,17 @@ func New(settings *config.TagliatelleSettings) *goanalysis.Linter { nil, ).WithLoadMode(goanalysis.LoadModeTypesInfo) } + +func toExtendedRules(src map[string]config.TagliatelleExtendedRule) map[string]tagliatelle.ExtendedRule { + result := make(map[string]tagliatelle.ExtendedRule, len(src)) + + for k, v := range src { + result[k] = tagliatelle.ExtendedRule{ + Case: v.Case, + ExtraInitialisms: v.ExtraInitialisms, + InitialismOverrides: v.InitialismOverrides, + } + } + + return result +}