-
-
Notifications
You must be signed in to change notification settings - Fork 495
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
feat(linter): support class sorting for tw.div
#4699
base: main
Are you sure you want to change the base?
Conversation
CodSpeed Performance ReportMerging #4699 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution! Three things are missing in this PR:
- A new changelog line that explains the new feature
- Update the documentation, and explain the new feature. You should add something like
**Since v2.0.0**
- Update the documentation and add a new example with this new feature. The contribution guide explains how to do so
Also, one question: what was the reason for adding tw.*
not tw.div
?
pub(crate) fn match_function(&self, name: &str) -> bool { | ||
let matchers = self.functions.iter().flatten(); | ||
let parts = name.split('.'); | ||
for matcher in matchers { | ||
let mut matcher = matcher.split('.'); | ||
let mut parts = parts.clone(); | ||
|
||
let mut zip = matcher.by_ref().zip(parts.by_ref()); | ||
if zip.all(|(m, p)| m == "*" || m == p) | ||
&& matcher.next().is_none() | ||
&& parts.next().is_none() | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub(crate) fn match_function(&self, name: &str) -> bool { | |
let matchers = self.functions.iter().flatten(); | |
let parts = name.split('.'); | |
for matcher in matchers { | |
let mut matcher = matcher.split('.'); | |
let mut parts = parts.clone(); | |
let mut zip = matcher.by_ref().zip(parts.by_ref()); | |
if zip.all(|(m, p)| m == "*" || m == p) | |
&& matcher.next().is_none() | |
&& parts.next().is_none() | |
{ | |
return true; | |
} | |
} | |
false | |
} | |
pub(crate) fn match_function(&self, name: &str) -> bool { | |
self.functions.iter().flatten().any(|matcher| { | |
let mut matcher_parts = matcher.split('.'); | |
let mut name_parts = name.split('.').clone(); | |
let all_parts_match = matcher_parts | |
.by_ref() | |
.zip(name_parts.by_ref()) | |
.all(|(m, p)| m == "*" || m == p); | |
all_parts_match | |
&& matcher_parts.next().is_none() | |
&& name_parts.next().is_none() | |
}) | |
} |
uses .any() to replace the explicit loop and manual return true. the result is functionally equivalent, with the same time and space complexity.
I prepared some testcases and tested this on the playground, and the behavior matches the original implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for suggesting this!🥹
Committed without using redundant .clone()
! 2e70bca
- let mut name_parts = name.split('.').clone();
+ let mut name_parts = name.split('.');
@ematipico
This is for supporting tags other than |
Summary
This PR adds support for class sorting in the
tw.div
syntax, commonly used with libraries such as twin.macro and react-twc.To enable sorting for
tw.div
or similar patterns, need to include a configuration entry liketw.*
inoptions.functions
.Test Plan
useSortedClasses
tests to reflect the added support for thetw.div
syntax.