rustywind icon indicating copy to clipboard operation
rustywind copied to clipboard

sort @apply in css files

Open onelesd opened this issue 2 years ago • 8 comments

Are there plans to support this?

onelesd avatar Mar 11 '22 21:03 onelesd

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

alexpriftuli avatar Mar 30 '22 16:03 alexpriftuli

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;
}

azzamsa avatar Aug 28 '22 08:08 azzamsa

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.

alexpriftuli avatar Aug 29 '22 08:08 alexpriftuli

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!.

azzamsa avatar Aug 31 '22 07:08 azzamsa

@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.

Rolv-Apneseth avatar Apr 15 '24 22:04 Rolv-Apneseth

@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.

praveenperera avatar Apr 15 '24 22:04 praveenperera

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

Rolv-Apneseth avatar Apr 15 '24 22:04 Rolv-Apneseth

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?

Rolv-Apneseth avatar Jun 05 '24 17:06 Rolv-Apneseth