heybourn / headwind

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

Support for Svelte Sass tags. #94

Open braebo opened 3 years ago

braebo commented 3 years ago

Is your feature request related to a problem? Please describe. Headwind cannot detect Tailwind classes in <style lang="sass"> tags in Svelte components.

Describe the solution you'd like It would be awesome if I could use Headwind in Svelte components using Sass.

Describe alternatives you've considered Getting better at Regex to add my own fix / reaching out to Svelte-Preprocess or Svelte-VSCode devs for a fix.

Additional context Not detected by headwind: Screenshot 2020-09-30 at 2 00 44 PM

Let me know the best route for me to take in order to get this working (reaching out to the other projects mentioned / implementing my own fix).

heybourn commented 3 years ago

I've never used Svelte, nor did I handle a lot of the regex stuff this extension uses so I can't help you here unfortunately. If you figure something out feel free to share so I can add support.

dummdidumm commented 3 years ago

The problem is that Svelte does single file components, so css and html are in one place (that's possible for html, too, btw). So what would be needed is some kind of advanced regex which in addition to the html class regex also checks if we are in a style tag, and if yes, apply the css regex.

tshemeng commented 3 years ago

@FractalHQ

add following lines in .vscode/settings.json

    "headwind.classRegex": {
        "css": "\\B@apply\\s+([_a-zA-Z0-9\\s\\-\\:\\/]+);",
        "html": "\\bclass\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\']",
        "javascript": "(?:\\bclassName\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\'])|(?:\\btw\\s*`([_a-zA-Z0-9\\s\\-\\:\\/]*)`)",
        "javascriptreact": "(?:\\bclassName\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\'])|(?:\\btw\\s*`([_a-zA-Z0-9\\s\\-\\:\\/]*)`)",
        "svelte": "\\B@apply\\s+([_a-zA-Z0-9\\s\\-\\:\\/]+)",
        "typescript": "(?:\\bclassName\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\'])|(?:\\btw\\s*`([_a-zA-Z0-9\\s\\-\\:\\/]*)`)",
        "typescriptreact": "(?:\\bclassName\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\'])|(?:\\btw\\s*`([_a-zA-Z0-9\\s\\-\\:\\/]*)`)"
    },

this works for me.

heybourn commented 3 years ago

@tshemeng would you happen to have a REGEX I could use for Pug?

tshemeng commented 3 years ago

@tshemeng would you happen to have a REGEX I could use for Pug?

what do you mean Pug ?

tshemeng commented 3 years ago

@heybourn I think Pug's syntax prevented solving it with simple REGEX, I'm no idea for this.

pikeas commented 3 years ago

The regex works but only when triggered manually. Is there a way to apply it on save?