Swiftlint: False positive in colon rule

Created on 2 Feb 2017  路  7Comments  路  Source: realm/SwiftLint

I'm setting a value to one of two localized strings with a ternary operator like so:

let statesTitle = compactEnabled ? Localized.Titles.additionalStates : Localized.Titles.stateLicenses

And receiving the SwiftLint colon violation warning:

Colon violation: colons should be next to the identifier when specifying a type and next to the key in dictionary literals.

Of course, neither of those situations apply to my above code.

bug wontfix

Most helpful comment

@vfn Thanks for the sample example. I could reproduce it with 0.21.0 as well.

Here's a reduced version of the snippet that still triggers the warning:

func baz(lhs: Int, rhs: Int) -> Bool {
    typealias Type = FooBar
    return lhs > rhs ? foo : Type.bar
}

All 7 comments

I couldn't reproduce it with this snippet

$ echo "let statesTitle = compactEnabled ? Localized.Titles.additionalStates : Localized.Titles.stateLicenses" | swiftlint lint --use-stdin  --no-cache --enable-all-rules

Done linting! Found 0 violations, 0 serious in 1 file.

@nevillco hi, I'm just following up on this, how can we reproduce this?

Closing due lack of activity.

@marcelofabri I'm experiencing this same issue on the current latest version.

$ swiftlint version
0.21.0

The following code triggers the colon rule:

struct FooBar {

    static let foo = true
    static let bar = false

    func baz(lhs: Int, rhs: Int) -> Bool {
        typealias Type = FooBar
        return lhs > rhs ? Type.foo : Type.bar
    }
}

Error:
screen shot 2017-08-23 at 4 10 53 pm

@vfn Thanks for the sample example. I could reproduce it with 0.21.0 as well.

Here's a reduced version of the snippet that still triggers the warning:

func baz(lhs: Int, rhs: Int) -> Bool {
    typealias Type = FooBar
    return lhs > rhs ? foo : Type.bar
}

I just took a look at the bug and found something weird.
SourceKitten parses Type.foo : Type.bar respectively in a following manner

  • Type
    syntaxtype.identifier <- 鉂搒hould be typeidentifier
    syntaxtype.typeidentifier
  • Token string
    foo <- 鉂搒hould be Type.foo
    Type.bar

But even if SourceKitten is able to correctly parse the two tokens as typeidentifiers, the switch case in ColonRule+Type.swift considers (.typeidentifier, .typeidentifier) as not valid kinds.

Any ideas??

This issue has been automatically marked as stale because it has not had any recent activity. Please comment to prevent this issue from being closed. Thank you for your contributions!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jcarroll-mediafly picture jcarroll-mediafly  路  3Comments

bourquep picture bourquep  路  3Comments

BalestraPatrick picture BalestraPatrick  路  3Comments

mrtj picture mrtj  路  3Comments

ivanbruel picture ivanbruel  路  3Comments