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: Enforce Double for function arguments instead of CGFloat #2753

Open
2 tasks done
sindresorhus opened this issue May 9, 2019 · 2 comments
Open
2 tasks done

Comments

@sindresorhus
Copy link

New Issue Checklist

New rule request

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

I prefer to only use Double for floats in my own functions, for consistency and ease of use, never CGFloat. I only support 64-bit systems, so CGFloat has no practical benefit for me. However, I often get PRs on my open source projects where they use CGFloat. Would be nice to be able to enforce using Double.

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

Would trigger:

func foo(number: CGFloat) {}

Would not trigger:

func foo(number: Double) {}
  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.

Opt-in

@emmavray
Copy link

emmavray commented May 9, 2019

@sindresorhus is there a reason to target function arguments specifically, and not a CGFloat used elsewhere?

@sindresorhus
Copy link
Author

It's the easiest case to target that will never have false-positives. Let's say the rule also supports variable declarations. What if a variable is passed into an Apple API that requires CGFloat? You would have to do appleAPI(number: CGFloat(yourNumber)) at every callsite. While I personally don't mind that for the purity of having Double's everywhere, that's more controversial, and I wanted to get the least controversial thing added first.

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

No branches or pull requests

3 participants