realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.68k stars 2.22k forks source link

empty_enum_arguments false positive, --fix command breaks code preventing successful compile #5269

Open edorphy opened 1 year ago

edorphy commented 1 year ago

New Issue Checklist

Describe the bug

The empty_enum_arguments has false positives when using HealthKit types. HealthKit still has a number of types using static functions instead of static vars. The --fix command will remove the required parenthesis and make the code not compile.

Screenshot 2023-10-09 at 7 46 11 AM

https://developer.apple.com/documentation/healthkit/hkunit

Since there are system APIs in the health space and probably other built-in sdks outside of the developers control, this rule should allow a customization to provide an allow list or ignore list.

Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint

Environment

0.53.0 pkg install

# insert yaml contents here

empty_enum_arguments is on by default

    static func swiftLintFalsePositive(for unit: HKUnit) {
        switch unit {
        case .foot(), .inch():
            print("foot or inch")

        case .meter(), .meterUnit(with: .kilo):
            print("metric units")

        default:
            print("Something else")
        }
    }
SimplyDanny commented 1 year ago

The Swift compiler now complains about empty parentheses on enum cases if the they don't have associated values. Therefore, empty_enum_arguments should just ignore them and only remove argument lists containing only placeholders. Doing so also fixes this ticket.