File tree Expand file tree Collapse file tree
changelog_unreleased/scss
src/language-css/utilities
tests/format/scss/function Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #### Prevent trailing comma in ` if() ` function (#18471 by @kovsu )
2+
3+ <!-- prettier-ignore -->
4+ ``` scss
5+ // Input
6+ $value : if (sass (false ): 1 ; else: -1 );
7+
8+ // Prettier stable
9+ $value : if (
10+ sass (false ): 1 ; else: -1 ,
11+ );
12+
13+ // Prettier main
14+ $value : if (sass (false ): 1 ; else: -1 );
15+ ```
Original file line number Diff line number Diff line change @@ -261,6 +261,18 @@ function isSCSSMapItemNode(path, options) {
261261 return false ;
262262 }
263263
264+ const parentNode = path . parent ;
265+
266+ // Don't treat SCSS if function arguments as maps (`if(sass(condition): value; else: value)`)
267+ // https://sass-lang.com/documentation/breaking-changes/if-function/
268+ if (
269+ parentNode &&
270+ parentNode . type === "value-func" &&
271+ parentNode . value === "if"
272+ ) {
273+ return false ;
274+ }
275+
264276 const parentParentNode = path . grandparent ;
265277
266278 // Check open parens contain key/value pair (i.e. `(key: value)` and `(key: (value, other-value)`)
Original file line number Diff line number Diff line change 1+ $value : if (sass (false ): 1 ; else: -1 );
Original file line number Diff line number Diff line change @@ -210,6 +210,36 @@ div {
210210================================================================================
211211` ;
212212
213+ exports [` 18465.scss - { " trailingComma" :" es5" } format 1` ] = `
214+ ====================================options=====================================
215+ parsers: ["scss"]
216+ printWidth: 80
217+ trailingComma: "es5"
218+ | printWidth
219+ =====================================input======================================
220+ $value: if(sass(false): 1; else: -1);
221+
222+ =====================================output=====================================
223+ $value: if(sass(false): 1; else: -1);
224+
225+ ================================================================================
226+ ` ;
227+
228+ exports [` 18465.scss - { " trailingComma" :" none" } format 1` ] = `
229+ ====================================options=====================================
230+ parsers: ["scss"]
231+ printWidth: 80
232+ trailingComma: "none"
233+ | printWidth
234+ =====================================input======================================
235+ $value: if(sass(false): 1; else: -1);
236+
237+ =====================================output=====================================
238+ $value: if(sass(false): 1; else: -1);
239+
240+ ================================================================================
241+ ` ;
242+
213243exports [` arbitrary-arguments.scss - { " trailingComma" :" es5" } format 1` ] = `
214244====================================options=====================================
215245parsers: ["scss"]
You can’t perform that action at this time.
0 commit comments