heybourn / headwind

An opinionated Tailwind CSS class sorter built for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=heybourn.headwind
MIT License
1.37k stars 46 forks source link

headwind and Solidjs class support? #203

Open MariuzM opened 11 months ago

MariuzM commented 11 months ago

I cant get headwind to work in Solidjs tsx component that is using class instead of React using className

i tried but not working :(

  "headwind.classRegex": {
    "html": "\\bclass\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\']",
    "javascriptsolid": "(?:\\class\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\'])|(?:\\btw\\s*`([_a-zA-Z0-9\\s\\-\\:\\/]*)`)"
  },
LucDeCaf commented 1 month ago

I know this is technically a necropost, but I feel like others will come across this in the future and want a solution.

"javascriptsolid" isn't a file type recognised by VSCode. All JSX and TSX files match to "javascriptreact" and "typescriptreact" respectively.

With that in mind, the following regex can be used that maintains support for both className and class:

// settings.json

{
    /* Other settings... */

    "headwind.classRegex": {
        "javascriptreact": "(?:\\b(?:className|class)\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\'])|(?:\\btw\\s*`([_a-zA-Z0-9\\s\\-\\:\\/]*)`)",
        "typescriptreact": "(?:\\b(?:className|class)\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\'])|(?:\\btw\\s*`([_a-zA-Z0-9\\s\\-\\:\\/]*)`)"
    }
}

The regexes replace className with the non-capturing group (?:className|class).

P.S. You may need to restart VSCode after updating settings.json.

Hope this helps 👍