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

Allow configuration of 'discouraged_object_literal' rule #2439

Closed
2 tasks done
shagedorn opened this issue Oct 15, 2018 · 2 comments
Closed
2 tasks done

Allow configuration of 'discouraged_object_literal' rule #2439

shagedorn opened this issue Oct 15, 2018 · 2 comments
Labels
enhancement Ideas for improvements of existing features and rules.

Comments

@shagedorn
Copy link

New Issue Checklist

New rule request

Similar to the object_literal rule, I'd like to have configurability for the inverse discouraged_object_literal rule, to enforce literals for some objects, and enforce the opposite for others.

Currently, only enforcing literals can be configured, but you cannot selectively discourage the others.

The main motivation comes from Xcode 10's terrible image literal support (you can basically only use them by dragging from the media library, and it's very hard to see or edit the raw image names in Xcode, nor do you see a preview).

Our goal is to enforce literals for all objects (currently that means colors), except for images, where we want to enforce non-literal syntax.

The relevant part of our config file would look like this:

opt_in_rules:
  - discouraged_object_literal
  - object_literal

# this part doesn't work yet
discouraged_object_literal:
  color_literal: false

# this already works
object_literal:
  image_literal: false

I would assume the existing ObjectLiteralConfiguration can be used for both rules.

Unless I'm missing something and this option shouldn't be implemented after all, I would volunteer to look into the code myself.

@realm-probot realm-probot bot added the O:User label Oct 15, 2018
@marcelofabri marcelofabri added the enhancement Ideas for improvements of existing features and rules. label Oct 17, 2018
@marcelofabri
Copy link
Collaborator

A PR would be welcome!

@shagedorn
Copy link
Author

Thank you 🎄

sjavora pushed a commit to sjavora/SwiftLint that referenced this issue Mar 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Ideas for improvements of existing features and rules.
Projects
None yet
Development

No branches or pull requests

2 participants