Are there equivalent to perl -c
syntax check for JavaScript from command? Given that I have NodeJS installed?
JSLint is not considered as it is not a real parser. I think YUI compressor is possible but I don't want to install Java on production machines, so I am checking if Node.JS already provided this syntax check mechanism.
Tip: To check if a JavaScript file is part of JavaScript project, just open the file in VS Code and run the JavaScript: Go to Project Configuration command. This command opens the jsconfig.json that the JavaScript file belongs to.
JavaScript Syntax. JavaScript. Syntax. ❮ Previous Next ❯. JavaScript syntax is the set of rules, how JavaScript programs are constructed: var x, y, z; // Declare Variables. x = 5; y = 6; // Assign Values. z = x + y; // Compute Values.
If you want to perform a syntax check like that way we do in perl ( another scripting language) you can simply use. node -c check syntax - node -c test.js will show no syntax error!! Note - we can even use it to check syntax for all files in a dir. - node -c *.js Hope that helps.
The easiest way to enable type checking in a JavaScript file is by adding // @ts-check to the top of a file. // @ts-check let itsAsEasyAs = 'abc'; itsAsEasyAs = 123; // Error: Type '123' is not assignable to type 'string'
@Ryan
If you want to perform a syntax check like that way we do in perl ( another scripting language) you can simply use. node -c
e.g. a js file as test.js has -
let x = 30
if ( x == 30 ) {
console.log("hello");
else {
console.log( "world");
}
now type in node -c test.js
it will show you
test.js:5
else {
^^^^
SyntaxError: Unexpected token else
at startup (bootstrap_node.js:144:11)
at bootstrap_node.js:509:3
Now after fixing the syntax issue as
let x = 30
if ( x == 30 ) {
console.log("hello");
} else {
console.log( "world");
}
check syntax - node -c test.js
will show no syntax error!!
Note - we can even use it to check syntax for all files in a dir. - node -c *.js
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With