From dccd2eb2ed344b3191465532a5dc66773b7ecc69 Mon Sep 17 00:00:00 2001 From: "Jorge B. | Noob In The Net" <103246614+NoobInTheNet@users.noreply.github.com> Date: Wed, 25 Nov 2026 01:22:11 +0100 Subject: [PATCH 1/4] Put classes that the CSS file lacks first MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A sorter built from a CSS file put a class that the file does not contain after all known classes. The built-in sorter and prettier-plugin-tailwindcss put such a class first, in its input order. Match them: add `Sorter::CssSorter`, which `Sorter::new_from_reader` and `Sorter::new_from_file` return, and sort its unknown classes first. The placeholders `...` and `…` stay last, as in the built-in sorter. `Sorter::CustomSorter` keeps the old order, because a list such as the `sortOrder` of a config file does not name every class. This changes the output for users of `--output-css-file` and `--vite-css`: a class that the CSS file lacks, such as a custom class name, moves from the end of the class list to its start. `--check-formatted` reports such files after the upgrade. `hover:flex` is not unknown when the file names `flex` but not `hover:flex`: it still sorts with the variants. `Sorter` gains a variant, so code that matches it exhaustively must handle `CssSorter`. Fixes #167 --- CHANGELOG.md | 10 +++ README.md | 4 +- npm/README.md | 4 +- rustywind-cli/src/main.rs | 2 + rustywind-core/CHANGELOG.md | 12 ++++ rustywind-core/src/app.rs | 135 ++++++++++++++++++++++++++++++----- rustywind-core/src/sorter.rs | 40 ++++++++--- 7 files changed, 179 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6877caff..f46ce021 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,16 @@ - Read a rule written without a space before `{`, such as `.a{`. The line regex skipped it. +### Breaking changes + +- In `--output-css-file` and `--vite-css`, classes that the CSS file does not + define now come first, in their input order, as in the built-in sorter and in + `prettier-plugin-tailwindcss`. They came last before. The placeholders `...` + and `…` still go last. The output of these options changes, so + `--check-formatted` reports files with custom classes after the upgrade, until + you run `--write`. `Sorter::CssSorter` documents the exceptions for classes + with a variant prefix. + ## [0.28.1] - 2026-11-23 ### Added diff --git a/README.md b/README.md index e998c263..069eb07f 100644 --- a/README.md +++ b/README.md @@ -158,10 +158,10 @@ Options: When set, RustyWind will use the config file to derive configurations. The config file current only supports json with one property sortOrder, e.g. { "sortOrder": ["class1", ...] } --output-css-file - When set RustyWind will determine the sort order by the order the class appear in the given CSS file + When set RustyWind will determine the sort order by the order the class appear in the given CSS file. Classes that the CSS does not define go first, in input order --vite-css - When set RustyWind will determine the sort order by the order the class appear in the CSS file that vite generates. + When set RustyWind will determine the sort order by the order the class appear in the CSS file that vite generates. Classes that the CSS does not define go first, in input order. Please provide the full URL to the CSS file ex: `rustywind --vite-css "http://127.0.0.1:5173/src/assets/main.css" . --dry-run` diff --git a/npm/README.md b/npm/README.md index 8ba7ca6a..94424184 100644 --- a/npm/README.md +++ b/npm/README.md @@ -104,10 +104,10 @@ Options: When set, RustyWind will use the config file to derive configurations. The config file current only supports json with one property sortOrder, e.g. { "sortOrder": ["class1", ...] } --output-css-file - When set RustyWind will determine the sort order by the order the class appear in the given CSS file + When set RustyWind will determine the sort order by the order the class appear in the given CSS file. Classes that the CSS does not define go first, in input order --vite-css - When set RustyWind will determine the sort order by the order the class appear in the CSS file that vite generates. + When set RustyWind will determine the sort order by the order the class appear in the CSS file that vite generates. Classes that the CSS does not define go first, in input order. Please provide the full URL to the CSS file ex: `rustywind --vite-css "http://127.0.0.1:5173/src/assets/main.css" . --dry-run` diff --git a/rustywind-cli/src/main.rs b/rustywind-cli/src/main.rs index 9e4563a1..8363aa93 100644 --- a/rustywind-cli/src/main.rs +++ b/rustywind-cli/src/main.rs @@ -78,9 +78,11 @@ pub struct Cli { #[arg(long, conflicts_with_all = &["output_css_file"])] config_file: Option, /// When set RustyWind will determine the sort order by the order the class appear in the given CSS file. + /// Classes that the CSS does not define go first, in input order. #[arg(long, conflicts_with_all = &["config_file", "vite_css"])] output_css_file: Option, /// When set RustyWind will determine the sort order by the order the class appear in the CSS file that vite generates. + /// Classes that the CSS does not define go first, in input order. /// /// Please provide the full URL to the CSS file ex: `rustywind --vite-css "http://127.0.0.1:5173/src/assets/main.css" . --dry-run` /// diff --git a/rustywind-core/CHANGELOG.md b/rustywind-core/CHANGELOG.md index eb7be014..aaf403b1 100644 --- a/rustywind-core/CHANGELOG.md +++ b/rustywind-core/CHANGELOG.md @@ -25,6 +25,18 @@ - Read a rule written without a space before `{`, such as `.a{`. The line regex skipped it. +### Breaking changes + +- A sorter built from a CSS file puts the classes that the file does not name + first, in their input order, as the built-in sorter (`Sorter::PatternSorter`) + and `prettier-plugin-tailwindcss` do. They came last before. The placeholders + `...` and `…` still go last. `Sorter::CssSorter` documents the exceptions for + classes with a variant prefix. +- `Sorter` has a new variant, `CssSorter`, which `Sorter::new_from_reader` and + `Sorter::new_from_file` return. Code that matches `Sorter` exhaustively must + handle it. `Sorter::CustomSorter` keeps the old order: classes that the list + does not name come last. + ## [0.7.0] - 2026-08-25 ### Added diff --git a/rustywind-core/src/app.rs b/rustywind-core/src/app.rs index fe9c487b..3d31e7f0 100644 --- a/rustywind-core/src/app.rs +++ b/rustywind-core/src/app.rs @@ -24,6 +24,8 @@ static PREFIXED_PATTERN_SORTERS: LazyLock { + /// Index of the class in the class list, to restore the input order of unknown classes + position: usize, original: &'a str, lookup: Cow<'a, str>, } @@ -460,16 +462,26 @@ impl RustyWind { } // otherwise, use the old HashMap-based approach - let candidates = classes.map(|class| SortCandidate { + let candidates = classes.enumerate().map(|(position, class)| SortCandidate { + position, original: class, lookup: normalize_tailwind_prefix(class, self.tailwind_prefix.as_deref()), }); + let puts_unknown_classes_first = matches!(self.sorter, Sorter::CssSorter(_)); let mut tailwind_classes: Vec<(&str, &usize)> = vec![]; - let mut custom_classes: Vec<&str> = vec![]; + let mut custom_classes: Vec<(usize, &str)> = vec![]; + let mut placeholders: Vec<&str> = vec![]; let mut variants: HashMap<&str, Vec> = HashMap::new(); for candidate in candidates { + // The placeholders `...` and `…` stay last, as in the built-in sorter, also when + // the CSS file names one of them as a class. + if puts_unknown_classes_first && is_ellipsis_placeholder(candidate.original) { + placeholders.push(candidate.original); + continue; + } + match self .sorter .get(candidate.original) @@ -486,7 +498,7 @@ impl RustyWind { let prefix = VARIANTS[prefix_match.pattern()]; variants.entry(prefix).or_default().push(candidate) } - None => custom_classes.push(candidate.original), + None => custom_classes.push((candidate.position, candidate.original)), } } } @@ -494,13 +506,11 @@ impl RustyWind { tailwind_classes.sort_by_key(|&(_class, class_placement)| class_placement); - let sorted_tailwind_classes: Vec<&str> = tailwind_classes + let mut known: Vec<&str> = tailwind_classes .iter() .map(|(class, _index)| *class) .collect(); - let mut sorted_variant_classes = vec![]; - for key in VARIANTS.iter() { let (mut sorted_classes, new_custom_classes) = self.sort_variant_classes( variants.remove(key).unwrap_or_default(), @@ -508,24 +518,32 @@ impl RustyWind { key.len() + 1, ); - sorted_variant_classes.append(&mut sorted_classes); + known.append(&mut sorted_classes); custom_classes = new_custom_classes } - [ - &sorted_tailwind_classes[..], - &sorted_variant_classes[..], - &custom_classes[..], - ] - .concat() + if puts_unknown_classes_first { + // Unknown classes keep their input order, as in prettier-plugin-tailwindcss. + custom_classes.sort_by_key(|&(position, _class)| position); + let mut sorted: Vec<&str> = custom_classes + .into_iter() + .map(|(_position, class)| class) + .collect(); + sorted.extend(known); + sorted.extend(placeholders); + sorted + } else { + known.extend(custom_classes.into_iter().map(|(_position, class)| class)); + known + } } fn sort_variant_classes<'a>( &self, classes: Vec>, - mut custom_classes: Vec<&'a str>, + mut custom_classes: Vec<(usize, &'a str)>, class_after: usize, - ) -> (Vec<&'a str>, Vec<&'a str>) { + ) -> (Vec<&'a str>, Vec<(usize, &'a str)>) { let mut tailwind_classes = Vec::with_capacity(classes.len()); for candidate in classes { @@ -557,7 +575,7 @@ impl RustyWind { Some(class_placement) => { tailwind_classes.push((candidate.original, class_placement)) } - None => custom_classes.push(candidate.original), + None => custom_classes.push((candidate.position, candidate.original)), } } @@ -1417,6 +1435,91 @@ mod tests { } } + #[test] + fn css_sorter_puts_unknown_classes_first_and_custom_sorter_puts_them_last() { + let input = "p-4 zebra custom flex hover:custom"; + let custom_app = RustyWind { + sorter: Sorter::new(HashMap::from([ + ("flex".to_string(), 0), + ("p-4".to_string(), 1), + ])), + ..RUSTYWIND_DEFAULT + }; + let css_app = css_sorter_app(".flex {\n}\n.p-4 {\n}\n"); + + assert_eq!( + custom_app.sort_classes(input), + "flex p-4 zebra custom hover:custom" + ); + assert_eq!( + css_app.sort_classes(input), + "zebra custom hover:custom flex p-4" + ); + } + + #[test] + fn css_sorter_keeps_unknown_variant_classes_in_input_order() { + let app = css_sorter_app(".flex {\n}\n"); + + // `hover:custom` is a variant class that the CSS lacks. It must not move behind `zebra`. + assert_eq!( + app.sort_classes("hover:custom zebra flex"), + "hover:custom zebra flex" + ); + } + + #[test] + fn css_sorter_sorts_a_variant_of_a_known_class_with_the_variants() { + let app = css_sorter_app(".flex {\n}\n.p-4 {\n}\n"); + + // `hover:flex` is not in the CSS, but its base class `flex` is, so it is no unknown class. + // It goes after the known classes, in the variant group. + assert_eq!( + app.sort_classes("hover:flex zebra p-4 flex"), + "zebra flex p-4 hover:flex" + ); + } + + #[test] + fn css_sorter_removes_a_duplicate_unknown_class_when_duplicates_are_not_allowed() { + let app = RustyWind { + allow_duplicates: false, + ..css_sorter_app(".flex {\n}\n") + }; + + assert_eq!(app.sort_classes("zebra flex yak zebra"), "zebra yak flex"); + } + + #[test] + fn css_sorter_keeps_ellipsis_placeholders_last() { + let app = css_sorter_app(".flex {\n}\n.p-4 {\n}\n"); + + assert_eq!( + app.sort_classes("p-4 … zebra ... flex"), + "zebra flex p-4 … ..." + ); + + // A CSS file can name `…` as a class. It stays a placeholder. + let app = css_sorter_app(".… {\n}\n.flex {\n}\n"); + assert_eq!(app.sort_classes("flex … zebra"), "zebra flex …"); + } + + #[test] + fn css_sorter_treats_only_one_built_in_variant_prefix_as_a_known_class() { + let app = css_sorter_app(".flex {\n}\n.p-4 {\n}\n"); + + // `max-md:` is no built-in variant prefix, so `max-md:flex` is unknown and goes first. + assert_eq!( + app.sort_classes("p-4 max-md:flex flex"), + "max-md:flex flex p-4" + ); + // Only one prefix is stripped, so a stacked `md:hover:flex` is unknown as well. + assert_eq!( + app.sort_classes("p-4 md:hover:flex flex"), + "md:hover:flex flex p-4" + ); + } + #[test] fn css_sorter_orders_classes_by_their_position_in_the_css() { let app = css_sorter_app( diff --git a/rustywind-core/src/sorter.rs b/rustywind-core/src/sorter.rs index 9d9b93b8..0ec4f828 100644 --- a/rustywind-core/src/sorter.rs +++ b/rustywind-core/src/sorter.rs @@ -93,13 +93,31 @@ impl Deref for FinderRegex { } } -/// Uses either pattern-based sorting or a custom sorter from a CSS file +/// Uses either pattern-based sorting or a sorter from a class list or a CSS file #[derive(Debug, Clone)] pub enum Sorter { /// Pattern-based sorting matching Tailwind CSS v4's canonical algorithm PatternSorter, - /// Custom sorter loaded from a CSS file + /// Custom sorter from a list of classes, such as the `sortOrder` of a config file. A class + /// that is not in the list goes after the classes of the list. CustomSorter(HashMap), + /// Sorter loaded from a CSS file that Tailwind generated. + /// + /// A class that the file does not name is unknown. Unknown classes go before the classes of + /// the file, in input order, as in prettier-plugin-tailwindcss. The placeholders `...` and `…` + /// go last. + /// + /// The sorter looks up the whole class first. A class that the file names itself, such as + /// `hover:bg-w` in Tailwind CSS output, keeps its own position. + /// + /// A class with a built-in variant prefix, such as `hover:` or `md:`, that the file does not + /// name itself is not unknown when the file names the part after the prefix. `hover:flex` is + /// then known when the file names `flex` but not `hover:flex`. It goes after the classes of + /// the file, with the variants. Only the first prefix counts: + /// `md:hover:flex` is known when the file names `hover:flex`. A class with another prefix, + /// such as `max-md:flex` or `peer-hover:flex`, is unknown unless the file names the whole + /// class. + CssSorter(HashMap), } impl Deref for Sorter { @@ -110,20 +128,24 @@ impl Deref for Sorter { Self::PatternSorter => { panic!("PatternSorter should not be used with HashMap-based sorting") } - Self::CustomSorter(sorter) => sorter, + Self::CustomSorter(sorter) | Self::CssSorter(sorter) => sorter, } } } impl Sorter { - /// Creates a custom sorter from class positions + /// Creates a [`Sorter::CustomSorter`] from class positions + /// + /// A class that the map lacks goes after the classes of the map. To put such classes first, + /// wrap the map in [`Sorter::CssSorter`] instead. pub fn new(sorter: HashMap) -> Self { Self::CustomSorter(sorter) } - /// Creates the sorter from a [File] + /// Creates a [`Sorter::CssSorter`] from a [File] /// - /// See [`Sorter::new_from_reader`] for the order of the classes. + /// See [`Sorter::new_from_reader`] for the order of the classes, and [`Sorter::CssSorter`] + /// for the order of unknown classes. /// /// # Errors /// @@ -134,12 +156,14 @@ impl Sorter { Self::new_from_reader(css_reader) } - /// Creates the sorter from any [BufReader] + /// Creates a [`Sorter::CssSorter`] from any [BufReader] /// /// The order is the order of the first rule that names a class. Each selector gives one class: /// the longest one with a `:` in its name, else the first class of its last compound selector /// that holds a class. A prelude with `&` and an at-rule prelude give none. /// + /// See [`Sorter::CssSorter`] for the order of unknown classes. + /// /// # Errors /// /// Returns an error when reading fails, or when the input is not valid UTF-8 @@ -154,7 +178,7 @@ impl Sorter { classes.entry(class).or_insert(next); } - Ok(Self::new(classes)) + Ok(Self::CssSorter(classes)) } } From 5c71a41dae0ff4ead4d99f4943e06d92a145e439 Mon Sep 17 00:00:00 2001 From: Praveen Perera Date: Wed, 25 Nov 2026 12:41:56 -0600 Subject: [PATCH 2/4] Address review of the CSS class order changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test the JSON unicode escape in the Vite module with a real `é`, since the literal `é` repeated the previous test. Say in the help text and READMEs that a variant of a defined class, such as `hover:flex`, sorts after the defined classes, and correct the changelogs: the placeholders now go last, they did not before. Record two selector shapes the scan misreads as known limits. --- CHANGELOG.md | 2 +- README.md | 4 ++-- npm/README.md | 4 ++-- rustywind-cli/src/main.rs | 6 ++++-- rustywind-core/CHANGELOG.md | 2 +- rustywind-core/src/css_class_order.rs | 6 ++++++ rustywind-vite/src/sorter.rs | 4 ++-- 7 files changed, 18 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f46ce021..cc6253c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,7 +32,7 @@ - In `--output-css-file` and `--vite-css`, classes that the CSS file does not define now come first, in their input order, as in the built-in sorter and in `prettier-plugin-tailwindcss`. They came last before. The placeholders `...` - and `…` still go last. The output of these options changes, so + and `…` now go last. The output of these options changes, so `--check-formatted` reports files with custom classes after the upgrade, until you run `--write`. `Sorter::CssSorter` documents the exceptions for classes with a variant prefix. diff --git a/README.md b/README.md index 069eb07f..28248ce7 100644 --- a/README.md +++ b/README.md @@ -158,10 +158,10 @@ Options: When set, RustyWind will use the config file to derive configurations. The config file current only supports json with one property sortOrder, e.g. { "sortOrder": ["class1", ...] } --output-css-file - When set RustyWind will determine the sort order by the order the class appear in the given CSS file. Classes that the CSS does not define go first, in input order + When set RustyWind will determine the sort order by the order the class appear in the given CSS file. Classes that the CSS does not define go first, in input order. A class with one built-in variant prefix, such as `hover:flex`, whose base class the CSS defines goes after the defined classes --vite-css - When set RustyWind will determine the sort order by the order the class appear in the CSS file that vite generates. Classes that the CSS does not define go first, in input order. + When set RustyWind will determine the sort order by the order the class appear in the CSS file that vite generates. Classes that the CSS does not define go first, in input order. A class with one built-in variant prefix, such as `hover:flex`, whose base class the CSS defines goes after the defined classes. Please provide the full URL to the CSS file ex: `rustywind --vite-css "http://127.0.0.1:5173/src/assets/main.css" . --dry-run` diff --git a/npm/README.md b/npm/README.md index 94424184..da4f34ff 100644 --- a/npm/README.md +++ b/npm/README.md @@ -104,10 +104,10 @@ Options: When set, RustyWind will use the config file to derive configurations. The config file current only supports json with one property sortOrder, e.g. { "sortOrder": ["class1", ...] } --output-css-file - When set RustyWind will determine the sort order by the order the class appear in the given CSS file. Classes that the CSS does not define go first, in input order + When set RustyWind will determine the sort order by the order the class appear in the given CSS file. Classes that the CSS does not define go first, in input order. A class with one built-in variant prefix, such as `hover:flex`, whose base class the CSS defines goes after the defined classes --vite-css - When set RustyWind will determine the sort order by the order the class appear in the CSS file that vite generates. Classes that the CSS does not define go first, in input order. + When set RustyWind will determine the sort order by the order the class appear in the CSS file that vite generates. Classes that the CSS does not define go first, in input order. A class with one built-in variant prefix, such as `hover:flex`, whose base class the CSS defines goes after the defined classes. Please provide the full URL to the CSS file ex: `rustywind --vite-css "http://127.0.0.1:5173/src/assets/main.css" . --dry-run` diff --git a/rustywind-cli/src/main.rs b/rustywind-cli/src/main.rs index 8363aa93..7a094284 100644 --- a/rustywind-cli/src/main.rs +++ b/rustywind-cli/src/main.rs @@ -78,11 +78,13 @@ pub struct Cli { #[arg(long, conflicts_with_all = &["output_css_file"])] config_file: Option, /// When set RustyWind will determine the sort order by the order the class appear in the given CSS file. - /// Classes that the CSS does not define go first, in input order. + /// Classes that the CSS does not define go first, in input order. A class with one built-in variant + /// prefix, such as `hover:flex`, whose base class the CSS defines goes after the defined classes. #[arg(long, conflicts_with_all = &["config_file", "vite_css"])] output_css_file: Option, /// When set RustyWind will determine the sort order by the order the class appear in the CSS file that vite generates. - /// Classes that the CSS does not define go first, in input order. + /// Classes that the CSS does not define go first, in input order. A class with one built-in variant + /// prefix, such as `hover:flex`, whose base class the CSS defines goes after the defined classes. /// /// Please provide the full URL to the CSS file ex: `rustywind --vite-css "http://127.0.0.1:5173/src/assets/main.css" . --dry-run` /// diff --git a/rustywind-core/CHANGELOG.md b/rustywind-core/CHANGELOG.md index aaf403b1..d69809b3 100644 --- a/rustywind-core/CHANGELOG.md +++ b/rustywind-core/CHANGELOG.md @@ -30,7 +30,7 @@ - A sorter built from a CSS file puts the classes that the file does not name first, in their input order, as the built-in sorter (`Sorter::PatternSorter`) and `prettier-plugin-tailwindcss` do. They came last before. The placeholders - `...` and `…` still go last. `Sorter::CssSorter` documents the exceptions for + `...` and `…` now go last. `Sorter::CssSorter` documents the exceptions for classes with a variant prefix. - `Sorter` has a new variant, `CssSorter`, which `Sorter::new_from_reader` and `Sorter::new_from_file` return. Code that matches `Sorter` exhaustively must diff --git a/rustywind-core/src/css_class_order.rs b/rustywind-core/src/css_class_order.rs index 1903d6f1..891d845e 100644 --- a/rustywind-core/src/css_class_order.rs +++ b/rustywind-core/src/css_class_order.rs @@ -34,6 +34,12 @@ //! //! - The scan suits the selectors that Tailwind CSS emits. For hand-written component CSS such //! as `.card .title { }`, it registers `title`, and `card` stays unknown. +//! - A utility whose only rule styles a descendant class, such as `@utility btn { & .icon { } }`, +//! compiles to `.btn .icon` and registers `icon`. `btn` stays unknown. A utility with +//! declarations of its own also emits `.btn { }`, which registers `btn`. +//! - A custom variant whose selector names a class with a colon that is longer than the +//! candidate, such as `@custom-variant x (&:where(.md\:grid-cols-2 *))`, registers +//! `md:grid-cols-2` for that rule instead of `x:flex`. //! - A nested rule without `&`, in the form `.a { .b { } }` or `.a { > .b { } }`, registers `a` //! and `b`. Tailwind CSS does not emit this form. //! - `cssparser` allows 75 nested blocks, and the block of a rule counts as one. The scan skips a diff --git a/rustywind-vite/src/sorter.rs b/rustywind-vite/src/sorter.rs index 209e1cb8..a2f25024 100644 --- a/rustywind-vite/src/sorter.rs +++ b/rustywind-vite/src/sorter.rs @@ -93,8 +93,8 @@ mod tests { #[test] fn decodes_a_unicode_escape_of_the_javascript_string_literal() { - // The module line is literal text: `é` is the escape for `é`. - let sorter = sorter_from_module(r#"const __vite__css = ".é { }""#).unwrap(); + // The module line is literal text: `\u00e9` is the JSON escape for `é`. + let sorter = sorter_from_module(r#"const __vite__css = ".\u00e9 { }""#).unwrap(); assert_eq!(sorter.get("é"), Some(&0)); assert_eq!(sorter.len(), 1); From d0873f3b6a04e600b6e97748135c2c6984497394 Mon Sep 17 00:00:00 2001 From: Praveen Perera Date: Wed, 25 Nov 2026 12:41:56 -0600 Subject: [PATCH 3/4] Mark Sorter as non_exhaustive Sorter gains CssSorter in this release, which already breaks exhaustive matches, so take the break once and let later variants be additive. --- rustywind-core/CHANGELOG.md | 2 ++ rustywind-core/src/sorter.rs | 1 + 2 files changed, 3 insertions(+) diff --git a/rustywind-core/CHANGELOG.md b/rustywind-core/CHANGELOG.md index d69809b3..32d0cbd4 100644 --- a/rustywind-core/CHANGELOG.md +++ b/rustywind-core/CHANGELOG.md @@ -36,6 +36,8 @@ `Sorter::new_from_file` return. Code that matches `Sorter` exhaustively must handle it. `Sorter::CustomSorter` keeps the old order: classes that the list does not name come last. +- `Sorter` is now `#[non_exhaustive]`, so a later variant is not a breaking + change. A `match` on `Sorter` outside this crate needs a wildcard arm. ## [0.7.0] - 2026-08-25 diff --git a/rustywind-core/src/sorter.rs b/rustywind-core/src/sorter.rs index 0ec4f828..88a0b7f4 100644 --- a/rustywind-core/src/sorter.rs +++ b/rustywind-core/src/sorter.rs @@ -95,6 +95,7 @@ impl Deref for FinderRegex { /// Uses either pattern-based sorting or a sorter from a class list or a CSS file #[derive(Debug, Clone)] +#[non_exhaustive] pub enum Sorter { /// Pattern-based sorting matching Tailwind CSS v4's canonical algorithm PatternSorter, From cbe64d7264ed7dda470efb0bd0a714b35fe09d48 Mon Sep 17 00:00:00 2001 From: Praveen Perera Date: Wed, 25 Nov 2026 12:45:13 -0600 Subject: [PATCH 4/4] Correct the CSS sort help and scan limits A variant class that the CSS defines keeps its own position, so the help now names the real fallback: the part after the first built-in prefix. The two new scan limits apply only to flat Tailwind output. --- README.md | 4 ++-- npm/README.md | 4 ++-- rustywind-cli/src/main.rs | 10 ++++++---- rustywind-core/src/css_class_order.rs | 9 +++++---- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 28248ce7..d8293f88 100644 --- a/README.md +++ b/README.md @@ -158,10 +158,10 @@ Options: When set, RustyWind will use the config file to derive configurations. The config file current only supports json with one property sortOrder, e.g. { "sortOrder": ["class1", ...] } --output-css-file - When set RustyWind will determine the sort order by the order the class appear in the given CSS file. Classes that the CSS does not define go first, in input order. A class with one built-in variant prefix, such as `hover:flex`, whose base class the CSS defines goes after the defined classes + When set RustyWind will determine the sort order by the order the class appear in the given CSS file. Classes that the CSS does not define go first, in input order. A class such as `hover:flex` that the CSS does not define, but whose part after the first built-in variant prefix it does, goes after the defined classes --vite-css - When set RustyWind will determine the sort order by the order the class appear in the CSS file that vite generates. Classes that the CSS does not define go first, in input order. A class with one built-in variant prefix, such as `hover:flex`, whose base class the CSS defines goes after the defined classes. + When set RustyWind will determine the sort order by the order the class appear in the CSS file that vite generates. Classes that the CSS does not define go first, in input order. A class such as `hover:flex` that the CSS does not define, but whose part after the first built-in variant prefix it does, goes after the defined classes. Please provide the full URL to the CSS file ex: `rustywind --vite-css "http://127.0.0.1:5173/src/assets/main.css" . --dry-run` diff --git a/npm/README.md b/npm/README.md index da4f34ff..dde4ed86 100644 --- a/npm/README.md +++ b/npm/README.md @@ -104,10 +104,10 @@ Options: When set, RustyWind will use the config file to derive configurations. The config file current only supports json with one property sortOrder, e.g. { "sortOrder": ["class1", ...] } --output-css-file - When set RustyWind will determine the sort order by the order the class appear in the given CSS file. Classes that the CSS does not define go first, in input order. A class with one built-in variant prefix, such as `hover:flex`, whose base class the CSS defines goes after the defined classes + When set RustyWind will determine the sort order by the order the class appear in the given CSS file. Classes that the CSS does not define go first, in input order. A class such as `hover:flex` that the CSS does not define, but whose part after the first built-in variant prefix it does, goes after the defined classes --vite-css - When set RustyWind will determine the sort order by the order the class appear in the CSS file that vite generates. Classes that the CSS does not define go first, in input order. A class with one built-in variant prefix, such as `hover:flex`, whose base class the CSS defines goes after the defined classes. + When set RustyWind will determine the sort order by the order the class appear in the CSS file that vite generates. Classes that the CSS does not define go first, in input order. A class such as `hover:flex` that the CSS does not define, but whose part after the first built-in variant prefix it does, goes after the defined classes. Please provide the full URL to the CSS file ex: `rustywind --vite-css "http://127.0.0.1:5173/src/assets/main.css" . --dry-run` diff --git a/rustywind-cli/src/main.rs b/rustywind-cli/src/main.rs index 7a094284..d9ccf215 100644 --- a/rustywind-cli/src/main.rs +++ b/rustywind-cli/src/main.rs @@ -78,13 +78,15 @@ pub struct Cli { #[arg(long, conflicts_with_all = &["output_css_file"])] config_file: Option, /// When set RustyWind will determine the sort order by the order the class appear in the given CSS file. - /// Classes that the CSS does not define go first, in input order. A class with one built-in variant - /// prefix, such as `hover:flex`, whose base class the CSS defines goes after the defined classes. + /// Classes that the CSS does not define go first, in input order. A class such as `hover:flex` that + /// the CSS does not define, but whose part after the first built-in variant prefix it does, goes + /// after the defined classes. #[arg(long, conflicts_with_all = &["config_file", "vite_css"])] output_css_file: Option, /// When set RustyWind will determine the sort order by the order the class appear in the CSS file that vite generates. - /// Classes that the CSS does not define go first, in input order. A class with one built-in variant - /// prefix, such as `hover:flex`, whose base class the CSS defines goes after the defined classes. + /// Classes that the CSS does not define go first, in input order. A class such as `hover:flex` that + /// the CSS does not define, but whose part after the first built-in variant prefix it does, goes + /// after the defined classes. /// /// Please provide the full URL to the CSS file ex: `rustywind --vite-css "http://127.0.0.1:5173/src/assets/main.css" . --dry-run` /// diff --git a/rustywind-core/src/css_class_order.rs b/rustywind-core/src/css_class_order.rs index 891d845e..a3705025 100644 --- a/rustywind-core/src/css_class_order.rs +++ b/rustywind-core/src/css_class_order.rs @@ -34,10 +34,11 @@ //! //! - The scan suits the selectors that Tailwind CSS emits. For hand-written component CSS such //! as `.card .title { }`, it registers `title`, and `card` stays unknown. -//! - A utility whose only rule styles a descendant class, such as `@utility btn { & .icon { } }`, -//! compiles to `.btn .icon` and registers `icon`. `btn` stays unknown. A utility with -//! declarations of its own also emits `.btn { }`, which registers `btn`. -//! - A custom variant whose selector names a class with a colon that is longer than the +//! - In the flat output of Tailwind CSS 4.3.3 and later, a utility whose only rule styles a +//! descendant class, such as `@utility btn { & .icon { width: 2rem; } }`, compiles to +//! `.btn .icon` and registers `icon`. `btn` stays unknown. A utility with declarations of its +//! own also emits `.btn { }`, which registers `btn`. Nested output keeps the outer `.btn` rule. +//! - In the same flat output, a custom variant whose selector names a class with a colon that is longer than the //! candidate, such as `@custom-variant x (&:where(.md\:grid-cols-2 *))`, registers //! `md:grid-cols-2` for that rule instead of `x:flex`. //! - A nested rule without `&`, in the form `.a { .b { } }` or `.a { > .b { } }`, registers `a`