You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you guys have any conventions on when to use blank lines? I see in 18.8 it is specified that blocks should not be padded. That is this is bad:
// bad
function bar() {
console.log(foo);
}
But, does this apply also for classes? My preference in style has been heavily influenced by python and thus when I do not see a convention being used from airbnb I default to whatever I can apply from the python style guide.
The convention is to surround methods by 1 blank line and functions by 2. In this way when we do add another method to the class we do not see a git difference in which we added a new empty line. Instead we can see clearly that a new method was added. For functions I prefer the 2 blank lines since I am treating them as if it were a class. I think of them to be a little bit less related (as opposed to methods).
Lastly, this is something that I also failed to see in the style guide: exports. Usually if my module consists of many functions I prefer to scroll to the bottom to see what I am exporting. For this reason I only write 1 single export {} and export default. In this way if ever decide to export another item now I just add it to the list instead of making git give me a line change on the function. That is, instead of seeing
- function foo() {+ export function foo() {
now we have
export {
someVar,
+ foo,
}
What are your preferences and why? Could we have some section in the style guide pointing them out for future reference? I'll be happy following them as long as there is consistency.
The text was updated successfully, but these errors were encountered:
Yes, it applies to classes as well. We always avoid extra padding blank lines. function and class should be self-consistent when possible. Our linter config already prevents two blank lines from ever appearing consecutively, in any context. I'd be happy to accept a PR that documents this more clearly!
We don't currently have a preference for exports in the way you describe - however, we do have a preference for only exporting one thing. In other words, files should ideally only have one default export, and zero named exports. A PR to add a section about this is welcome as well.
Do you guys have any conventions on when to use blank lines? I see in 18.8 it is specified that blocks should not be padded. That is this is bad:
But, does this apply also for classes? My preference in style has been heavily influenced by python and thus when I do not see a convention being used from airbnb I default to whatever I can apply from the python style guide.
In particular I prefer to write like this:
The convention is to surround methods by 1 blank line and functions by 2. In this way when we do add another method to the class we do not see a git difference in which we added a new empty line. Instead we can see clearly that a new method was added. For functions I prefer the 2 blank lines since I am treating them as if it were a class. I think of them to be a little bit less related (as opposed to methods).
Lastly, this is something that I also failed to see in the style guide: exports. Usually if my module consists of many functions I prefer to scroll to the bottom to see what I am exporting. For this reason I only write 1 single
export {}
andexport default
. In this way if ever decide to export another item now I just add it to the list instead of making git give me a line change on the function. That is, instead of seeingnow we have
export { someVar, + foo, }
What are your preferences and why? Could we have some section in the style guide pointing them out for future reference? I'll be happy following them as long as there is consistency.
The text was updated successfully, but these errors were encountered: