A linter that handles struct tags.

Tagliatelle

Sponsor Build Status

A linter that handles struct tags.

Supported string casing:

Source Camel Case Go Camel Case
GooID gooId gooID
HTTPStatusCode httpStatusCode httpStatusCode
FooBAR fooBar fooBar
URL url url
ID id id
hostIP hostIp hostIP
JSON json json
JSONName jsonName jsonName
NameJSON nameJson nameJSON
UneTête uneTête uneTête
Source Pascal Case Go Pascal Case
GooID GooId GooID
HTTPStatusCode HttpStatusCode HTTPStatusCode
FooBAR FooBar FooBar
URL Url URL
ID Id ID
hostIP HostIp HostIP
JSON Json JSON
JSONName JsonName JSONName
NameJSON NameJson NameJSON
UneTête UneTête UneTête
Source Snake Case Go Snake Case
GooID goo_id goo_ID
HTTPStatusCode http_status_code HTTP_status_code
FooBAR foo_bar foo_bar
URL url URL
ID id ID
hostIP host_ip host_IP
JSON json JSON
JSONName json_name JSON_name
NameJSON name_json name_JSON
UneTête une_tête une_tête
Source Kebab Case Go KebabCase
GooID goo-id goo-ID
HTTPStatusCode http-status-code HTTP-status-code
FooBAR foo-bar foo-bar
URL url URL
ID id ID
hostIP host-ip host-IP
JSON json JSON
JSONName json-name JSON-name
NameJSON name-json name-JSON
UneTête une-tête une-tête

Examples

// json and camel case
type Foo struct {
    ID     string `json:"ID"` // must be "id"
    UserID string `json:"UserID"`// must be "userId"
    Name   string `json:"name"`
    Value  string `json:"val,omitempty"`// must be "value"
}
Owner
Ludovic Fernandez
Maintainer of Traefik, lego, prm, and a lot things
Ludovic Fernandez
Comments
  • tagliatelle now warns on inline struct fields

    tagliatelle now warns on inline struct fields

    Since 7b219253661560e60d284e3cddfb912dc49862fc, structs with json:",inline" fields now prompt a warning from tagliatelle that a name should be given in the expected camelCase.

    I think this is incorrect behavior as there is no field name for an inline struct.

  • tagliatelle: issue with invalid struct

    tagliatelle: issue with invalid struct

    Tagliatelle is unable to detect issue with invalid tags

    // MessedUpTags is to validate structtag validation is done
    // without it, the tool could let think everything is ok, while it's not.
    type MessedUpTags struct {
    	// an invalid tag listed in the rule is supported.
    	Bad string `json:"bad` // want "struct field tag `json:\"bad` not compatible with reflect.StructTag.Get: bad syntax for struct tag value"
    
    	// an invalid tag not in the rule is supported.
    	Whatever string `foo:whatever` // want "struct field tag `foo:whatever` not compatible with reflect.StructTag.Get: bad syntax for struct tag value"
    
    	// a invalid tag supported by the rule, is not hidden by another broken tag
    	Mixed string `json:"mixed" foo:mixed` // want "struct field tag `json:\"mixed\" foo:mixed` not compatible with reflect.StructTag.Get: bad syntax for struct tag value"
    }
    
  • Ignore struct fields with `inline` tag flag

    Ignore struct fields with `inline` tag flag

    Fixes #8.

    Updated the test file to include a json:",inline" field. Without the fix, that file fails with:

    === RUN   TestAnalyzer
        analysistest.go:446: a/sample.go:10:14: unexpected diagnostic: json(camel): got 'Quux' want 'quux'
    
  • consider default name when validating

    consider default name when validating

    Hey! Thanks for this, amazing project!

    I have a small issue which I think other people will have as well, for instance, consider this struct:

    type Foo struct {
      Foo string `yaml:",omitempty"`
      Bar string `yaml:"notBar"`
    }
    

    If I validate it using snake case, both fields should fail, as the first will be, by default Foo and the second one is in camel case.

    Would be nice if either the default name is considered or if we could disallow not naming the field.

    Cheers!

  • validate and report the struct tag is invalid

    validate and report the struct tag is invalid

    using structtag.Analyzer is the one in charge of doing that.

    This is a fix for #11

    It's a draft version, as I'm awaiting a reply to my bug report on golang.org/x/tools

    https://github.com/golang/go/issues/52973

  • Exclude Certain Types

    Exclude Certain Types

    We need a way to exclude certain types so we don't have to continuously disable this linter on that line. I would love regex support or something similar. For example, working with mongo, the default ID field is _id.

  • Detect non-functional `omitempty`

    Detect non-functional `omitempty`

    omitempty has no effect on fields whose type is a struct. Neither the language nor go vet bother to warn about useless omitempty, leading to surprises. Perhaps tagliatelle should support this check?

  • Different struct casing for subpackages

    Different struct casing for subpackages

    I have a project that integrates with different APIs. Different vendors have different casing e.g. one uses camel case another snake case. Right now I need to disable this linter because of this. Would be nice if I could define it per subpackage/subfolder.

  • Add support for custom initialisms

    Add support for custom initialisms

    In my codebase, I use initialisms that are domain-specific and not included in Go's common initialisms.

    The underlying strcase package supports customization, so I think it should be fairly simple to implement in tagliatelle: https://github.com/ettle/strcase#customization

    If implemented, it would be great to also raise a PR to support the new configuration in golangci-lint.


    Example of the problem:

    json(goCamel): got 'docURLs' want 'docUrLs'
    
  • Auto fix tags.

    Auto fix tags.

    Hey there can you provide auto fixing via a cli flag or golangci-lint's built in fix API? So that I can solve all the issues just by a single command.

