Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
function-url-quotes
autofix (#6558)
Closes #6500. > Is there anything in the PR that needs further explanation? ~~Two possible code smells I want to call out. In both cases, I opted to pick a "dirty" solution that doesn't change existing behaviour and minimizes/localizes the changed code. However, there are probably more correct/elegant ways to do this. Advice is welcome!~~ I was able to address these thanks to code review, but I'll leave the comments for posterity. --- First, this rule operates on both declarations and at-rules. It seems like in `checkArgs`, this type information is "erased". To resolve this, I have my utility functions `addQuotes` and `removeQuotes` take in a union type, and then use a crude `'params' in node` to differentiate the type. This ... feels wrong? I was a bit unsure if there's a better way for me to do this (either from a TS perspective, or perhaps a Stylelint util that I'm missing). --- Secondly, the previous iteration of this rule lowercases declarations and at-rule parameters before passing them in as arguments to `functionArgumentsSearch`. This ensures that the rule matches `UrL` and the like. However, this has the side effect of lowercasing the declaration value and/or at-rule parameters. Then, when I apply the autofix, I propagate this lowercase change (which means that the autofix also inadvertently lowercases the code). To resolve this problem, I pass in a case-insensitive regex to `functionArgumentsSearch`. I don't think this is *technically* wrong, but it is likely a performance regression; I didn't want to change `functionArgumentsSearch` implementation instead. With that in mind, any suggestions on better ways to do this? Thanks in advance - implementing this autofix was trickier than I thought! Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
- Loading branch information
1 parent
b4fd2d5
commit 6c74739
Showing
7 changed files
with
136 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"stylelint": minor | ||
--- | ||
|
||
Added: `function-url-quotes` autofix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.