Style-dictionary: Removing .value from aliases

Created on 23 Mar 2021  路  4Comments  路  Source: amzn/style-dictionary

If all values have to be defined with value, as explained by @chazzmoney in https://github.com/amzn/style-dictionary/issues/119#issuecomment-526755832 , could .value be removed from the end of all aliases (or made optional, to not break existing ones), as it is used everywhere?

Instead of this:

{
  "color": {
    "alert": { "value": "red" },
    "reference": { "value": "{color.alert.value}" }
  }
}

We could write this:

{
  "color": {
    "alert": { "value": "red" },
    "reference": { "value": "{color.alert}" }
  }
}

Not a great gain here on an example with one single alias, but nice in a larger code base.

discuss enhancement

Most helpful comment

@dbanksdesign I didn't think about transitive transforms indeed. (They are awesome btw!)

One way would be to try the alias path first, and try with the added .value only if it didn't match.

All 4 comments

I like this idea, I know it is a pain to write .value all the time. One thing we would need to consider is technically you can reference things that are not tokens. The 'transitive-transforms' example in the 3.0 branch shows one example: https://github.com/amzn/style-dictionary/blob/3.0/examples/advanced/transitive-transforms/tokens/color/core.json5#L13

If there would be a way to do this while not breaking the other types of references I would be all for it!

@dbanksdesign I didn't think about transitive transforms indeed. (They are awesome btw!)

One way would be to try the alias path first, and try with the added .value only if it didn't match.

what if you want to alias other stuff than value? :fire:

How about a build message when it fails due to a missing reference that suggests, "Did you remember to add .value to your reference(s)"? Maybe a band aid but it may be the band aid that Gotham needs, for now. Again, not ideal and as mentioned here you are not always referencing a .value but maybe this helps nudge another idea.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

johnny353535 picture johnny353535  路  3Comments

dbanksdesign picture dbanksdesign  路  5Comments

chazzmoney picture chazzmoney  路  4Comments

custa1200 picture custa1200  路  5Comments

gael-boyenval picture gael-boyenval  路  3Comments