Prevent trailing comma in SCSS if() function (#18471)
Co-authored-by: fisker Cheung <lionkay@gmail.com>
This commit is contained in:
1 parent
1cd40668c3
commit
177f908981
4 files changed
+58
No files matched your search
@@ -0,0 +1,15 @@
|
||||
#### Prevent trailing comma in `if()` function (#18471 by @kovsu)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```scss
|
||||
// Input
|
||||
$value: if(sass(false): 1; else: -1);
|
||||
|
||||
// Prettier stable
|
||||
$value: if(
|
||||
sass(false): 1; else: -1,
|
||||
);
|
||||
|
||||
// Prettier main
|
||||
$value: if(sass(false): 1; else: -1);
|
||||
```
|
||||
@@ -261,6 +261,18 @@ function isSCSSMapItemNode(path, options) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const parentNode = path.parent;
|
||||
|
||||
// Don't treat SCSS if function arguments as maps (`if(sass(condition): value; else: value)`)
|
||||
// https://sass-lang.com/documentation/breaking-changes/if-function/
|
||||
if (
|
||||
parentNode &&
|
||||
parentNode.type === "value-func" &&
|
||||
parentNode.value === "if"
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const parentParentNode = path.grandparent;
|
||||
|
||||
// Check open parens contain key/value pair (i.e. `(key: value)` and `(key: (value, other-value)`)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
$value: if(sass(false): 1; else: -1);
|
||||
@@ -210,6 +210,36 @@ div {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`18465.scss - {"trailingComma":"es5"} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["scss"]
|
||||
printWidth: 80
|
||||
trailingComma: "es5"
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
$value: if(sass(false): 1; else: -1);
|
||||
|
||||
=====================================output=====================================
|
||||
$value: if(sass(false): 1; else: -1);
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`18465.scss - {"trailingComma":"none"} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["scss"]
|
||||
printWidth: 80
|
||||
trailingComma: "none"
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
$value: if(sass(false): 1; else: -1);
|
||||
|
||||
=====================================output=====================================
|
||||
$value: if(sass(false): 1; else: -1);
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`arbitrary-arguments.scss - {"trailingComma":"es5"} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["scss"]
|
||||
|
||||
Reference in new issue
Block a user