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.

Wrong indentation when formatting with eslint rule brace-style as stroustrup

See original GitHub issue

Versions:

  • prettier-eslint version: ^9.0.0
  • node version: 10.16.0
  • npm (or yarn) version: 6.10.1

Have you followed the debugging tips?

Yes

Relevant code or config

function test() {
    try {
        console.log('try');
    } catch (ex) {
        console.log(ex);
    }
}

.eslintrc

{
    "rules": {
        "brace-style": ["error", "stroustrup"]
    }
}

What I did:

prettier-eslint --write "*.js"

What happened:

Code was formatted this way:

function test() {
    try {
        console.log('try');
    }
 catch (ex) { //wrong indentation here
        console.log(ex);
    }
}

Reproduction repository:

Problem description:

No indentation on line 5. even if my code is properly indented and following ESLint rules properly, prettier will reformat it and screw up indentation.

Suggested solution:

Code should be formatted this way:

function test() {
    try {
        console.log('try');
    }
    catch (ex) {
        console.log(ex);
    }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:9
  • Comments:6

github_iconTop GitHub Comments

2reactions
github-actions[bot]commented, May 25, 2020

Stale issue

2reactions
alexseitsingercommented, Mar 7, 2020

It’s worth mentioning that I was able to resolve this issue by enabling @typescript-eslint/indent for TypeScript and indent for plain JavaScript.

Read more comments on GitHub >

github_iconTop Results From Across the Web

brace-style - ESLint - Pluggable JavaScript Linter
Brace style is closely related to indent style in programming and describes the placement of braces relative to their control statement and body....
Read more >
Nextjs: eslint rule doesn't affect auto-formatting - Stack Overflow
The good news is that I already learned that there's an eslint rule for this specific case: brace-style: "stroustrup".
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 >
tslint-eslint-rules - npm
These are rules designed to prevent you from making mistakes. They either prescribe a better way of doing something or help you avoid...
Read more >
eslint-plugin-base-style-config | Yarn - Package Manager
A Set of Essential ESLint rules for JS, TS and React. It's part of a Set of Essential Configuration Files for Backend/Frontend/Build code...
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