Live data from Hacker News

Proposed JavaScript Standard Style

github.com

41–50 of 116 posts

Re: Proposed JavaScript Standard Style

#42
post #14

Earlier quoted context omitted.

Let's just say that coupling this preference with the name "standard" is an extremely contentious decision (search the github issues).

https://github.com/Flet/semistandard Of course the solution is to create a separate "standard."

This is great, but I don't like the space between function names and arguments.

I'm going to fork this and create my own standard...

Re: Proposed JavaScript Standard Style

#43
post #30

Regarding the "no semicolon" stuff, is there actually any way to write this type of formatting list.map(func1) .filter(func2) .map(func3) .reduce(func4); in JavaScript? As far as I know, the semicolon rules would automatically terminate the statement after map(func1). EDIT: Ah, thanks – the things I read never mentioned JS doing lookahead during ASI. This makes it a lot nicer, tbh.

That's fine in JavaScript and will work as expected.

Re: Proposed JavaScript Standard Style

#44
post #30

Regarding the "no semicolon" stuff, is there actually any way to write this type of formatting list.map(func1) .filter(func2) .map(func3) .reduce(func4); in JavaScript? As far as I know, the semicolon rules would automatically terminate the statement after map(func1). EDIT: Ah, thanks – the things I read never mentioned JS doing lookahead during ASI. This makes it a lot nicer, tbh.

It depends on the engine, but most, when parsing, will look-ahead and see that `.` in `.filter(func2)` is an invalid start to an expression and assume it is part of the previous line.

Re: Proposed JavaScript Standard Style

#45
post #8

2 spaces for indentation? No :(

I always use a tab and set the IDE to show two spaces for each tab. Visual Studio has a setting for this. In the same project if someone wants 4, they can just change it to 4 spaces. In the file, its always stored as a tab

I agree. The number of spaces for indentation is completely irrelevant in a style guide as it can be configured in the editor on a personal basis.

Re: Proposed JavaScript Standard Style

#46

Earlier quoted context omitted.

This. Calling this "JS standard!" bothers me to no end. I suppose I have to create my own style and call it "standard" too.

https://xkcd.com/927/

Maybe we can also standardize this exact post since there have already been like five of them.

Re: Proposed JavaScript Standard Style

#47
post #24

I've been lucky enough to avoid having to deal with a style guide in a long time. The general idea is sound, but such a guide is always accompanied by hours-long meetings of senior developers hurling their egos at each other over an issue like semicolon usage. Such a waste of everyone's time.

Yeah, that's the whole point of this "standard" project. So instead of adopting for example eslint and then sit in a meeting and decide which rules to follow or not, you adopt standard and say, we are using this now, deal with it.

Re: Proposed JavaScript Standard Style

#48
post #30

Regarding the "no semicolon" stuff, is there actually any way to write this type of formatting list.map(func1) .filter(func2) .map(func3) .reduce(func4); in JavaScript? As far as I know, the semicolon rules would automatically terminate the statement after map(func1). EDIT: Ah, thanks – the things I read never mentioned JS doing lookahead during ASI. This makes it a lot nicer, tbh.

No, ASI (automatic semicolon insertion) does not insert a semicolon on the first line (or the 2nd or 3rd) in this case.

The code works as expected.

Re: Proposed JavaScript Standard Style

#49
post #30

Regarding the "no semicolon" stuff, is there actually any way to write this type of formatting list.map(func1) .filter(func2) .map(func3) .reduce(func4); in JavaScript? As far as I know, the semicolon rules would automatically terminate the statement after map(func1). EDIT: Ah, thanks – the things I read never mentioned JS doing lookahead during ASI. This makes it a lot nicer, tbh.

In most cases[0], Js "looks" at the next line to see if it could continue the current statement, in which case no semicolon is inserted.

[0] Not true for "restricted productions", which include naked returns, and some other "special" cases.

Post reply on HN