1

I'm trying to configure swiftlint in my project and white_list is not working.

Here is what I'm trying to do:

my .swiftlint.yml:

whitelist_rules:
  - force_cast: warning

my code:

let forceCast: Int = "hue" as! Int

which gives me the error:

Force Cast Violation: Force casts should be avoided. (force_cast)

when I expect it to give me only a warning, not an error. Beyond this example, no other rule is working when on whitelist.

I know swiftlint is reading my .swiftlint.yml because I tested it with disabled_rules and it seemed to be working fine, so it's not a matter with the path of my .swiftlint.yml file.

Also, for the record,

  • I have configured correctly the Run Script Phase
  • I am not using whitelist_rules along with disabled_rules and opt_in_rules, I'm using only whitelist_rules.
  • I'm using swiftlint version 0.40.3, xcode 11.3, ios 13.2 and swift 5

What am I missing? Why isn't it working?

Mik
  • 31
  • 3
  • 1
    I don't think you can configure a rule on the same line where it's being added to the whitelist. Try removing the `: warning` here, and then on another line (outside of the whitelist rules) say `force_cast: warning` to configure the rule, and see if that works. – TylerP Sep 29 '20 at 20:32

1 Answers1

1

In case anyone had recent issues with whilelist_rules configuration key, notice that it was renamed to only_rules in version 0.41.0

https://github.com/realm/SwiftLint/releases/tag/0.41.0

caperonce
  • 61
  • 6