Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript code analysis and best practices

Are there any tools out there to help programmers that REALLY want type safety and the more stringent rules of a language like c# or java with javascript?

For example, something that say analyzed source files and found things like undeclared variables or a js file of defined type objects like int or string?

like image 546
j03m Avatar asked Jul 10 '10 05:07

j03m


People also ask

Can we use Sonarqube for JavaScript?

You can use sonar. javascript. node. maxspace property to allow the analysis to use more memory.


1 Answers

In addition to JSLint, Google Closure Compiler can be used for static analysis of JS source as well, and it checks different things than JSLint too.

Neither of these tools does provide exactly what you want though.. Closure Compiler attempts type-checking if I remember correctly, but it doesn't always work (at all).

Although such features may seem desirable from the point of view of someone who's used to strictly typed languages, I often see people attempting to use JS like C#/Java/whatever go wrong on more than one level, and usually ending up with less readable and worse code in general. Of course this may not be your case, but this is just a general observation/warning to keep in mind.

My suggestion would be to embrace the "looseness" of the language, with perhaps test-driven development as a quality assistance tool (JsTestDriver).

like image 166
Jani Hartikainen Avatar answered Nov 04 '22 17:11

Jani Hartikainen