brace-style "allowSingleLine" should differentiate between if/else and function statements.
See original GitHub issueWhat version of ESLint are you using?
v2.2.0
What parser (default, Babel-ESLint, etc.) are you using?
Default.
Please show your full configuration:
"brace-style": [2, "1tbs", { "allowSingleLine": true }]
What did you do? Please include the actual source code causing the issue.
I have two snippets that eslint is (correctly) reporting. However, I’d like to disable half of the violations.
good, please continue flagging as an error
if (foo) { doFoo(); } else { doOther(); }
please allow me to disable errors for these statements
var o = { action: function () { doSomething(); } };
What did you expect to happen?
I expected "allowSingleLine"
to accept an object to expose more granularity in my config.
"brace-style": [2, "1tbs", { "allowSingleLine": { "ifStatements": false, "functions": true } }]
What actually happened? Please include the actual, raw output from ESLint.
I’m seeing the usual errors being reported. Nothing out of the ordinary.
error Statement inside of curly braces should be on next line brace-style
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Are methods and if/else statements functions? - Codecademy
I know this does not explain much, but it does show the more obvious differences. With exception of object literals, which use curly...
Read more >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 >demo-outil-edition - node_modules - eslint - CHANGELOG.md
39dfe08 Update: false positives in function-call-argument-newline (fixes ... 6cb63fd Update: Add iife to padding-line-between-statements ...
Read more >Are braces necessary in one-line statements in JavaScript?
No. But they are recommended. If you ever expand the statement you will need them. This is perfectly valid if (cond) alert("Condition met!...
Read more >Difference Between if else and Switch - Scaler Topics
The else statement can either be a single statement, or it can even be a block of statements. Syntax of if-else statement. if...
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
Thanks for your interest in improving eslint. Unfortunately, it looks like consensus couldn’t be reached on this issue and so I’m closing it. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach consensus after 21 days tend never to reach consensus, and as such, we close those issues. This doesn’t mean the idea isn’t interesting, just that it’s not something the team can commit to.
As a reminder, you can still create a custom rule for your use use.
I’d much rather revert all one-liner functions to multi-line to avoid that issue entirely. I would go mad trying to keep an entire team’s worth of contributions using both single line functions and this comment above them all!