One can find JSHint from website jshint.com (or from Github: https://github.com/jshint/jshint/). JSHint is tool for linting Javascript. It has plenty of tips how to make your code work in every browser or how to be more compatible with Ecmascript-standard or just make you code rock. While website version is neat and works as expected you can come in the point when you need local version. Then you just install Node.js and version for it from: https://build.opensuse.org/project/show/home:illuusio:nodejs-fedora (they are pure openSUSE packages that are ported from Fedora project and I can image this is causing some cruel battles in court but you can use them if you wish.)
JSHint is very easy tool and it will drive you nuts because it will reveal all you bad habits to the World. Using it is simple as typing
jshint yourbestscript.js
For example Leaflet 0.7.2 script gives errors like that (this is minified version)
leaflet.js: line 6, col 215, Missing semicolon. leaflet.js: line 6, col 385, Expected an assignment or function call and instead saw an expression. leaflet.js: line 6, col 386, Missing semicolon. leaflet.js: line 6, col 395, Missing semicolon. leaflet.js: line 6, col 534, Missing semicolon. leaflet.js: line 6, col 535, Missing semicolon. leaflet.js: line 6, col 623, Missing semicolon. leaflet.js: line 6, col 624, Missing semicolon. leaflet.js: line 6, col 777, Missing semicolon. leaflet.js: line 6, col 786, Missing semicolon. leaflet.js: line 6, col 942, Expected an assignment or function call and instead saw an expression. leaflet.js: line 6, col 943, Missing semicolon. leaflet.js: line 6, col 966, Missing semicolon. leaflet.js: line 6, col 967, Missing semicolon. leaflet.js: line 6, col 996, Missing semicolon. leaflet.js: line 6, col 1070, Missing semicolon. leaflet.js: line 6, col 1138, Missing semicolon. leaflet.js: line 6, col 1197, Missing semicolon. leaflet.js: line 6, col 1275, Missing semicolon. leaflet.js: line 6, col 1459, Missing semicolon. leaflet.js: line 6, col 1646, Missing semicolon. leaflet.js: line 6, col 1648, Missing semicolon. leaflet.js: line 6, col 1743, Missing semicolon. leaflet.js: line 6, col 1844, 'e' is already defined. leaflet.js: line 6, col 1929, Missing semicolon. leaflet.js: line 6, col 1949, 'i' is already defined. leaflet.js: line 6, col 1955, Missing '()' invoking a constructor. leaflet.js: line 6, col 2013, Missing semicolon. leaflet.js: line 6, col 2195, Missing semicolon. leaflet.js: line 6, col 2291, Missing semicolon. leaflet.js: line 6, col 2341, Expected an assignment or function call and instead saw an expression. leaflet.js: line 6, col 2342, Missing semicolon. leaflet.js: line 6, col 2342, Expected an assignment or function call and instead saw an expression. leaflet.js: line 6, col 2343, Missing semicolon. leaflet.js: line 6, col 2597, Expected an assignment or function call and instead saw an expression. leaflet.js: line 6, col 2598, Missing semicolon. leaflet.js: line 6, col 2652, Missing '()' invoking a constructor. leaflet.js: line 6, col 2682, Expected an assignment or function call and instead saw an expression. leaflet.js: line 6, col 2756, Expected an assignment or function call and instead saw an expression. leaflet.js: line 6, col 2986, Expected an assignment or function call and instead saw an expression. leaflet.js: line 6, col 3171, Expected an assignment or function call and instead saw an expression. leaflet.js: line 6, col 3241, Missing semicolon. leaflet.js: line 6, col 3245, Missing semicolon. leaflet.js: line 6, col 3301, Missing semicolon. leaflet.js: line 6, col 3370, Missing semicolon. leaflet.js: line 6, col 3507, Missing semicolon. leaflet.js: line 6, col 3597, Expected an assignment or function call and instead saw an expression. leaflet.js: line 6, col 3598, Missing semicolon. leaflet.js: line 6, col 3598, Expected an assignment or function call and instead saw an expression. leaflet.js: line 6, col 4018, Expected an assignment or function call and instead saw an expression. leaflet.js: line 6, col 4018, Too many errors. (66% scanned).
Line numbers are broken because as I said it’s minified version of Leaflet but you get the point. Now if you do Javascript there is no excuse to wait your customer, user, mom or lover to nag about how bad your code it you can check it and feel the pain. Next time I’ll make your code shine.
]]>