outmoded / hapi-contrib

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

Indentation style question #112

Closed geek closed 5 years ago

geek commented 7 years ago

With ESLint v4.0 we now have stricter indentation enforcement... which of the following snippets do you prefer.

Style 1

    const count = (typeof credentials.scope === 'string' ? (scope[type].indexOf(credentials.scope) !== -1 ? 1 : 0)
                                                         : Hoek.intersect(scope[type], credentials.scope).length);

Style 2

    const count = (typeof credentials.scope === 'string' ? (scope[type].indexOf(credentials.scope) !== -1 ? 1 : 0)
        : Hoek.intersect(scope[type], credentials.scope).length);

Style 3

    const count = (typeof credentials.scope === 'string'
        ? (scope[type].indexOf(credentials.scope) !== -1 ? 1 : 0)
        : Hoek.intersect(scope[type], credentials.scope).length);

Style 4

    const count = (typeof credentials.scope === 'string'
        ? (scope[type].indexOf(credentials.scope) !== -1 ? 1 : 0)
        : Hoek.intersect(scope[type], credentials.scope).length
    );

Style 5

const count = (typeof credentials.scope === 'string' ?
        (scope[type].indexOf(credentials.scope) !== -1 ? 1 : 0) :
        Hoek.intersect(scope[type], credentials.scope).length);
Marsup commented 7 years ago

1st

geek commented 7 years ago

@Marsup added a couple more possibilities

Marsup commented 7 years ago

Mix of 1 and 3 ? (ie. 3 with more padding)

Marsup commented 7 years ago

And I hate those parenthesis so 3 or 4 makes no diff to me as long as they're there.

cjihrig commented 7 years ago

I like 4, but with the ? and : on the previous lines.

geek commented 7 years ago

@Marsup and @cjihrig thanks for the help, I'll PR an update to the style guide and to hapi.

    const count = typeof credentials.scope === 'string' ?
        (scope[type].indexOf(credentials.scope) !== -1 ? 1 : 0) :
        Hoek.intersect(scope[type], credentials.scope).length;
devinivy commented 7 years ago

I'm into it 👍

Marsup commented 7 years ago

Looks like those indents are going to be a problem. I don't agree with most of those errors on joi tests.

johnbrett commented 7 years ago

I'm think I'm late here, but my vote would have been for 3 or 4 😄. I prefer operator at the start of the line. Will happily use whatever's agreed on though 👍

AdriVanHoudt commented 7 years ago

I prefer 3 :P

mark-bradshaw commented 7 years ago

3

hueniverse commented 7 years ago

3 or 2. I like 1 best but recent changes in VS force it to 3 so...