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

sort @apply in css files #54

Open
onelesd opened this issue Mar 11, 2022 · 10 comments
Open

sort @apply in css files #54

onelesd opened this issue Mar 11, 2022 · 10 comments

Comments

@onelesd
Copy link

onelesd commented Mar 11, 2022

Are there plans to support this?

@alexpriftuli
Copy link

I did this with a custom regex
rustywind --custom-regex "@apply ([_a-zA\.-Z0-9\s\-:\[\]]+);" --write ./src/css/**/*

@azzamsa
Copy link
Contributor

azzamsa commented Aug 28, 2022

Is there a way not to break other lines?

rustywind --custom-regex "@apply ([_a-zA\.-Z0-9\s\-:\[\]]+);" --write ./src/css/**/ gives me this:

modified   src/styles/base/utilities.css
@@ -2,10 +2,7 @@
 
 /*  subtle 'fade in' to the lazyloaded image */
 [data-lazy] {
-  @apply w-full opacity-0;
-
-  transition: opacity 0.25s ease-in;
-  min-height: 120px;
+  @apply w-full opacity-0; transition: opacity 0.25s ease-in; min-height: 120px;
 }

Expected: (don't change other lines)

[data-lazy] {
+ @apply w-full opacity-0;
  transition: opacity 0.25s ease-in;
  min-height: 120px;
}

@alexpriftuli
Copy link

rustywind --custom-regex "@apply ([_a-zA\.-Z0-9\-:\[\] ]+);" --write ./src/css/**/*

Instead of \s you can put (space) at the end, before the last ]
\s gets all whitespaces, including \n.

@azzamsa
Copy link
Contributor

azzamsa commented Aug 31, 2022

rustywind --custom-regex "@apply ([_a-zA.-Z0-9-:[] ]+);" --write ./src/css/**/*

Thank you. Worked like a charm!

Before:

 /*  subtle 'fade in' to the lazyloaded image */
 [data-lazy] {
-  @apply w-full opacity-0;
-
-  transition: opacity 0.25s ease-in;
-  min-height: 120px;
+  @apply w-full opacity-0; transition: opacity 0.25s ease-in; min-height: 120px;
 }

After: ✅ (I change the class order of @apply to see it it works but doesn't mess the other lines)

@@ -2,7 +2,7 @@

/*  subtle 'fade in' to the lazyloaded image */
[data-lazy] {
-  @apply w-full opacity-0;
+  @apply opacity-0 w-full;

  transition: opacity 0.25s ease-in;
  min-height: 120px;

@alexpriftuli What a regex guru! Thanks a lot!.

@Rolv-Apneseth
Copy link
Contributor

@praveenperera would you like this to be an included feature? Maybe a flag specifically for doing the @apply rule or just one for specifically CSS files? Minor but it is nice to have.

@praveenperera
Copy link
Member

@Rolv-Apneseth I forget if we support multiple regex's now, if so we could add it as another regex. Will need some tests to confirm its working on not messing other stuff up.

@Rolv-Apneseth
Copy link
Contributor

As in - it would just get run by default? But yeah I could try do this when I have some time.

@Rolv-Apneseth
Copy link
Contributor

Hey sorry forgot about this, didn't get a notification for the reaction.

So I don't think there's currently a way for running multiple regexes, but I could try implement that if you like. So the RE static variable would be a list of regexes?

Alternatively (I think) this regex can handle both cases (?:\bclass(?:Name)*\s*=\s*["']|@apply )([_a-zA-Z0-9\.\s\-:\[\]\/]+)["';].

Are you sure this wouldn't be better behind some kind of flag since it's covering a different use-case?

@weber-s
Copy link

weber-s commented Nov 15, 2024

Hello!

I would prefer the regex handling both case, notably because of editor integration that run on save. If the regex handle both, there is nothing more to do.
The same is true for pre-commit, etc.

Thank you!

@praveenperera
Copy link
Member

praveenperera commented Nov 22, 2024

My plan is to write parsers for different files that can extract the classes, I'll start with one for css.

It will always fallback to the default regex and you'll have the option to skip the parsers completely.

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

6 participants