Skip to content

Commit

Permalink
Removeitertools dependency, make unique more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenperera committed Jan 19, 2025
1 parent 587d541 commit a0e70c2
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 29 deletions.
25 changes: 12 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ repository = "https://github.com/avencera/rustywind"

[workspace.dependencies]
once_cell = "1.20"
regex = "1.11"
itertools = "0.13"

# hashmap
ahash = "0.8"
Expand All @@ -26,6 +24,10 @@ color-eyre = "0.6"
env_logger = "0.11"
log = "0.4"

# regex
regex = "1.11"


[profile.release]
codegen-units = 1
lto = "fat"
Expand Down
3 changes: 0 additions & 3 deletions rustywind-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ rustywind_vite = { path = "../rustywind-vite" }
# rustywind_core = { version = "0.3" }
# rustywind_vite = { version = "0.3" }

# iter
itertools = { workspace = true }

# utils
regex = { workspace = true }
once_cell = { workspace = true }
Expand Down
2 changes: 0 additions & 2 deletions rustywind-cli/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use clap::ValueEnum;
use color_eyre::Help;
use eyre::{Context, Result};
use ignore::WalkBuilder;
use itertools::Itertools;
use regex::Regex;
use rustywind_core::class_wrapping::ClassWrapping;
use rustywind_core::RustyWind;
Expand Down Expand Up @@ -183,7 +182,6 @@ fn get_search_paths_from_starting_paths(starting_paths: &[PathBuf]) -> Vec<PathB
.filter(|f| f.path().is_file())
.map(|file| file.path().to_owned())
})
.unique()
.collect()
}

Expand Down
6 changes: 6 additions & 0 deletions rustywind-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]

### Refactor

- Completely refactored the public API, now all the functionality is in the `RustyWind` struct

### Changed

- Changed `HowClassesAreWrapped` to `ClassWrapping`
- Fixed some clippy warnings
- Implemented `Default` for `Options`
Expand Down
6 changes: 3 additions & 3 deletions rustywind-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rustywind_core"
version = "0.2.1"
version = "0.3.0"
description = "A library for sorting tailwind CSS classes"
documentation = "https://docs.rs/rustywind_core"
authors.workspace = true
Expand All @@ -10,14 +10,14 @@ homepage.workspace = true
repository.workspace = true

[dependencies]
itertools = { workspace = true }
once_cell = { workspace = true }
regex = { workspace = true }
ahash = { workspace = true }
eyre = { workspace = true }

# string matching
# parsing
aho-corasick = "1.0"
winnow = { version = "0.6", features = ["simd"] }

[dev-dependencies]
pretty_assertions = "1.4"
Expand Down
13 changes: 7 additions & 6 deletions rustywind-core/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::{
};
use ahash::AHashMap as HashMap;
use aho_corasick::{Anchored, Input};
use itertools::Itertools as _;
use regex::Captures;

/// The options to pass to the sorter.
Expand Down Expand Up @@ -64,11 +63,11 @@ impl RustyWind {
pub fn sort_classes(&self, class_string: &str) -> String {
let extracted_classes = self.unwrap_wrapped_classes(class_string);

let sorted = if self.allow_duplicates {
self.sort_classes_vec(extracted_classes.into_iter())
} else {
self.sort_classes_vec(extracted_classes.into_iter().unique())
};
let mut sorted = self.sort_classes_vec(extracted_classes.into_iter());

if !self.allow_duplicates {
sorted.dedup();
}

self.rewrap_wrapped_classes(sorted)
}
Expand All @@ -95,10 +94,12 @@ impl RustyWind {
ClassWrapping::CommaSingleQuotes => classes
.iter()
.map(|class| format!("'{}'", class))
.collect::<Vec<String>>()
.join(", "),
ClassWrapping::CommaDoubleQuotes => classes
.iter()
.map(|class| format!("\"{}\"", class))
.collect::<Vec<String>>()
.join(", "),
}
}
Expand Down
33 changes: 33 additions & 0 deletions rustywind-core/src/parser/css.rs
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
use eyre::Result;

fn parse_apply_classes(_css_file: &str) -> Result<Vec<&str>> {

Check failure on line 3 in rustywind-core/src/parser/css.rs

View workflow job for this annotation

GitHub Actions / clippy

function `parse_apply_classes` is never used

error: function `parse_apply_classes` is never used --> rustywind-core/src/parser/css.rs:3:4 | 3 | fn parse_apply_classes(_css_file: &str) -> Result<Vec<&str>> { | ^^^^^^^^^^^^^^^^^^^ | = note: `-D dead-code` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(dead_code)]`

Check failure on line 3 in rustywind-core/src/parser/css.rs

View workflow job for this annotation

GitHub Actions / macos (stable, x86_64-apple-darwin)

function `parse_apply_classes` is never used
todo!()
}

#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
use test_case::test_case;

#[test_case(
"@apply w-full opacity-0;",
vec!["w-full", "opacity-0"] ;
"basic apply directive"
)]
#[test_case(
"@apply flex items-center;\nheight: 60px;\n@apply bg-gray-100;",
vec!["flex", "items-center", "bg-gray-100"] ;
"mixed content with multiple applies"
)]
#[test_case(
"/* Header styles */\n@apply text-lg font-bold;",
vec!["text-lg", "font-bold"] ;
"with comments"
)]
#[test_case( "@apply;", vec![] ; "empty apply")]
fn test_extract_apply_classes(input: &str, output: Vec<&str>) {
let classes = parse_apply_classes(input);
assert!(classes.is_ok());
assert_eq!(classes.unwrap(), output);
}
}

0 comments on commit a0e70c2

Please sign in to comment.