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 uptry/catch one liners #143
Comments
This comment has been minimized.
This comment has been minimized.
julien-f
commented
May 21, 2015
|
I think it's because, try { result = parse(raw) } catch (err) { return cb(err) }
// or
try {
result = parse(raw)
} catch (err) {
return cb(err)
} |
This comment has been minimized.
This comment has been minimized.
|
Wow, fast reply! Having them on one line actually works, but it makes for very long lines so I'm not sure if I want to use that. Hmm, well we do allow the following if (false) return 123
else return 456But not with curly brackets: if (true) { return 123 }
else { return 456 }But with |
This comment has been minimized.
This comment has been minimized.
julien-f
commented
May 21, 2015
|
You can use the following, it's ugly but it should work: try { result = parse(raw)
} catch (err) { return cb(err) } |
This comment has been minimized.
This comment has been minimized.
|
Ugh, that is ugly :) I think I'll stick with the 4-line version for now. But I do propose that we have the rules be something that disallows anything after the That way the thing I originally wanted would work and that ugly hack wouldn't... I don't think there is any use case where you want to allow text after the curly bracket, unless when it's a one liner that closes on that line. |
This comment has been minimized.
This comment has been minimized.
julien-f
commented
May 29, 2015
|
standard is based on ESLint, therefore you will to find this rule in the set of existing ones or propose a new one there. |
This comment has been minimized.
This comment has been minimized.
|
Like @julien-f says, you should use: try { result = parse(raw) } catch (err) { return cb(err) }
// or
try {
result = parse(raw)
} catch (err) {
return cb(err)
}This is a result of our requiring "one true brace style", i.e. opening brace of a block must be on the same line. You can read more here: http://eslint.org/docs/rules/brace-style I agree that this try-catch case seems like it should be an exception. If you can get eslint to change it or add an option for this, I would merge it. But this isn't a bug in standard, so I'm going to close this issue for now. |
LinusU commentedMay 21, 2015
Isn't the following allowed? I'm getting a rather cryptic error message and since we do allow e.g.
ifone liners I figured it would be okay.