nushell / nushell/nufmt

if-else should format to either single line or multiline

Open
#217 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Rust
Stars
230
Forks
40
Avg merge
15h 30m
Merged PRs (30d)
1

Description

Describe the bug

formatting an if-else statement where all blocks are considered "one-liners" formats the whole statement as a single line. (great!)

however if one of the blocks is considered a one-liner but others are not, it should abandon the strategy of keeping as single line. that's how other formatters deal with this.

this also applies to try-catch-finally. maybe other things as well.

Script or statement

if true { foo } else { bar | baz | qux }

Actual behavior/output

formats to

if true { foo } else {
     bar | baz | qux
}
Expected behavior/output
if true {
     foo
} else {
     bar | baz | qux
}
Environment

current github versions of nushell and nufmt

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided if true { foo } else { bar | baz | qux } statement using the current nufmt. Trace the formatter’s handling of mixed one-line and multiline blocks, then add a regression test covering if-else and, if applicable, try-catch-finally; done means mixed blocks consistently use multiline formatting.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.