Skip to content

Commit

Permalink
Stop inserting space in LESS variable property access
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Jan 3, 2023
1 parent 41cee06 commit 70f97d3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
17 changes: 17 additions & 0 deletions changelog_unreleased/less/14103.md
@@ -0,0 +1,17 @@
#### Do not insert space in LESS property access (#14034 by @mvorisek)

<!-- prettier-ignore -->
```less
// Input
a {
color: @colors[@white];
}

// Prettier stable
a {
color: @colors[ @white];
}

// Prettier main
<Same as input>
```
16 changes: 15 additions & 1 deletion src/language-css/printer-postcss.js
Expand Up @@ -620,7 +620,21 @@ function genericPrint(path, options, print) {
}

// Ignore `@` in Less (i.e. `@@var;`)
if (iNode.type === "value-atword" && iNode.value === "") {
if (
iNode.type === "value-atword" &&
(iNode.value === "" ||
/*
@var[ @notVarNested ][notVar]
^^^^
*/
iNode.value.endsWith("[") ||
/*
@var[ @notVarNested ][notVar]
^^^^^^^^^
*/
(iNextNode?.type === "value-word" &&
iNextNode.value.startsWith("]")))
) {
continue;
}

Expand Down
10 changes: 5 additions & 5 deletions tests/format/less/case/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -453,11 +453,11 @@ printWidth: 80
};
@not-var {
canchangecase: @var[ @notVarNested][notVar];
canchangecase: @var[ @notVarNested][notVar];
canchangecase: @var[ @notVarNested ][notVar];
canchangecase: @var[ @notVarNested][ notVar];
canchangecase: @var[ @notVarNested][notVar ];
canchangecase: @var[@notVarNested][notVar];
canchangecase: @var[@notVarNested][notVar];
canchangecase: @var[@notVarNested][notVar];
canchangecase: @var[@notVarNested][notVar];
canchangecase: @var[@notVarNested][notVar];
canchangecase: @var[notVar];
}
Expand Down

0 comments on commit 70f97d3

Please sign in to comment.