-
-
Notifications
You must be signed in to change notification settings - Fork 964
feat(css): add support for SCSS @function and @return at-rules
#9431
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
724717e
feat(css): add support for SCSS `@function` and `@return` at-rules
denbezrukov 0662098
feat(css): simplify parsing of SCSS parameter default values and vari…
denbezrukov a346113
[autofix.ci] apply automated fixes
autofix-ci[bot] 0566077
accept snapshots
denbezrukov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
29 changes: 29 additions & 0 deletions
29
crates/biome_css_formatter/src/scss/statements/function_at_rule.rs
This file contains hidden or 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,29 @@ | ||
| use crate::prelude::*; | ||
| use biome_css_syntax::{ScssFunctionAtRule, ScssFunctionAtRuleFields}; | ||
| use biome_formatter::write; | ||
|
|
||
| #[derive(Debug, Clone, Default)] | ||
| pub(crate) struct FormatScssFunctionAtRule; | ||
|
|
||
| impl FormatNodeRule<ScssFunctionAtRule> for FormatScssFunctionAtRule { | ||
| fn fmt_fields(&self, node: &ScssFunctionAtRule, f: &mut CssFormatter) -> FormatResult<()> { | ||
| let ScssFunctionAtRuleFields { | ||
| function_token, | ||
| name, | ||
| parameters, | ||
| block, | ||
| } = node.as_fields(); | ||
|
|
||
| write!( | ||
| f, | ||
| [ | ||
| function_token.format(), | ||
| space(), | ||
| name.format(), | ||
| parameters.format(), | ||
| space(), | ||
| block.format() | ||
| ] | ||
| ) | ||
| } | ||
| } | ||
This file contains hidden or 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
26 changes: 26 additions & 0 deletions
26
crates/biome_css_formatter/src/scss/statements/return_at_rule.rs
This file contains hidden or 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,26 @@ | ||
| use crate::prelude::*; | ||
| use biome_css_syntax::{ScssReturnAtRule, ScssReturnAtRuleFields}; | ||
| use biome_formatter::write; | ||
|
|
||
| #[derive(Debug, Clone, Default)] | ||
| pub(crate) struct FormatScssReturnAtRule; | ||
|
|
||
| impl FormatNodeRule<ScssReturnAtRule> for FormatScssReturnAtRule { | ||
| fn fmt_fields(&self, node: &ScssReturnAtRule, f: &mut CssFormatter) -> FormatResult<()> { | ||
| let ScssReturnAtRuleFields { | ||
| return_token, | ||
| value, | ||
| semicolon_token, | ||
| } = node.as_fields(); | ||
|
|
||
| write!( | ||
| f, | ||
| [ | ||
| return_token.format(), | ||
| space(), | ||
| value.format(), | ||
| semicolon_token.format() | ||
| ] | ||
| ) | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
crates/biome_css_formatter/tests/specs/css/scss/at-rule/function.scss
This file contains hidden or 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,9 @@ | ||
| @function | ||
| double( | ||
| $value:2, | ||
| $ratio: 1.5, | ||
| $rest... | ||
| ){ | ||
| @return | ||
| $value * $ratio; | ||
| } |
42 changes: 42 additions & 0 deletions
42
crates/biome_css_formatter/tests/specs/css/scss/at-rule/function.scss.snap
This file contains hidden or 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,42 @@ | ||
| --- | ||
| source: crates/biome_formatter_test/src/snapshot_builder.rs | ||
| info: css/scss/at-rule/function.scss | ||
| --- | ||
|
|
||
| # Input | ||
|
|
||
| ```scss | ||
| @function | ||
| double( | ||
| $value:2, | ||
| $ratio: 1.5, | ||
| $rest... | ||
| ){ | ||
| @return | ||
| $value * $ratio; | ||
| } | ||
|
|
||
| ``` | ||
|
|
||
|
|
||
| ============================= | ||
|
|
||
| # Outputs | ||
|
|
||
| ## Output 1 | ||
|
|
||
| ----- | ||
| Indent style: Tab | ||
| Indent width: 2 | ||
| Line ending: LF | ||
| Line width: 80 | ||
| Quote style: Double Quotes | ||
| Trailing newline: true | ||
| ----- | ||
|
|
||
| ```scss | ||
| @function double($value: 2, $ratio: 1.5, $rest...) { | ||
| @return $value * $ratio; | ||
| } | ||
|
|
||
| ``` |
2 changes: 2 additions & 0 deletions
2
crates/biome_css_formatter/tests/specs/css/scss/at-rule/return.scss
This file contains hidden or 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,2 @@ | ||
| @return | ||
| $width * 2 ; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.