简体   繁体   中英

Is it possible to check JavaScript files with node and get errors when a semicolon is missing?

I use the following command before sending JS files to my server:

node --check <filename>.js

That way I can be sure there are no gross errors before forwarding the file to the server (ie a missing ) generates an error).

What I noticed, though, is that node.js does not give me an error if I do not put a semicolon at the end of a line. I would like that to happen, but after looking at the command line options, I just cannot see such a feature.

Is there a way to do that with node.js ?

What I noticed, though, is that node.js does not give me an error if I do not put a semicolon at the end of a line.

That's because JavaScript has an error-correction mechanism called automatic semicolon insertion (see this question's answers for more about ASI), where the parser will insert semicolons into the token stream for you if they're missing in many cases. So Node itself isn't going to give you this information.

I would recommend using a proper lint tool instead, such as ESLint , JSHint , or any of several others.

Its actually not an error if you don't put in a semicolon in javascript. I've seen both kinds of developers some of them prefer it and some of them don't.

I agree with the answer above, you can use linters and they run with IDEs pretty smoothly.

You can correct yourself as you go rather than writing lines of code and at the end, correcting all your syntax errors (which obviously doesn't scale and becomes irritating after a while).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM