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

Rule Request: Avoid optional Bools #2011

ejmartin504 opened this Issue Jan 19, 2018 · 1 comment


None yet
2 participants

ejmartin504 commented Jan 19, 2018

New Issue Checklist

Rule Request

  1. Why should this rule be added? Share links to existing discussion about what
    the community thinks about this.

This is somewhat similar to #1885 -- optional Bools are similar to optional collections in that an "empty" Bool rarely conveys much information.
I haven't found any existing discussions about this, but I have seen folks trying different solutions to dealing with optional Bools, all of which, to me, are not pretty. (see for example: Rule Request: Avoid optional collections)

  1. Provide several examples of what would and wouldn't trigger violations.

Would trigger:

let foo: Bool?
let bar: Bool? = false
let baz = Optional.some(false)

These would not trigger:

// Properties should provide default value
let foo: Bool = false

// functions should return Bool instead of optional Bool
func foo() -> Bool

// input params should default to true or false instead of being optional
func foo(bar: Bool = false)

// Optional Bool's can arise from collections
let jsonData: [String: Any]
let foo: Bool? = jsonData["foo"] as? Bool
  1. Should the rule be configurable, if so what parameters should be configurable?


  1. Should the rule be opt-in or enabled by default? Why?
    See for guidelines on when to mark a
    rule as opt-in.

I'm curious what others think, but I would probably see this as an opt-in rule.

@ejmartin504 ejmartin504 changed the title from Rule Request: Avoid optional bools to Rule Request: Avoid optional Bools Jan 19, 2018


This comment has been minimized.


marcelofabri commented Feb 3, 2018

Implemented in #2013

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