Wrong indentation when formatting with eslint rule brace-style as stroustrup
See original GitHub issueVersions:
prettier-eslint
version: ^9.0.0node
version: 10.16.0npm
(oryarn
) 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:
- Created 4 years ago
- Reactions:9
- Comments:6
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Stale issue
It’s worth mentioning that I was able to resolve this issue by enabling @typescript-eslint/indent for TypeScript and indent for plain JavaScript.