JavaScript: Fix inconsistent indentation in switch statement (#6514)
* Add "SwitchStatement" to isInsideParenthesis * Change tests * Add tests * Update CHANGELOG.unreleased.md * Add pr number and link
This commit is contained in:
1 parent
c5c8862333
commit
2e2368f5d7
4 files changed
+64
-1
No files matched your search
@@ -626,6 +626,43 @@ return (
|
||||
);
|
||||
```
|
||||
|
||||
#### JavaScript: Fix inconsistent indentation in switch statement ([#6514] by [@sosukesuzuki])
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```js
|
||||
// Input
|
||||
switch ($veryLongAndVeryVerboseVariableName && $anotherVeryLongAndVeryVerboseVariableName) {
|
||||
}
|
||||
|
||||
switch ($longButSlightlyShorterVariableName && $anotherSlightlyShorterVariableName) {
|
||||
}
|
||||
|
||||
// Prettier (stable)
|
||||
switch (
|
||||
$veryLongAndVeryVerboseVariableName &&
|
||||
$anotherVeryLongAndVeryVerboseVariableName
|
||||
) {
|
||||
}
|
||||
|
||||
switch (
|
||||
$longButSlightlyShorterVariableName && $anotherSlightlyShorterVariableName
|
||||
) {
|
||||
}
|
||||
|
||||
// Prettier (master)
|
||||
switch (
|
||||
$veryLongAndVeryVerboseVariableName &&
|
||||
$anotherVeryLongAndVeryVerboseVariableName
|
||||
) {
|
||||
}
|
||||
|
||||
switch (
|
||||
$longButSlightlyShorterVariableName &&
|
||||
$anotherSlightlyShorterVariableName
|
||||
) {
|
||||
}
|
||||
```
|
||||
|
||||
[#5910]: https://github.com/prettier/prettier/pull/5910
|
||||
[#6186]: https://github.com/prettier/prettier/pull/6186
|
||||
[#6206]: https://github.com/prettier/prettier/pull/6206
|
||||
@@ -648,6 +685,7 @@ return (
|
||||
[#6441]: https://github.com/prettier/prettier/pull/6441
|
||||
[#6446]: https://github.com/prettier/prettier/pull/6446
|
||||
[#6506]: https://github.com/prettier/prettier/pull/6506
|
||||
[#6514]: https://github.com/prettier/prettier/pull/6514
|
||||
[@duailibe]: https://github.com/duailibe
|
||||
[@gavinjoyce]: https://github.com/gavinjoyce
|
||||
[@sosukesuzuki]: https://github.com/sosukesuzuki
|
||||
|
||||
@@ -544,6 +544,7 @@ function printPathNoParens(path, options, print, args) {
|
||||
n !== parent.body &&
|
||||
(parent.type === "IfStatement" ||
|
||||
parent.type === "WhileStatement" ||
|
||||
parent.type === "SwitchStatement" ||
|
||||
parent.type === "DoWhileStatement");
|
||||
|
||||
const parts = printBinaryishExpressions(
|
||||
|
||||
@@ -288,6 +288,12 @@ switch (veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVery
|
||||
alert( 'default' );
|
||||
}
|
||||
|
||||
switch ($veryLongAndVeryVerboseVariableName && $anotherVeryLongAndVeryVerboseVariableName) {
|
||||
}
|
||||
|
||||
switch ($longButSlightlyShorterVariableName && $anotherSlightlyShorterVariableName) {
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
switch (a) {
|
||||
case 3:
|
||||
@@ -315,7 +321,7 @@ switch (
|
||||
|
||||
switch (
|
||||
veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong >
|
||||
veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong
|
||||
veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong
|
||||
) {
|
||||
case 3:
|
||||
alert("3");
|
||||
@@ -324,5 +330,17 @@ switch (
|
||||
alert("default");
|
||||
}
|
||||
|
||||
switch (
|
||||
$veryLongAndVeryVerboseVariableName &&
|
||||
$anotherVeryLongAndVeryVerboseVariableName
|
||||
) {
|
||||
}
|
||||
|
||||
switch (
|
||||
$longButSlightlyShorterVariableName &&
|
||||
$anotherSlightlyShorterVariableName
|
||||
) {
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -27,3 +27,9 @@ switch (veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVery
|
||||
default:
|
||||
alert( 'default' );
|
||||
}
|
||||
|
||||
switch ($veryLongAndVeryVerboseVariableName && $anotherVeryLongAndVeryVerboseVariableName) {
|
||||
}
|
||||
|
||||
switch ($longButSlightlyShorterVariableName && $anotherSlightlyShorterVariableName) {
|
||||
}
|
||||
Reference in new issue
Block a user