-
-
Notifications
You must be signed in to change notification settings - Fork 929
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
Add support for multi-argument functions to function-calc-no-unspaced-operator
#7670
Conversation
|
lib/rules/function-calc-no-unspaced-operator/__tests__/index.mjs
Outdated
Show resolved
Hide resolved
If you can't make a benchmark, do you feel confident that your new approach is faster or at least as fast as the current one? |
This change:
Main :
These results match my expectations. |
Great. |
Thank you @Mouvedia for the feedback 🙇 |
I didn't check the code yet :) Feel free to switch from draft to ready if you want a proper review. |
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.
@romainmenke Thanks a lot! I feel this PR token-based approach is much better than the current character-based approach. 👍🏼
So, as @Mouvedia commented, can you fix the conflict and make this PR ready for review? Since this PR will be merged into PR #7655, I will hand over refactoring in #7655 after merging this PR.
Or, if you don't mind, I can take on this issue. |
@ybiquitous I've made a few more edits:
Feel free to take this! |
function-calc-no-unspaced-operator
false negatives (alternative approach)function-calc-no-unspaced-operator
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.
I did a first quick pass; nothing major.
This is well documented except for the token positions but that can't be helped.
e.g. token[4]
If a regression slipped by I couldn't tell but I think our test suite would catch it.
|
||
const afterOperator = operand.charAt(operatorIndex + 1); | ||
if ( |
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.
nit
Maybe add some const declarations?
e.g.
const bar = operation.secondOperand?.value[0];
const foo = bar === cssTokenizer.TokenType.Dimension || bar === cssTokenizer.TokenType.Percentage || bar === cssTokenizer.TokenType.Number;
Can you remove the stylelint/lib/reference/functions.mjs Line 29 in f87f784
|
I've made a few edits, but will defer to @ybiquitous now for the remainder of the work on this rule :) |
@romainmenke Thank you for your work! I'll take over this. 👍🏼 |
5dc44b2
into
function-calc-no-unspaced-operator-bugfix
Remember to change the author in the 16.X.0 changelog. |
Closes #7618
@ybiquitous This rule and the implementation was a lot more complex that I originally thought it would be. Doing pure code review was tricky for me and I needed to take a deep dive.
The code in this PR is a mess, but it also isn't intended to be used as is.
It can be used, we can continue work from this. But I haven't spend much time on self-review to get it into a really good state.
As I understand it know there are multiple issues and layers.
Steps:
10px-20px
->10px -20px
(px-20px
is the entire unit here)10px -20px
->10px -|20px
(|
to indicate that these are separate)10px -|20px
->10px - 20px
10px -\t20px
->10px - 20px
The csstools tokenizer and parsing packages have several aspects that help with some of these steps.
The tokenizer is just arrays, strings and numbers. So Step 1 can be handled purely on the token stream. It is a messy function, but it gives us more control and nice separation of concerns.
The parsing algorithm walker can be stateful. This is useful to keep track of being in a math context or not e.g.
calc((((10px+2px))))
In general I try to do as much work and analysis on the parsed values (e.g.
token[4].value
,token[4].unit
, ...) and as little as possible on the string representation (e.g.token[1]
,node.toString()
)My hope is that doing the same work from different angles is a good way to transfer some knowledge :)
Ref #7655