Skip to content

Commit

Permalink
Merge pull request #41 from ony3000/allman-switch-case
Browse files Browse the repository at this point in the history
When `braceStyle` is `allman`, the opening brace of a switch statement case block also breaks into new lines.
  • Loading branch information
ony3000 authored Aug 16, 2024
2 parents c2bc774 + c2de6f2 commit 870302c
Show file tree
Hide file tree
Showing 29 changed files with 242 additions and 122 deletions.
4 changes: 2 additions & 2 deletions src/packages/core-parts/finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function findTargetBraceNodes(ast: any): BraceNode[] {
nonCommentNodes.push(currentASTNode);

braceNodes.push({
type: parentNode?.type === 'SwitchCase' ? BraceType.OBNT : BraceType.OB,
type: BraceType.OB,
range: [currentNodeRangeStart, currentNodeRangeStart + 1],
});
braceNodes.push({
Expand Down Expand Up @@ -907,7 +907,7 @@ export function findTargetBraceNodesForSvelte(ast: any): BraceNode[] {
nonCommentNodes.push(currentASTNode);

braceNodes.push({
type: parentNode?.type === 'SwitchCase' ? BraceType.OBNT : BraceType.OB,
type: BraceType.OB,
range: [currentNodeRangeStart, currentNodeRangeStart + 1],
});
braceNodes.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,14 @@ exports[`switch (2) - case with block 1`] = `
"<script lang="ts">
switch (action)
{
case "say_hello": {
case "say_hello":
{
}
case "say_hi": {
case "say_hi":
{
}
default: {
default:
{
}
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ exports[`switch (2) - case with block 1`] = `
"<script lang="ts">
switch (action)
{
case "say_hello": {
case "say_hello":
{
const message = "hello";
console.log(message);
break;
}
case "say_hi": {
case "say_hi":
{
const message = "hi";
console.log(message);
break;
}
default: {
default:
{
console.log("Empty action received.");
}
}
Expand Down
18 changes: 12 additions & 6 deletions tests/v2-test/astro/issue-25/allman.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,23 +296,29 @@ switch (action) {
output: `---
switch (action)
{
case "say_hello": {
case "say_hello":
{
}
case "say_hi": {
case "say_hi":
{
}
default: {
default:
{
}
}
---
<script>
switch (action)
{
case "say_hello": {
case "say_hello":
{
}
case "say_hi": {
case "say_hi":
{
}
default: {
default:
{
}
}
</script>
Expand Down
18 changes: 12 additions & 6 deletions tests/v2-test/astro/switch/allman.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,20 @@ switch (action) {
output: `---
switch (action)
{
case "say_hello": {
case "say_hello":
{
const message = "hello";
console.log(message);
break;
}
case "say_hi": {
case "say_hi":
{
const message = "hi";
console.log(message);
break;
}
default: {
default:
{
console.log("Empty action received.");
}
}
Expand All @@ -137,17 +140,20 @@ switch (action)
<script>
switch (action)
{
case "say_hello": {
case "say_hello":
{
const message = "hello";
console.log(message);
break;
}
case "say_hi": {
case "say_hi":
{
const message = "hi";
console.log(message);
break;
}
default: {
default:
{
console.log("Empty action received.");
}
}
Expand Down
9 changes: 6 additions & 3 deletions tests/v2-test/babel/issue-25/allman.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,14 @@ switch (action) {
`,
output: `switch (action)
{
case "say_hello": {
case "say_hello":
{
}
case "say_hi": {
case "say_hi":
{
}
default: {
default:
{
}
}
`,
Expand Down
9 changes: 6 additions & 3 deletions tests/v2-test/babel/switch/allman.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,20 @@ switch (action) {
`,
output: `switch (action)
{
case "say_hello": {
case "say_hello":
{
const message = "hello";
console.log(message);
break;
}
case "say_hi": {
case "say_hi":
{
const message = "hi";
console.log(message);
break;
}
default: {
default:
{
console.log("Empty action received.");
}
}
Expand Down
9 changes: 6 additions & 3 deletions tests/v2-test/html/issue-25/__snapshots__/allman.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,14 @@ exports[`switch (2) - case with block 1`] = `
"<script lang="ts">
switch (action)
{
case "say_hello": {
case "say_hello":
{
}
case "say_hi": {
case "say_hi":
{
}
default: {
default:
{
}
}
</script>
Expand Down
9 changes: 6 additions & 3 deletions tests/v2-test/html/switch/__snapshots__/allman.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ exports[`switch (2) - case with block 1`] = `
"<script lang="ts">
switch (action)
{
case "say_hello": {
case "say_hello":
{
const message = "hello";
console.log(message);
break;
}
case "say_hi": {
case "say_hi":
{
const message = "hi";
console.log(message);
break;
}
default: {
default:
{
console.log("Empty action received.");
}
}
Expand Down
18 changes: 12 additions & 6 deletions tests/v2-test/svelte/issue-25/__snapshots__/allman.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,14 @@ exports[`switch (2) - case with block 1`] = `
"<script lang="ts">
switch (action)
{
case "say_hello": {
case "say_hello":
{
}
case "say_hi": {
case "say_hi":
{
}
default: {
default:
{
}
}
</script>
Expand All @@ -263,11 +266,14 @@ exports[`switch (2) - case with block 1`] = `
{
switch (action)
{
case "say_hello": {
case "say_hello":
{
}
case "say_hi": {
case "say_hi":
{
}
default: {
default:
{
}
}
}}
Expand Down
18 changes: 12 additions & 6 deletions tests/v2-test/svelte/switch/__snapshots__/allman.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,20 @@ exports[`switch (2) - case with block 1`] = `
"<script lang="ts">
switch (action)
{
case "say_hello": {
case "say_hello":
{
const message = "hello";
console.log(message);
break;
}
case "say_hi": {
case "say_hi":
{
const message = "hi";
console.log(message);
break;
}
default: {
default:
{
console.log("Empty action received.");
}
}
Expand All @@ -68,17 +71,20 @@ exports[`switch (2) - case with block 1`] = `
{
switch (action)
{
case "say_hello": {
case "say_hello":
{
const message = "hello";
console.log(message);
break;
}
case "say_hi": {
case "say_hi":
{
const message = "hi";
console.log(message);
break;
}
default: {
default:
{
console.log("Empty action received.");
}
}
Expand Down
9 changes: 6 additions & 3 deletions tests/v2-test/typescript/issue-25/allman.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,14 @@ switch (action) {
`,
output: `switch (action)
{
case "say_hello": {
case "say_hello":
{
}
case "say_hi": {
case "say_hi":
{
}
default: {
default:
{
}
}
`,
Expand Down
9 changes: 6 additions & 3 deletions tests/v2-test/typescript/switch/allman.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,20 @@ switch (action) {
`,
output: `switch (action)
{
case "say_hello": {
case "say_hello":
{
const message = "hello";
console.log(message);
break;
}
case "say_hi": {
case "say_hi":
{
const message = "hi";
console.log(message);
break;
}
default: {
default:
{
console.log("Empty action received.");
}
}
Expand Down
18 changes: 12 additions & 6 deletions tests/v2-test/vue/issue-25/allman.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,14 @@ switch (action) {
output: `<script setup lang="ts">
switch (action)
{
case "say_hello": {
case "say_hello":
{
}
case "say_hi": {
case "say_hi":
{
}
default: {
default:
{
}
}
</script>
Expand All @@ -456,11 +459,14 @@ switch (action)
{
switch (action)
{
case 'say_hello': {
case 'say_hello':
{
}
case 'say_hi': {
case 'say_hi':
{
}
default: {
default:
{
}
}
}
Expand Down
Loading

0 comments on commit 870302c

Please sign in to comment.