mark-nicepants / figma2flutter

Converts design token json files to flutter
Apache License 2.0
17 stars 16 forks source link

[BUG] Name munging fails with leading underscores or trailing non alphabetic characters #8

Closed freemansoft closed 8 months ago

freemansoft commented 8 months ago

:information_source: Info

Version: 0.2.0-alpha current head of the main branch

:speech_balloon: Description

variable names or other string generation removes spaces and underscores. That code fails if there is a

  1. leading underscore Eg: _base
  2. trailing dash and special character Eg: -↑

I had to remove the leading underscores the trailing underscores and the special characters.

:scroll: tokens file you tried to import

These tokens fail because of the arrow characters. Generated by zengarden

        "0-deg-↑": {
          "value": "linear-gradient(0deg, #475569 0%, #94a3b8 100%)",
          "type": "color"
        },
        "45-deg-↗": {
          "value": "linear-gradient(45deg, #475569 0%, #94a3b8 100%)",
          "type": "color"
        },
        "90-deg-→": {
          "value": "linear-gradient(90deg, #475569 0%, #94a3b8 100%)",
          "type": "color"
        },
        "180-deg-↓": {
          "value": "linear-gradient(180deg, #475569 0%, #94a3b8 100%)",
          "type": "color"
        },
        "225-deg-↙": {
          "value": "linear-gradient(225deg, #475569 0%, #94a3b8 100%)",
          "type": "color"
        },
        "270-deg-←": {
          "value": "linear-gradient(270deg, #475569 0%, #94a3b8 100%)",
          "type": "color"
        }

leading underscores generated by zengarden

  "radii": {
    "50": {
      "value": "{radii.base} * .5",
      "type": "borderRadius"
    },
    "75": {
      "value": "{radii.base} * .75",
      "type": "borderRadius"
    },
    "100": {
      "value": "{radii.base} * 1",
      "type": "borderRadius"
    },
    "150": {
      "value": "{radii.base} * 1.5",
      "type": "borderRadius"
    },
    "200": {
      "value": "{radii.base} * 2",
      "type": "borderRadius"
    },
    "250": {
      "value": "{radii.base} * 2.50",
      "type": "borderRadius"
    },
    "300": {
      "value": "{radii.base} * 3",
      "type": "borderRadius"
    },
    "400": {
      "value": "{radii.base} * 4",
      "type": "borderRadius"
    },
    "500": {
      "value": "{radii.base} * 5",
      "type": "borderRadius"
    },
    "600": {
      "value": "{radii.base} * 6",
      "type": "borderRadius"
    },
    "800": {
      "value": "{radii.base} * 8",
      "type": "borderRadius"
    },
    "none": {
      "value": "0",
      "type": "borderRadius"
    },
    "round": {
      "value": "9999",
      "type": "borderRadius"
    },
    "_base": {
      "value": "8",
      "type": "borderRadius"
    }
  },
freemansoft commented 8 months ago

The README in example2 in this PR https://github.com/mark-nicepants/figma2flutter/pull/4 describes this

stongef-sonepar commented 8 months ago

Could you take a look if my PR #7 fixes this issue? I removed the extension methods for camel and pascal cased that were custom made and added recase package.

freemansoft commented 8 months ago

I'm not sure how to merge the changes in this open PR into my branch in my fork :-( Will manually apply changes for testing.

freemansoft commented 8 months ago

Your change fixes the leading underscore issue 👍

There is still the issue that for the zengarden generated labels they include symbol characters that are illegal as variable names in dart. Not a big deal I don't think.

freemansoft commented 8 months ago

Fixed by PR https://github.com/mark-nicepants/figma2flutter/pull/4