SwiftLint
SwiftLint copied to clipboard
duplicate_enum_cases and conditional compilation
New Issue Checklist
- [x] Updated SwiftLint to the latest version
- [x] I searched for existing GitHub issues
Describe the bug
The newly added duplicate_enum_cases does not consider conditional compilation flags.
It reports duplicates even though there are none in the configuration actually compiled.
Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint duplicate_enum_cases_if_else.swift
Loading configuration from '.swiftlint.yml'
Linting Swift files at paths duplicate_enum_cases_if_else.swift
Linting 'duplicate_enum_cases_if_else.swift' (1/1)
duplicate_enum_cases_if_else.swift:3:6: error: Duplicate Enum Cases Violation: Enum can't contain multiple cases with the same name. (duplicate_enum_cases)
duplicate_enum_cases_if_else.swift:5:6: error: Duplicate Enum Cases Violation: Enum can't contain multiple cases with the same name. (duplicate_enum_cases)
duplicate_enum_cases_if_else.swift:7:6: error: Duplicate Enum Cases Violation: Enum can't contain multiple cases with the same name. (duplicate_enum_cases)
Done linting! Found 3 violations, 3 serious in 1 file.
Environment
0.33.0 Cocoapods
enum Tag: String {
#if CONFIG_A
case value = "CONFIG_A"
#elseif CONFIG_B
case value = "CONFIG_B"
#else
case value = "CONFIG_DEFAULT"
#endif
}
@marcelofabri: I debugged this and found out that SourceKit gives all enum elements regardless of conditional compilation. Seems that your fix https://bugs.swift.org/browse/SR-9630 is going to fix this bug also. So I suggest to close this issue until Swift 5.1 (like this one https://github.com/realm/SwiftLint/issues/2542). The only thing to do with this bug is to add this example to DuplicateEnumCasesRule.nonTriggeringExamples to test it in future.
@a-25 I don't think that SR-9630 is related to this: that ticket is about having a better way to determine which is the current Swift version.
This is still happening just FYI.
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!
This issue still exists in 0.41.0.
Still happening on 0.46.1 and 0.47.0_1.
The teporary solution is to wrap your code with:
// swiftlint: disable duplicate_enum_cases
...
// swiftlint: enable duplicate_enum_cases
This is still a bug in 0.47.1.
I'll double check with the latest version though. Cause seems there is one. 😀
OK, this issue is fixed at least in 0.52.2 and probably since a few versions earlier