SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

duplicate_enum_cases and conditional compilation

Open nevil opened this issue 6 years ago • 6 comments

New Issue Checklist

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
}

nevil avatar Jun 10 '19 06:06 nevil

@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 avatar Aug 15 '19 12:08 a-25

@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.

marcelofabri avatar Aug 15 '19 15:08 marcelofabri

This is still happening just FYI.

kylebrowning avatar Jun 23 '20 14:06 kylebrowning

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!

stale[bot] avatar Nov 08 '20 02:11 stale[bot]

This issue still exists in 0.41.0.

mwilson-within avatar Nov 18 '20 17:11 mwilson-within

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

ppamorim avatar Apr 13 '22 11:04 ppamorim

This is still a bug in 0.47.1.

jonnyijapan avatar Jun 21 '23 01:06 jonnyijapan

I'll double check with the latest version though. Cause seems there is one. 😀

jonnyijapan avatar Jun 21 '23 01:06 jonnyijapan

OK, this issue is fixed at least in 0.52.2 and probably since a few versions earlier

jonnyijapan avatar Jun 21 '23 01:06 jonnyijapan