IBLinter icon indicating copy to clipboard operation
IBLinter copied to clipboard

Allow users to define valid UserRuntimeAttributes

Open SD10 opened this issue 6 years ago • 3 comments

At IBAnimatable we have a ton of UIKit subclasses with @IBInspectable properties. Some of these are String's and can be very error prone to work with.

Example: The border property accepts a String of either: solid or dash

If the user writes something like dotted, we should show an error

I think this is possible but the user has to tell us: a) All valid keys b) All classes/subclasses this property is used on

Probably in a .yml file?

That may seem like a lot of work but if IBAnimatable were to publish this .yml file on their docs, it could be reusable.

SD10 avatar Mar 22 '18 21:03 SD10

The idea which validates runtime attributes looks good. But all valid keys and classes definitions make .iblinter.yml too complex. So we extract the definitions to another file. IBAnimatable‘s valid key map .yml file may be published as IBDecodable plugin.

kateinoigakukun avatar Mar 22 '18 23:03 kateinoigakukun

decoding UserRuntimeAttributes https://github.com/IBDecodable/IBDecodable/pull/5

I am interested with this feature. I am thinking about generating the file using sourcery if @IBInspectable annotation is accessible. Each framework must provide its own file.

phimage avatar Apr 09 '18 10:04 phimage

How about having a rule, similar to custom_module_rule which would take as a param list of files where each IBInspectable will provide valid values in a comment. Since IBLiner already has SourceKitten as a dependency it (probably?) can be done.

...
user_runtime_attributes:
- path_to_file
...
// _blurEffectStyle: ExtraLight, Light, Dark
@IBInspectable var _blurEffectStyle: String? {
  didSet {
    ...

// _borderType: solid, dash
@IBInspectable var _borderType: String? {
  didSet {
    ...

viktorasl avatar Jan 25 '19 08:01 viktorasl