-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: require brackets for conditional statements #49
Conversation
8a24db3
to
9d75255
Compare
@@ -13,5 +13,6 @@ module.exports = { | |||
rules: { | |||
eqeqeq: "error", | |||
"prefer-const": "error", | |||
curly: "error", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would vote for ["error", "multi-line", "consistent"]. Some simple short lines look straightforward to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to lean towards explicit brackets for conditionals, for a couple reasons:
It provides consistency everywhere, where you don't have to think about how to write an if statement (an if statement will always have opening and closing brackets)
It provides a somewhat cleaner git history. For example, if I write code like...
if (someCheck) return value;
and you update the code to...
if (someCheck) {
const calculatedValue = value + 1;
return calculatedValue;
}
then it appears that you were responsible for defining someCheck
(because you edited that line of code). So if a future dev has a question about someCheck
, they might be more likely to reach out to you, although I was the one responsible for the original code. It's a super nitpicky edge case, though.
Also, I just find something like this kind of gross (but valid with w/ ["error", "multi-line", "consistent"]
):
let sum = 0;
while (item.next()) sum += item.value;
I'd love to get other people's feedback on this one. I could definitely be over thinking it 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I agree with you now:) Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed with @scnwwu. Looks good here
9d75255
to
bf9abc6
Compare
Summary
This adds the
curly
rule to enforce consistency around conditional statements.Testing
yarn lint && yarn format
succeeded