Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The classRegex doesn't seem to work #179

Open
bitabs opened this issue Dec 21, 2021 · 6 comments
Open

The classRegex doesn't seem to work #179

bitabs opened this issue Dec 21, 2021 · 6 comments

Comments

@bitabs
Copy link

bitabs commented Dec 21, 2021

Describe the bug
I'm trying to modify the regex so that the sorting works outside of className=.... For example, I want to modify the following regex:

"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[\\.\\sa-zA-Z]*`([_a-zA-Z0-9\\s\\-\\:\\/]*)`)",
    "javascriptreact": "(?:\\bclassName\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\'])|(?:\\btw[\\.\\sa-zA-Z]*`([_a-zA-Z0-9\\s\\-\\:\\/]*)`)",
    "typescript": "(?:\\bclassName\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\'])|(?:\\btw[\\.\\sa-zA-Z]*`([_a-zA-Z0-9\\s\\-\\:\\/]*)`)",
    "typescriptreact": "(?:\\bclassName\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\'])|(?:\\btw[\\.\\sa-zA-Z]*`([_a-zA-Z0-9\\s\\-\\:\\/]*)`)"
}

so that the sorting can work for situations like this:

import c from 'clsx'

const container = c(`w-5 flex`) // should then change to `flex w-5`

<div className={container} />

However, it's unable to sort it

@phacks
Copy link

phacks commented Jan 3, 2022

Hey @TheCapedBaldi! The version currently available on the VSCode Marketplace is a few versions behind what’s on this repo, and classRegex doesn’t seem to work on that one. v2.0.0 is available in alpha in #122 and might solve your issue!

@bitabs
Copy link
Author

bitabs commented Jan 6, 2022

Thank you @phacks. I will give it a go at it shortly, and close this ticket once it works 🙏🏻

@homerjam
Copy link

homerjam commented Jan 14, 2022

I've tested 2.0.0 and it appears classRegex isn't working, though there isn't really a clear example of how to set this up so it could be I've done it wrong

@phacks
Copy link

phacks commented Jan 14, 2022

@homerjam In case it helps, here is the classRegex we use for HAML files (the syntax is similar to Pug’s):

"headwind.classRegex": {
  "haml": [
        {
            "regex": "\\.([\\._:a-zA-Z0-9\\-]+)",
            "separator": "\\.",
            "replacement": "."
        },
        "\\bclass\\s*:\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\']"
    ],
},

@homerjam
Copy link

@homerjam In case it helps, here is the classRegex we use for HAML files (the syntax is similar to Pug’s):

"headwind.classRegex": {
  "haml": [
        {
            "regex": "\\.([\\._:a-zA-Z0-9\\-]+)",
            "separator": "\\.",
            "replacement": "."
        },
        "\\bclass\\s*:\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\']"
    ],
},

Thanks, perhaps I'm using it wrong. Is this inside package.json?

@phacks
Copy link

phacks commented Jan 14, 2022

Oh—it’s inside VSCode’s settings, not your package.json. Here’s how to change those: in VSCode, open the Command Panel (P on macOS) then search for Preferences: Open Settings (JSON).
You can then edit that JSON file to add the classRegex, save and restart VSCode for it to take effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants