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.

Allow `brace-style` rule to enforce different styles on different block types

See original GitHub issue

What version of ESLint are you using? v3.1.0

What rule do you want to change? brace-style

I would like to enable different brace handling based on the type of block. For example, different handling for IfStatements vs FunctionDeclaration (and even FunctionExpression).

Ideally you would be able to use individual options to mimic the predefined formats (

  "brace-style": ["error", { "IfStatement": "new-line", "FunctionDeclaration": "new-line", "FunctionExpression": "same-line" }, { "noCuddledElse": true }]

BlocksSupported: FunctionDeclaration FunctionExpression ArrowFunctionExpression IfStatement TryStatement DoWhileStatement WhileStatement WithStatement ForStatement ForInStatement ForOfStatement SwitchStatement

Options: new-line - brace always starts on a new line same-line - brace always starts on same line ignore - rule does not apply

Additional options to support “stroustrup” style: noCuddledElse - else keywords start on own line noCuddledCatchFinally - catch/finally keywords start on own line

What code should be flagged as incorrect with this change?

With this enabled, the following would be an error:

function doSomething() 
  // function body

if (true) {
  // body
} else {


What happens when the rule is applied to this code now?

The brace variations do match the flexibility defined. I feel like i’m fighting with my tooling (VSCode) when using the brace-style rule and would like the possibility of adding additional properties for the rule to better fit within our preferred code formatting and development tooling.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:38 (23 by maintainers)

github_iconTop GitHub Comments

platinumazurecommented, Feb 24, 2017

@jrsearles Sorry for losing track of this, but where are we here? Have I missed your PR?

fatcerberuscommented, Mar 12, 2018

I really want to see this implemented too, as the current brace-style implementation is not nearly granular enough. My style is mostly Stroustrup, but for class, function and method declarations I use the Allman style with the braces on their own line. There’s no way to express this to ESLint so I’m currently forced to disable the brace-style rule entirely.

Read more comments on GitHub >

github_iconTop Results From Across the Web

brace-style - ESLint - Pluggable JavaScript Linter
Another style is called Allman, in which all the braces are expected to be on their own lines ... This rule enforces consistent...
Read more >
brace-style | typescript-eslint
Enforce consistent brace style for blocks.. Some problems reported by this rule are automatically fixable by the --fix ESLint command line option.
Read more >
Use preferred braces style (enforce braces in 'using' statement)
To see and configure these rules, open ReSharper options (ReSharper | Options), type braces in the search box, and check matched items on ......
Read more >
Artistic Style 3.1
Embedded statements that are multiple-line and are NOT in a C-type format, such as Python, are usually mal-formatted (a C-type format has blocks...
Read more >
Why does Golang enforce curly bracket to not be on the next ...
Lua has been using semicolons for code blocks and not requiring semicolons since before Go was even concieved. They could allow other brace ......
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 Post

No results found

github_iconTop Related Hashnode Post

No results found