The most opinionated Go source code linter for code audit.
The most opinionated Go source code linter for code audit.

go-critic Highly extensible Go source code linter providing checks currently missing from other linters. There is never too much static code analysis.

Jan 6, 2023
[mirror] This is a linter for Go source code.

Golint is a linter for Go source code. Installation Golint requires a supported release of Go. go get -u golang.org/x/lint/golint To find out where g

Dec 23, 2022
Staticcheck - The advanced Go linter

The advanced Go linter Staticcheck is a state of the art linter for the Go programming language. Using static analysis, it finds bugs and performance

Jan 1, 2023
A Go linter to check that errors from external packages are wrapped

Wrapcheck A simple Go linter to check that errors from external packages are wrapped during return to help identify the error source during debugging.

Dec 27, 2022
a simple golang SSA viewer tool use for code analysis or make a linter
a simple golang SSA viewer tool use for code analysis or make a linter

ssaviewer A simple golang SSA viewer tool use for code analysis or make a linter ssa.html generate code modify from src/cmd/compile/internal/ssa/html.

May 17, 2022
The Golang linter that checks that there is no simultaneous return of `nil` error and an invalid value.

nilnil Checks that there is no simultaneous return of nil error and an invalid value. Installation & usage $ go install github.com/Antonboom/nilnil@la

Dec 14, 2022
Go linter which checks for dangerous unicode character sequences

bidichk - checks for dangerous unicode character sequences bidichk finds dangerous unicode character sequences in Go source files. Considered dangerou

Oct 5, 2022
Go linter that checks types that are json encoded - reports unsupported types and unnecessary error checks

Checks types passed to the json encoding functions. Reports unsupported types and reports occations, where the check for the returned error can be omited.

Oct 7, 2022
Linter for PostgreSQL

Использование Проверить миграции: oh-my-pg-linter check ./migrations/*.sql Добавить директории с дополнительными проверками (переопределение - кто пос

Nov 25, 2021
World's spookiest linter

nosleep The world's spookiest linter nosleep is a golang-ci compatible linter which checks for and fails if it detects usages of time.Sleep. Why did y

Oct 15, 2022
Go linter to analyze expression groups: require 'import' declaration groups

grouper — a Go linter to analyze expression groups Installation

Jun 19, 2022
funcresult — a Go linter to analyze function result parameters

Go linter to analyze function result parameters: require named / unnamed function result parameters

Jan 27, 2022
nostdglobals is a simple Go linter that checks for usages of global variables defined in the go standard library

nostdglobals is a simple Go linter that checks for usages of global variables defined in the go standard library

Feb 17, 2022
Goalinter-v1: Goa framework (version1) linter

goavl: Goa framework (ver1) linter goavlは、goa version1(フォーク版)のlinterです。開発目的は、goa

Jul 28, 2022
Linter for Go's fmt.Errorf message

wrapmsg wrapmsg is Go code linter. this enforces fmt.Errorf's message when you wrap error. Example // OK ???? if err := pkg.Cause(); err != nil { re

Dec 27, 2022
misspelled word linter for Go comments, string literals and embedded files

gospel The gospel program lints Go source files for misspellings in comments, strings and embedded files. It uses hunspell to identify misspellings an

Aug 6, 2022
structslop is a static analyzer for Go that recommends struct field rearrangements to provide for maximum space/allocation efficiency.

structslop Package structslop defines an Analyzer that checks struct can be re-arranged fields to get optimal struct size.

Dec 28, 2022
Marshal data into commands struct!
Marshal data into commands struct!

Commandarrgh in a nuthsell Commandarrgh is an interface that helps you marshaling data into a command arguments structure. Maybe you have been trying

Dec 18, 2021
Pagser is a simple, extensible, configurable parse and deserialize html page to struct based on goquery and struct tags for golang crawler
Pagser is a simple, extensible, configurable parse and deserialize html page to struct based on goquery and struct tags for golang crawler

Pagser Pagser inspired by page parser。 Pagser is a simple, extensible, configurable parse and deserialize html page to struct based on goquery and str

Dec 13, 2022
Match regex group into go struct using struct tags and automatic parsing

regroup Simple library to match regex expression named groups into go struct using struct tags and automatic parsing Installing go get github.com/oris

Nov 5, 2022