diff --git a/Cargo.lock b/Cargo.lock index da83539..0dd0e9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -645,8 +645,8 @@ dependencies = [ "once_cell", "rayon", "regex", - "rustywind_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustywind_vite 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rustywind_core", + "rustywind_vite", "serde", "serde_json", ] @@ -665,20 +665,6 @@ dependencies = [ "test-case", ] -[[package]] -name = "rustywind_core" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18cfff3749d71f686b32eb5520949084e63855573003730b92e23e20c459b7c1" -dependencies = [ - "ahash", - "aho-corasick", - "eyre", - "itertools", - "once_cell", - "regex", -] - [[package]] name = "rustywind_vite" version = "0.2.1" @@ -688,22 +674,7 @@ dependencies = [ "once_cell", "regex", "rustls", - "rustywind_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ureq", -] - -[[package]] -name = "rustywind_vite" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74e9b5bfc1c9746c95310d4a9bc99377f2080923c345f72cc7688d8cd2a69280" -dependencies = [ - "color-eyre", - "eyre", - "once_cell", - "regex", - "rustls", - "rustywind_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rustywind_core", "ureq", ] diff --git a/rustywind-cli/Cargo.toml b/rustywind-cli/Cargo.toml index 0370029..1658c1c 100644 --- a/rustywind-cli/Cargo.toml +++ b/rustywind-cli/Cargo.toml @@ -16,8 +16,11 @@ pkg-fmt = "tgz" [dependencies] # rustywind -rustywind_core = { version = "0.2.1" } -rustywind_vite = { version = "0.2.1" } +rustywind_core = { path = "../rustywind-core" } +rustywind_vite = { path = "../rustywind-vite" } + +# rustywind_core = { version = "0.3" } +# rustywind_vite = { version = "0.3" } # iter itertools = { workspace = true } diff --git a/rustywind-cli/src/main.rs b/rustywind-cli/src/main.rs index d24c194..2f86f1d 100644 --- a/rustywind-cli/src/main.rs +++ b/rustywind-cli/src/main.rs @@ -89,7 +89,7 @@ pub struct Cli { custom_regex: Option, /// Specify how individual classes are wrapped. #[arg(long)] - class_wrapping: Option, + class_wrapping: Option, /// Do not print log messages #[arg(long, default_value = "false", conflicts_with_all = &["dry_run"])] quiet: bool, diff --git a/rustywind-cli/src/options.rs b/rustywind-cli/src/options.rs index 07cab14..7011bff 100644 --- a/rustywind-cli/src/options.rs +++ b/rustywind-cli/src/options.rs @@ -4,7 +4,7 @@ use eyre::{Context, Result}; use ignore::WalkBuilder; use itertools::Itertools; use regex::Regex; -use rustywind_core::sorter::HowClassesAreWrapped; +use rustywind_core::sorter::ClassWrapping; use rustywind_core::{parser, sorter}; use rustywind_vite::create_vite_sorter; use serde::Deserialize; @@ -36,14 +36,14 @@ struct ConfigFileContents { // Wrapper to be able to use the `ValueEnum` trait without adding clap to the core crate #[derive(Clone, Copy, Debug)] -pub struct CliHowClassesAreWrapped(HowClassesAreWrapped); +pub struct CliClassWrapping(ClassWrapping); -impl ValueEnum for CliHowClassesAreWrapped { +impl ValueEnum for CliClassWrapping { fn value_variants<'a>() -> &'a [Self] { &[ - CliHowClassesAreWrapped(HowClassesAreWrapped::NoWrapping), - CliHowClassesAreWrapped(HowClassesAreWrapped::CommaSingleQuotes), - CliHowClassesAreWrapped(HowClassesAreWrapped::CommaDoubleQuotes), + CliClassWrapping(ClassWrapping::NoWrapping), + CliClassWrapping(ClassWrapping::CommaSingleQuotes), + CliClassWrapping(ClassWrapping::CommaDoubleQuotes), ] } @@ -146,10 +146,10 @@ fn get_custom_regex_from_cli(cli: &Cli) -> Result { } } -fn get_class_wrapping_from_cli(cli: &Cli) -> HowClassesAreWrapped { +fn get_class_wrapping_from_cli(cli: &Cli) -> ClassWrapping { match &cli.class_wrapping { Some(class_wrapping) => class_wrapping.0, - None => HowClassesAreWrapped::NoWrapping, + None => ClassWrapping::NoWrapping, } } diff --git a/rustywind-core/CHANGELOG.md b/rustywind-core/CHANGELOG.md index e3d8fef..8775102 100644 --- a/rustywind-core/CHANGELOG.md +++ b/rustywind-core/CHANGELOG.md @@ -2,6 +2,9 @@ ## [Unreleased] +- Changed `HowClassesAreWrapped` to `ClassWrapping` +- Fixed some clippy warnings + ## [0.2.0] - 2024-10-21 - Add options to handle wrapped classes to extend the set of use cases [#109](https://github.com/avencera/rustywind/pull/109), thanks [@dikkadev]](https://github.com/dikkadev]) diff --git a/rustywind-core/src/sorter.rs b/rustywind-core/src/sorter.rs index f3c3452..10e5436 100644 --- a/rustywind-core/src/sorter.rs +++ b/rustywind-core/src/sorter.rs @@ -31,29 +31,29 @@ impl Deref for FinderRegex { /// How individual classes are wrapped. #[derive(Debug, Clone, Copy)] -pub enum HowClassesAreWrapped { +pub enum ClassWrapping { NoWrapping, CommaSingleQuotes, CommaDoubleQuotes, } -impl Default for HowClassesAreWrapped { +impl Default for ClassWrapping { fn default() -> Self { Self::NoWrapping } } -impl HowClassesAreWrapped { +impl ClassWrapping { pub fn as_str(&self) -> &'static str { match self { - HowClassesAreWrapped::NoWrapping => "no-wrapping", - HowClassesAreWrapped::CommaSingleQuotes => "comma-single-quotes", - HowClassesAreWrapped::CommaDoubleQuotes => "comma-double-quotes", + ClassWrapping::NoWrapping => "no-wrapping", + ClassWrapping::CommaSingleQuotes => "comma-single-quotes", + ClassWrapping::CommaDoubleQuotes => "comma-double-quotes", } } } -impl> From for HowClassesAreWrapped { +impl> From for ClassWrapping { fn from(s: T) -> Self { match s.as_ref() { "no-wrapping" => Self::NoWrapping, @@ -88,7 +88,7 @@ pub struct Options { pub regex: FinderRegex, pub sorter: Sorter, pub allow_duplicates: bool, - pub class_wrapping: HowClassesAreWrapped, + pub class_wrapping: ClassWrapping, } /// Checks if the file contents have any classes. @@ -121,18 +121,15 @@ pub fn sort_classes(class_string: &str, options: &Options) -> String { rewrap_wrapped_classes(sorted, options.class_wrapping) } -fn unwrap_wrapped_classes<'a>( - class_string: &'a str, - wrapping: HowClassesAreWrapped, -) -> Vec<&'a str> { +fn unwrap_wrapped_classes(class_string: &str, wrapping: ClassWrapping) -> Vec<&str> { match wrapping { - HowClassesAreWrapped::NoWrapping => class_string.split_ascii_whitespace().collect(), - HowClassesAreWrapped::CommaSingleQuotes => class_string + ClassWrapping::NoWrapping => class_string.split_ascii_whitespace().collect(), + ClassWrapping::CommaSingleQuotes => class_string .split(',') .flat_map(|class| class.split_ascii_whitespace()) .map(|class| class.trim_matches('\'')) .collect(), - HowClassesAreWrapped::CommaDoubleQuotes => class_string + ClassWrapping::CommaDoubleQuotes => class_string .split(',') .flat_map(|class| class.split_ascii_whitespace()) .map(|class| class.trim_matches('"')) @@ -140,14 +137,14 @@ fn unwrap_wrapped_classes<'a>( } } -fn rewrap_wrapped_classes<'a>(classes: Vec<&'a str>, wrapping: HowClassesAreWrapped) -> String { +fn rewrap_wrapped_classes(classes: Vec<&str>, wrapping: ClassWrapping) -> String { match wrapping { - HowClassesAreWrapped::NoWrapping => classes.join(" "), - HowClassesAreWrapped::CommaSingleQuotes => classes + ClassWrapping::NoWrapping => classes.join(" "), + ClassWrapping::CommaSingleQuotes => classes .iter() .map(|class| format!("'{}'", class)) .join(", "), - HowClassesAreWrapped::CommaDoubleQuotes => classes + ClassWrapping::CommaDoubleQuotes => classes .iter() .map(|class| format!("\"{}\"", class)) .join(", "), @@ -244,7 +241,7 @@ mod tests { regex: FinderRegex::DefaultRegex, sorter: Sorter::DefaultSorter, allow_duplicates: false, - class_wrapping: HowClassesAreWrapped::NoWrapping, + class_wrapping: ClassWrapping::NoWrapping, }; // HAS_CLASSES -------------------------------------------------------------------------------- @@ -514,80 +511,72 @@ mod tests { // CLASS WRAPPING #[test_case( r#"flex-col inline flex"#, - HowClassesAreWrapped::NoWrapping, + ClassWrapping::NoWrapping, vec![r#"flex-col"#, r#"inline"#, r#"flex"#] ; "no wrapping" )] #[test_case( r#"'flex-col', 'inline', 'flex'"#, - HowClassesAreWrapped::CommaSingleQuotes, + ClassWrapping::CommaSingleQuotes, vec![r#"flex-col"#, r#"inline"#, r#"flex"#] ; "comma single quotes" )] #[test_case( r#""flex-col", "inline", "flex""#, - HowClassesAreWrapped::CommaDoubleQuotes, + ClassWrapping::CommaDoubleQuotes, vec![r#"flex-col"#, r#"inline"#, r#"flex"#] ; "comma double quotes" )] - fn test_unwrap_wrapped_classes<'a>( - input: &str, - wrapping: HowClassesAreWrapped, - output: Vec<&str>, - ) { + fn test_unwrap_wrapped_classes<'a>(input: &str, wrapping: ClassWrapping, output: Vec<&str>) { assert_eq!(unwrap_wrapped_classes(input, wrapping), output) } #[test_case( vec![r#"flex-col"#, r#"inline"#, r#"flex"#], - HowClassesAreWrapped::NoWrapping, + ClassWrapping::NoWrapping, r#"flex-col inline flex"# ; "no wrapping" )] #[test_case( vec![r#"flex-col"#, r#"inline"#, r#"flex"#], - HowClassesAreWrapped::CommaSingleQuotes, + ClassWrapping::CommaSingleQuotes, r#"'flex-col', 'inline', 'flex'"# ; "comma single quotes" )] #[test_case( vec![r#"flex-col"#, r#"inline"#, r#"flex"#], - HowClassesAreWrapped::CommaDoubleQuotes, + ClassWrapping::CommaDoubleQuotes, r#""flex-col", "inline", "flex""# ; "comma double quotes" )] - fn test_rewrap_wrapped_classes<'a>( - input: Vec<&'a str>, - wrapping: HowClassesAreWrapped, - output: &str, - ) { + fn test_rewrap_wrapped_classes<'a>(input: Vec<&'a str>, wrapping: ClassWrapping, output: &str) { assert_eq!(rewrap_wrapped_classes(input, wrapping), output) } #[test_case( None, - HowClassesAreWrapped::NoWrapping, + ClassWrapping::NoWrapping, r#"
"#, r#"
"# ; "normal HTML use case" )] #[test_case( Some(r#"(?:\[)([_a-zA-Z0-9\.,\-'"\s]+)(?:\])"#), - HowClassesAreWrapped::CommaSingleQuotes, + ClassWrapping::CommaSingleQuotes, r#"classes = ['flex-col', 'inline', 'flex']"#, r#"classes = ['inline', 'flex', 'flex-col']"# ; "array with single quotes" )] #[test_case( Some(r#"(?:\[)([_a-zA-Z0-9\.,\-'"\s]+)(?:\])"#), - HowClassesAreWrapped::CommaDoubleQuotes, + ClassWrapping::CommaDoubleQuotes, r#"classes = ["flex-col", "inline", "flex"]"#, r#"classes = ["inline", "flex", "flex-col"]"# ; "array with double quotes" )] fn test_unusual_use_cases( regex_overwrite: Option<&str>, - class_wrapping: HowClassesAreWrapped, + class_wrapping: ClassWrapping, input: &str, output: &str, ) { diff --git a/rustywind-vite/Cargo.toml b/rustywind-vite/Cargo.toml index 8086016..c1a9e3a 100644 --- a/rustywind-vite/Cargo.toml +++ b/rustywind-vite/Cargo.toml @@ -10,7 +10,8 @@ homepage.workspace = true repository.workspace = true [dependencies] -rustywind_core = { version = "0.2.1" } +rustywind_core = { path = "../rustywind-core" } +# rustywind_core = { version = "0.3" } # tls rustls = { version = "0.23", features = ["ring"], default-features = false }