Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upif statements: force brace or one-liner #16
Comments
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
I'm also |
This comment has been minimized.
This comment has been minimized.
kytwb
commented
Feb 23, 2015
if (condition) {
expression
} else {
more expressions
} |
This comment has been minimized.
This comment has been minimized.
|
There is now an If we add this rule to if (foo)
doSomething()
else
doSomethingElse()
while (foo
&& bar) baz()
if (foo) foo(
bar,
baz)It will not error for these patterns: if (foo) return; else doSomething()
if (foo) return
else if (bar) baz()
else doSomething()
do something()
while (foo)
if (foo) {
return
}
if (foo) { return }
while (true) {
doSomething()
doSomethingElse()
}This is definitely a breaking change (it causes many of the modules in |
This comment has been minimized.
This comment has been minimized.
|
Is this worth doing? cc @mafintosh @othiym23 |
This comment has been minimized.
This comment has been minimized.
|
I'm happy with the result of that rule. ACK from me.
|
This comment has been minimized.
This comment has been minimized.
othiym23
commented
Feb 26, 2015
|
@feross I'm in favor, but (to set error bars) I feel like I'm unusually particular about this rule. |
This comment has been minimized.
This comment has been minimized.
|
fwiw, I'm also in favor of this. |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
kytwb
commented
Feb 27, 2015
|
Isn't it too permissive? |
This comment has been minimized.
This comment has been minimized.
|
@kytwb what would you see changed? |
This comment has been minimized.
This comment has been minimized.
kytwb
commented
Feb 27, 2015
|
I'd reject those as well if (foo) return; else doSomething()
if (foo) return
else if (bar) baz()
else doSomething()
do something()
while (foo)
if (foo) { return }And force explicit blocks and braces while accepting same line chaining of else/else if/while with previous closing brace: if (foo) {
return;
} else {
doSomething()
}
if (foo) {
return
} else if (bar) {
baz()
} else {
doSomething()
}
do {
something()
} while (foo)
if (foo) {
return
} |
This comment has been minimized.
This comment has been minimized.
|
@kytwb I personally use |
This comment has been minimized.
This comment has been minimized.
|
@kytwb Most users of |
This comment has been minimized.
This comment has been minimized.
kytwb
commented
Mar 2, 2015
|
Fair enough. |
feross
added a commit
that referenced
this issue
Mar 7, 2015
This comment has been minimized.
This comment has been minimized.
|
This rule is added in
|
dcousens commentedJan 30, 2015
I find I have to double take when I look at this, to make sure I'm not mis-understanding what is actually part of the expressions that get executed.
The example is the following:
I think that is confusing and unnecessary, and IMHO it should only either be:
or
edit: Infact, I only ever use the shorthand one-liner for early-exit
returnstatements, but YMMV.@feross thoughts?