Giter Club home page Giter Club logo

Comments (22)

refack avatar refack commented on May 4, 2024 9

ASI is a flamable issue. IMHO semicolons are a style choice, so I wouldn't be opinionated about usage.
I'd call that section Respect the Semicolon put two code snippets that exemplify the pitfalls of both, something like:

function aaa() {
    return
    {
        test: 1
    };
}
aaa() === undefined;

and

var m = new Map()
var a = [1,2,3]
[...m.values()].forEach(console.log)
> [...m.values()].forEach(console.log)
>  ^^^
> SyntaxError: Unexpected token ...

And the tl;dr should be use a linter

from nodebestpractices.

TimonLukas avatar TimonLukas commented on May 4, 2024 8

I'd argue that since they are a style choice they should not be included in a guide like this. No site really has advantages, and there is a reason why projects like semistandard are successful next to projects like standard.

from nodebestpractices.

syzer avatar syzer commented on May 4, 2024 8

I was in favour of manual semi insertion.

Could come up with code examples when js would fail if not for the manual semi insertion.

But then, some 6-7 years ago on some hackaton, during 30+ th hour of coding (2am or so),
my friend had put , instead ; and we wasted half an hour debugging...

Since then I tried ASI (automatic semi) , first on some small projects, then on big enterprise projects.
Never had any issues around it.
Never.

My advise: just try it!
After one week with ASI you will not want to go back to manual.

Its not just about that code is more readable with ASI...
Its about having bug free codebase.

And those errors that only manual semi can fix?
Again: because of eslint we never, ever encountered them.

from nodebestpractices.

fox1t avatar fox1t commented on May 4, 2024 6

I agree that this rule doesn't make any sense today. This is a just personal taste, with no influence on the readability of the source code: omitting semicolons is only a matter of preference. In addition to that, ESLint has specific rules to avoid multiline expressions mistakes. https://eslint.org/docs/rules/semi and https://eslint.org/docs/rules/no-unexpected-multiline
I think that would be better to remove this rule and update eslint section to include this references.

from nodebestpractices.

MartinMuzatko avatar MartinMuzatko commented on May 4, 2024 4

I proposed a PR. Hope it unites all the opinions here in this thread.

from nodebestpractices.

deksden avatar deksden commented on May 4, 2024 3

IMHO, usage of semicolons itself is not enough to make code error-proof.

Only combination of several factors like block style, linter usage make code much safer even without semicolons.

from nodebestpractices.

snypelife avatar snypelife commented on May 4, 2024 3

This is a fantastic thread and was one of the things that made me go πŸ€” in terms of best practices. I fully support dropping the section recommending semicolons while strongly advocating the use of a linter.

Also giving explicit examples such as standardjs, prettier or even AirBnB config I feel would be helpful.

from nodebestpractices.

goldbergyoni avatar goldbergyoni commented on May 4, 2024 2

@refack based on all of the above, it seems to be too opinionated for our guide. If you and @idori agree, let's drop

from nodebestpractices.

j-f1 avatar j-f1 commented on May 4, 2024 2

How about β€œ3.4 Be Consistent With Your Semicolons?” (i.e. it doesn’t matter if you pick semicolons or no semicolons, as long as you’re aware of the pitfalls of each and stay consistent)

from nodebestpractices.

MartinMuzatko avatar MartinMuzatko commented on May 4, 2024 2

I agree. I would say "use a coding style" is important than following none at all. But using semicolons or not is very opinionated. However, I hope that standardjs will be more wide-spread used and adopted in the future.

from nodebestpractices.

deksden avatar deksden commented on May 4, 2024 2

Title for 3.4 can be changed to something like "Don't forget about proper statement separation" and describe some side-effects of not using explicit semicolons and following ASI. ASI itself is not bad. Main threat is not omitting semicolons itself, but problems with run-time separation of different statements.

Samples from this thread can make some wiki page with details.

from nodebestpractices.

rochejul avatar rochejul commented on May 4, 2024 1

Hi @idori

Sure, but my point is: I am not sure that a rule like "Don't Forget the Semicolon" is revelant, because the ecmascript engine is not hardly based on this "feature".

I could understand that this is more readable. But it cannot avoid some side issues.

I would suggest a warning more a use case like that:

if (aCondition) 
   doSomething();

Because on various languages, I have resolved a lot of big bugs because people do:

if (aCondition) 
   doSomething();
  doSomethingElse();

Where always use brackets on conditions avoid side issue.

Again, I understand your point of view.

My two cents

Regards

from nodebestpractices.

fox1t avatar fox1t commented on May 4, 2024 1

On the https://standardjs.com/ site there is a section that explains why no semi is the default choice using 3 links:
http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding
http://inimino.org/~inimino/blog/javascript_semicolons
https://www.youtube.com/watch?v=gsfbh17Ax9I
and also here:
https://standardjs.com/rules.html#semicolons

from nodebestpractices.

goldbergyoni avatar goldbergyoni commented on May 4, 2024 1

@refack @idori @j-f1 I think we should contain only definitive guidelines which includes verbs (do that, drop this, include these) and not general piece of information (you should now that).

Hence, I would combine @refack and @j-f1 suggestions into something like: Be consistent and mindful about semi-color + @refack text and examples.

@idori u lead this issue

from nodebestpractices.

idori avatar idori commented on May 4, 2024

Hi @rochejul and thanks for the input!
Please note that the issue you raised it explained in the previews point (3.3 Start a Codeblock's Curly Braces in the Same Line)
We might need to make it more clear though, as the example is inside the link to Stackoverflow

from nodebestpractices.

goldbergyoni avatar goldbergyoni commented on May 4, 2024

@refack what do you think?

from nodebestpractices.

refack avatar refack commented on May 4, 2024

P.S. we could ask @feross why he picked no-extra-semi for standard?

from nodebestpractices.

refack avatar refack commented on May 4, 2024

P.P.S. - ASI = Automatic Semicolon Insertion
From the spec:

Automatic Semicolon Insertion

Most ECMAScript statements and declarations must be terminated with a semicolon. Such semicolons may always appear explicitly in the source text. For convenience, however, such semicolons may be omitted from the source text in certain situations. These situations are described by saying that semicolons are automatically inserted into the source code token stream in those situations.

from nodebestpractices.

shelmire avatar shelmire commented on May 4, 2024

I concur with @refack . Semicolons are a style choice. And one option requires writing less code!

from nodebestpractices.

idori avatar idori commented on May 4, 2024

I do like @refack's definition, but I agree to take if out completely if it's a too opinionated subject for a style guide.

from nodebestpractices.

deksden avatar deksden commented on May 4, 2024

@syzer : exactly!

I never miss any semi in my code - ESLint make code safer, i always have some tricky bug eliminated only by working out some eslint issues (sure you have to configure it to your style).

So - semi is not mandatory, imho

from nodebestpractices.

stale avatar stale commented on May 4, 2024

Hello there! πŸ‘‹
This issue has gone silent. Eerily silent. ⏳
We currently close issues after 100 days of inactivity. It has been 90 days since the last update here.
If needed, you can keep it open by replying here.
Thanks for being a part of the Node.js Best Practices community! πŸ’š

from nodebestpractices.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.