Skip to content
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

Closed
2 tasks done
ejmartin504 opened this issue Jan 19, 2018 · 1 comment
Closed
2 tasks done

Rule Request: Avoid optional Bools #2011

ejmartin504 opened this issue Jan 19, 2018 · 1 comment
Labels
rule-request Requests for a new rules.

Comments

@ejmartin504
Copy link

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?

No

  1. Should the rule be opt-in or enabled by default? Why?
    See README.md 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 Rule Request: Avoid optional bools Rule Request: Avoid optional Bools Jan 19, 2018
@marcelofabri marcelofabri added the rule-request Requests for a new rules. label Jan 19, 2018
@marcelofabri
Copy link
Collaborator

Implemented in #2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule-request Requests for a new rules.
Projects
None yet
Development

No branches or pull requests

2 participants