outmoded / hapi-contrib

Discussion forum for project contributors
Other
78 stars 25 forks source link

Conflict in rules for object assignment #99

Closed saeidalidadi closed 7 years ago

saeidalidadi commented 7 years ago

In style.md there is two rules for object assignment which deny each other. the two are as bellow:

thebergamo commented 7 years ago

I can't figure how one deny other.

const emptyObj = {};

This code above are agree with the two rules.

* No space for empty objects {}
Remove spaces inside brackets when the object is empty.
``` javascript
// don't use
const obj = { };

// use 
const obj = {};

For me the rules are correct.

saeidalidadi commented 7 years ago

@thebergamo I mean the line:

const user = { name: 'john', email: 'john@example.com' };

Is this true for this rule? No inline object in assignment unless empty.

thebergamo commented 7 years ago

Well, in this case isn't true. Because when you're assigning an object to a variable is recommended you not using an inline object. The correct statement is:

const user = {
    name: 'john',
    email: 'john@example.com'
};

Inline objects are used in just two cases, when you're sending as an option in a function not assign for a variable, or assign an empty object to a variable.

nlf commented 7 years ago

the confusion here is that the line

const user = { name: 'john', email: 'john@example.com' };

is there to demonstrate the spacing rule, not to show that it's appropriate to define an object this way. i agree, it's a bit confusing. we can change it to be a function call instead, which is acceptable per style guidelines.