The Wayback Machine - http://web.archive.org/web/20220726121202/https://github.com/realm/SwiftLint/issues/4012
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicated Key in Dictionary Literal Violation does not understand #line directive. #4012

Open

ke-kx opened this issue Jun 30, 2022 · 3 comments

Comments

@ke-kx
Copy link

@ke-kx ke-kx commented Jun 30, 2022

New Issue Checklist

Describe the bug

Duplicated Key in Dictionary Literal Violation does not understand #line directive.

Complete output when running SwiftLint, including the stack trace and command used
➜ swiftlint lint test.swift
Linting Swift files at paths test.swift
Linting 'test.swift' (1/1)
/Users/nils_kunze/work/misc/test.swift:1:14: warning: Colon Spacing Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. (colon)
/Users/nils_kunze/work/misc/test.swift:3:5: warning: Duplicated Key in Dictionary Literal Violation: Dictionary literals with duplicated keys will crash in runtime. (duplicated_key_in_dictionary_literal)
/Users/nils_kunze/work/misc/test.swift:4:5: warning: Duplicated Key in Dictionary Literal Violation: Dictionary literals with duplicated keys will crash in runtime. (duplicated_key_in_dictionary_literal)
/Users/nils_kunze/work/misc/test.swift:5:5: warning: Duplicated Key in Dictionary Literal Violation: Dictionary literals with duplicated keys will crash in runtime. (duplicated_key_in_dictionary_literal)
Done linting! Found 4 violations, 0 serious in 1 file.

Environment

  • SwiftLint version (run swiftlint version to be sure)? 0.47.1

  • Installation method used (Homebrew, CocoaPods, building from source, etc)? brew

  • Paste your configuration file: None / defrault

  • Are you using nested configurations? no

  • Which Xcode version are you using (check xcodebuild -version)? -

  • Do you have a sample that shows the issue? Run echo "[string here]" | swiftlint lint --no-cache --use-stdin --enable-all-rules
    to quickly test if your example is really demonstrating the issue. If your example is more
    complex, you can use swiftlint lint --path [file here] --no-cache --enable-all-rules.

var values: [Int : String] = [
    #line: "one",
    #line: "two",
    #line: "three",
    #line: "four"
]
@SimplyDanny
Copy link
Collaborator

@SimplyDanny SimplyDanny commented Jul 3, 2022

Interesting catch, @ke-kx! I wonder where/why you would use such code, however?

@ke-kx
Copy link
Author

@ke-kx ke-kx commented Jul 6, 2022

Good question^^ I found this in unit tests of a customer code base. I guess they don't care about the actual keys and just want to make sure that they are unique or something like that?

@SimplyDanny
Copy link
Collaborator

@SimplyDanny SimplyDanny commented Jul 6, 2022

So reformatting the dictionary, putting all key-value pairs onto a single line, leads to an exception in the worst case, because keys are no longer unique. Doesn't seem like a good idea to me.

Well, never mind ... The bug is valid and should be quite easy to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants