ldez / tagliatelle

A linter that handles struct tags.
Apache License 2.0
47 stars 9 forks source link

Plural IDs error #16

Closed dro-sh closed 1 year ago

dro-sh commented 1 year ago

I have a struct with array of IDs. Structure:

type WithArrays struct {
  ModelIDs []string   `json:"modelsIds"`
  MembersIDs []string `json:"membersIds"`
}

Config:

linters-settings:
  tagliatelle:
    case:
      use-field-name: true
      rules:
        json: camel

But linter thinks that it is a part of field name. I should disable linter for whole structure.

Screenshot 2023-02-23 at 10 14 27 AM

Is there a way to fix it?

ldez commented 1 year ago

Hello,

you can set use-field-name to false or just exclude the fields:

type WithArrays struct {
    ModelIDs   []string `json:"modelsIds"`  //nolint:tagliatelle
    MembersIDs []string `json:"membersIds"` //nolint:tagliatelle
}
dro-sh commented 1 year ago

Can it be fixed at future? Or it is a false positive and cannot be detected?

ldez commented 1 year ago

The problem here is that ID is an acronym like HTTP, CIA, etc.

type WithAcronyms struct {
    FooIDs      string `json:"fooIds"`
    BarHTTPs    string `json:"barHTTPs"`
    BarEXAMPLEs string `json:"barEXAMPLEs"`
}
$ golangci-lint run
foo.go:4:21: json(camel): got 'fooIds' want 'fooIDs' (tagliatelle)
        FooIDs      string `json:"fooIds"`
                           ^
foo.go:5:21: json(camel): got 'barHTTPs' want 'barHttPs' (tagliatelle)
        BarHTTPs    string `json:"barHTTPs"`
                           ^
foo.go:6:21: json(camel): got 'barEXAMPLEs' want 'barExamplEs' (tagliatelle)
        BarEXAMPLEs string `json:"barEXAMPLEs"`
                           ^

Being smart with acronyms is complex and the root of unwanted side effects.

dro-sh commented 1 year ago

Okey, thanks :)