JavaScript: Fix inconsistent indentation in switch statement (#6514)
* Add "SwitchStatement" to isInsideParenthesis * Change tests * Add tests * Update CHANGELOG.unreleased.md * Add pr number and linkmaster
parent
c5c8862333
commit
2e2368f5d7
|
@ -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
|
[#5910]: https://github.com/prettier/prettier/pull/5910
|
||||||
[#6186]: https://github.com/prettier/prettier/pull/6186
|
[#6186]: https://github.com/prettier/prettier/pull/6186
|
||||||
[#6206]: https://github.com/prettier/prettier/pull/6206
|
[#6206]: https://github.com/prettier/prettier/pull/6206
|
||||||
|
@ -648,6 +685,7 @@ return (
|
||||||
[#6441]: https://github.com/prettier/prettier/pull/6441
|
[#6441]: https://github.com/prettier/prettier/pull/6441
|
||||||
[#6446]: https://github.com/prettier/prettier/pull/6446
|
[#6446]: https://github.com/prettier/prettier/pull/6446
|
||||||
[#6506]: https://github.com/prettier/prettier/pull/6506
|
[#6506]: https://github.com/prettier/prettier/pull/6506
|
||||||
|
[#6514]: https://github.com/prettier/prettier/pull/6514
|
||||||
[@duailibe]: https://github.com/duailibe
|
[@duailibe]: https://github.com/duailibe
|
||||||
[@gavinjoyce]: https://github.com/gavinjoyce
|
[@gavinjoyce]: https://github.com/gavinjoyce
|
||||||
[@sosukesuzuki]: https://github.com/sosukesuzuki
|
[@sosukesuzuki]: https://github.com/sosukesuzuki
|
||||||
|
|
|
@ -544,6 +544,7 @@ function printPathNoParens(path, options, print, args) {
|
||||||
n !== parent.body &&
|
n !== parent.body &&
|
||||||
(parent.type === "IfStatement" ||
|
(parent.type === "IfStatement" ||
|
||||||
parent.type === "WhileStatement" ||
|
parent.type === "WhileStatement" ||
|
||||||
|
parent.type === "SwitchStatement" ||
|
||||||
parent.type === "DoWhileStatement");
|
parent.type === "DoWhileStatement");
|
||||||
|
|
||||||
const parts = printBinaryishExpressions(
|
const parts = printBinaryishExpressions(
|
||||||
|
|
|
@ -288,6 +288,12 @@ switch (veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVery
|
||||||
alert( 'default' );
|
alert( 'default' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch ($veryLongAndVeryVerboseVariableName && $anotherVeryLongAndVeryVerboseVariableName) {
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($longButSlightlyShorterVariableName && $anotherSlightlyShorterVariableName) {
|
||||||
|
}
|
||||||
|
|
||||||
=====================================output=====================================
|
=====================================output=====================================
|
||||||
switch (a) {
|
switch (a) {
|
||||||
case 3:
|
case 3:
|
||||||
|
@ -315,7 +321,7 @@ switch (
|
||||||
|
|
||||||
switch (
|
switch (
|
||||||
veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong >
|
veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong >
|
||||||
veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong
|
veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong
|
||||||
) {
|
) {
|
||||||
case 3:
|
case 3:
|
||||||
alert("3");
|
alert("3");
|
||||||
|
@ -324,5 +330,17 @@ switch (
|
||||||
alert("default");
|
alert("default");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (
|
||||||
|
$veryLongAndVeryVerboseVariableName &&
|
||||||
|
$anotherVeryLongAndVeryVerboseVariableName
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (
|
||||||
|
$longButSlightlyShorterVariableName &&
|
||||||
|
$anotherSlightlyShorterVariableName
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -27,3 +27,9 @@ switch (veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVery
|
||||||
default:
|
default:
|
||||||
alert( 'default' );
|
alert( 'default' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch ($veryLongAndVeryVerboseVariableName && $anotherVeryLongAndVeryVerboseVariableName) {
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($longButSlightlyShorterVariableName && $anotherSlightlyShorterVariableName) {
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue