beautifier / beautifier/js-beautify
Allow comment of a "else[ if]" block to be dedented
- Dominant language
- JavaScript
- Stars
- 9k
- Forks
- 1.4k
- PR merge metrics
- No merged PRs in 30d
Description
# Description
When writing `if...else` block with 1TBS style, it's hard to comment the `else` (or `else if`) comment as the comment for the `else` block is indented at the same level than the `if` block content.
# Input
The code looked like this before beautification:
```
// In this case
if (foo) {
// Do something
// Else do something else
} else {
// Do something else
}
```
# Expected Output
The code should have looked like this after beautification:
```
if (foo) {
// Do something
// Else do something else
} else {
// Do something else
}
```
# Actual Output
The code actually looked like this after beautification:
```
if (foo) {
// Do something
// Else do something else
} else {
// Do something else
}
```
## Environment
OS: Linux Mint 17
## Settings
```json
{
"indent_size": 4,
"indent_char": " ",
"eol": "\n",
"indent_level": 0,
"indent_with_tabs": false,
"preserve_newlines": true,
"max_preserve_newlines": 5,
"jslint_happy": false,
"space_after_anon_function": false,
"brace_style": "collapse-preserve-inline",
"keep_array_indentation": true,
"keep_function_indentation": true,
"space_before_conditional": true,
"break_chained_methods": false,
"eval_code": false,
"unescape_strings": false,
"wrap_line_length": 130,
"wrap_attributes": "auto",
"wrap_attributes_indent_size": 4,
"end_with_newline": true,
"operator_position": "before-newline"
}
```
Contributor guide
Research direction
Start by running js-beautify with the JavaScript input and settings shown in the issue, then compare the actual and expected indentation around the else comment. Done means the comment before an else or else-if block is dedented as shown while the surrounding block formatting remains unchanged; add or update a regression test for this example if the test location can be identified.
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