question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[prettierx] flexible block brace style

See original GitHub issue

Similar to --break-before-else option, please add an option for Stroustrup brace style. This would basically add breaks before certain statements, including else, catch, and finally. See ESLint’s Brace Style Documentation for examples.


From @brodybits (May 2021):

  • Looking at the eslint brace-style rule, I think it would be ideal to support the “Allman” as well as “Stroustrup” brace style.
  • For discussion if we should support configuration per statement type, as was proposed for non-block statements in PR #327
  • This may supersede the --break-before-else option from PR #224.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
shannonmoellercommented, Jun 1, 2020

The stoustrup style applies to more than if/else blocks. It applies to any set of inseparable blocks.

Input:

if (conditionA) {
  // ...
} else if (conditionB) {
  // ...
} else {
  // ...
}

try {
  // ...
} catch (error) {
  // ...
} finally {
  // ...
}

do {
  // ...
} while (condition);

switch (value) {
  case 'a': {
    // ...
    break;
  } case 'b': {
    // ...
    break;
  } default: {
    // ...
    break;
  }
}

Output:

if (conditionA) {
  // ...
}
else if (conditionB) {
  // ...
}
else {
  // ...
}

try {
  // ...
}
catch (error) {
  // ...
}
finally {
  // ...
}

do {
  // ...
}
while (condition);

switch (value) {
  case 'a': {
    // ...
    break;
  }
  case 'b': {
    // ...
    break;
  }
  default: {
    // ...
    break;
  }
}

Basically there should be at least one break after any } that closes a block statement.

4reactions
shannonmoellercommented, Jun 1, 2020

Should also respect comments:

// do this if we can
if (foo) {
  // ...
}
// otherwise do this
else {
  // ...
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

brodybits/prettierx: a less opinionated fork of Prettier ... - GitHub
prettierX - a less opinionated fork of Prettier. License: MIT npm. An unofficial fork of the Prettier code formatter, intended to provide some...
Read more >
Options - Prettier
If you want Prettier to force all prose blocks to be on a single line and rely on editor/viewer soft wrapping instead, you...
Read more >
Rules - JavaScript Standard Style
Keep else statements on the same line as their curly braces. eslint: brace-style // ✓ ok if (condition) { // . ... Add...
Read more >
prettierx | Yarn - Package Manager
prettierX - a less opinionated fork of the Prettier code formatter ... (with some prettierX language-js updates now based on Prettier 2.3.2).
Read more >
Removing new lines before empty blocks in Eclipse
As far as I can tell this is not (yet) possible in eclipse; you can specify when new lines should be inserted or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found