0

I got this swiftlint error from sonarCube:

Rename this constant to match the regular expression ^[a-z][a-zA-Z0-9]*$.".

How can I disable the swiftlint warning from sonarCube?

// Rename this constant to match the regular expression ^[a-z][a-zA-Z0-9]*$.

let zht: [item]
let en: [item]
let zhs: [item]
Alexander
  • 59,041
  • 12
  • 98
  • 151
wong john
  • 55
  • 4
  • 1
    That trailing dot (meaning “any character”) after the dollar sign (meaning “end of line”) looks like a mistake. How could there be character after the end of the line, for a regex that’s presumably not evaluated in multi-line mode? – Alexander May 05 '22 at 02:18
  • In any case, these variable and type names are just bad. You should fix them. – Alexander May 05 '22 at 02:18
  • Can you share your .swiftlint.yml config file? – bsarrazin May 05 '22 at 03:34
  • but my api comes with this response. i only want to disable this regular expression here only without globally disabled. Any disable swiftlint can be used – wong john May 05 '22 at 05:30
  • You can disable that rule locally in that swift file using `// swiftlint:disable ` – Joakim Danielson May 05 '22 at 06:23
  • @JoakimDanielson I don't think the author uses SwiftLint, they mentioned SonarCube. – lazarevzubov May 05 '22 at 06:34
  • @lazarevzubov ok, I am not familiar with that product and OP mention and has tagged with swiftlint so I leave my comment for now. – Joakim Danielson May 05 '22 at 06:39
  • 1
    If we assume the dot at the end isn’t part of the regex but a period that ends the sentence then none of the variable names violates the regex so that is also strange. It looks like OP has a lot to clarify here. – Joakim Danielson May 05 '22 at 07:54

1 Answers1

-1

It doesn't seem possible in Swift at the moment, but you don't have to name your variables to match response fields. Do you use Codable? If so, it's easy to have any name you wish:

struct YourModel: Decodable {
  enum CodingKeys: String, CodingKey {
    case wantedName = "unwantedNameFromResponse"
  }
  let wantedName: String
}
lazarevzubov
  • 1,767
  • 2
  • 14
  • 24
  • do i need to rename it? – wong john May 05 '22 at 08:57
  • The variable? Yes, that was the point. If it's not possible to bypass the linter rule, I suggested renaming the variable with an "invalid" name. You said that the variable name comes from API and I tried to explain that it's not an obstacle. – lazarevzubov May 05 '22 at 09:31