apache / apache/netbeans

JS wrong format indentation in switch nested in switch default

Open
#7,243 0 comments 0 reactions 0 assignees View on GitHub
kind:bug needs:triage
Dominant language
Java
Stars
3.1k
Forks
935
Avg merge
2d 3h
Merged PRs (30d)
17

Description

### Apache NetBeans version

Apache NetBeans 21

### What happened

In code like this
```
let a, b;
switch(a){
case 0:
//stuff
break;
case 1:
//stuff
break;
default:
switch(b){
case 0:
//stuff
break;
}
}
```
formatting with ALT+Shift+F the code is formatted you see above with the second switch at the same level of "default". A workaround is to add something else before between default and switch. Unfortunately cannot be a comment because it has the same problem. Must be code, e.g. a useless "let c;" will do.

```
let a, b;
switch(a){
case 0:
//stuff
break;
case 1:
//stuff
break;
default:
let c;
switch(b){
case 0:
//stuff
break;
}
}```

### Language / Project Type / NetBeans Component

PHP project

### How to reproduce

Open a PHP project then add a JS file and try the above code.

### Did this work correctly in an earlier version?

No / Don't know

### Operating System

Debian Bookworm (12)

### JDK

Java: 17.0.10; OpenJDK 64-Bit Server VM 17.0.10+7-Debian-1deb12u1 Runtime: OpenJDK Runtime Environment 17.0.10+7-Debian-1deb12u1

### Apache NetBeans packaging

Apache NetBeans binary zip

### Anything else

_No response_

### Are you willing to submit a pull request?

No

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue by opening a PHP project, adding a JavaScript file, and formatting the nested-switch example with Alt+Shift+F. The fix is done when a switch directly under a default clause is indented as shown in the workaround without requiring an extra statement, while the surrounding switch cases remain correctly formatted.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.