Swiftlint: identifier_name behavior question

Created on 27 Feb 2018  路  4Comments  路  Source: realm/SwiftLint

Hello!

Our team ran into an interesting scenario. We've been linting with what we think are identifier_name violations for a long time. We have many local variables with names under the min length. We first noticed this issue when another team member recently updated from Sierra to High Sierra. All of a sudden he started getting lint errors in scenarios like this. (see myFunc below)

After some head scratching we had him checkout the project from scratch and the errors went away! Which kinda makes sense since we all lint and no one else was having errors. Ultimately we tried to figure out what the difference between his two projects were on his machine. The one that had the errors vs the one that didn't. We did byte comparison file by file, double checked the swiftlint config and version of swiftlint. Couldn't figure it out. Eventually we just copied the source files from the "good" checkout to the "bad" checkout and magically linting passed! We did a git status and no changes. Naturally since the project was clean on both. Not sure why it was failing at first, but something about magically copying the files over again, even though git status didn't detect any differences was the solution. It is very odd and the only thing he recently did was update to HS. And the only swiftlint error was identifier_name. Which looking at our config made sense for us to fail on.

So...The big question. Are local variables supposed to be checked for this violation? It would seem not, as our project passes and we have ~20 places where this does occur. We ended up creating a new project with a single VC with only this violation (see code below) and confirmed it appears only class level properties seem to be checked. Hopefully someone can confirm this!

Thanks

struct Person {
// This triggers a violation (which is correct)
    let n: String

    func myFunc() {
// This does not trigger a violation unless you magically update to High Sierra from Sierra (which is ???)
        let a = "Hello"
        print(a)
    }
}
question

Most helpful comment

wow. this is crazy.

Thanks

All 4 comments

You're probably using Xcode 9.3 beta (Swift 4.1) on High Sierra. Check #136 for more context.

Basically SourceKit didn't return local variables in the structure until Swift 4.1.

wow. this is crazy.

Thanks

I'm closing this, feel free to reopen/open another issue if you have more questions!

@marcelofabri can we have in this 'identifier_name' rule the same fix than the one made for the 'explicit_type_interface' rule in https://github.com/realm/SwiftLint/issues/2028 ?

Was this page helpful?
0 / 5 - 0 ratings