What is the most effective JavaScript syntax checking solution? - javascript

I am developing an AJAX application and in the process of doing this I am creating many small JS files that will eventually be concatenated and minified in the production release. However in development I will be working with the individual uniminified files.
The issue I have is that I am using Kate in Ubuntu as my editor and when I make small errors like an extra comma in a JSON structure, or an extra parenthesis, colon, semi-colon, or other simple syntax error I have no way of knowing until I see it in Firebug or IE Developer Toolbar (run in a VM). Unfortunately Firebug isn't very good at identifying which line has the syntax error and only IE complains about extra commas. If I could see these mistakes in real-time like a good modern IDE it would be awesome. However, I'll settle for any syntax checking solution that doesn't require me to copy and paste each file from my local machine into a text area.
Also, JSLint goes a bit overboard with it's checking. Half of the things it complains about I do intentionally.
What are my options?

jshint ( http://www.jshint.com/ )is one of the descendants of jslint after several people had also such problems with jslint (being too opinionated).
You could do similar things I guess with jshint as well as it is done by jslint here: http://sergioserra.posterous.com/using-jslint-with-kate
Personally, I used vim with jslint (with a much more permissible configuration than the default), which was checking syntax live.
Another alternative is Closure Linter from Google: https://developers.google.com/closure/utilities/

Related

Checking JavaScript code for typos in Notepad++

I use a combination of Notepad++, JSHint and Cordova CLI to create my hybrid Android web apps - yes, I am aware that there are more sophisticated ways of doing this but tht is not what this question is about.
One of the issues I run into every now and again is a typographic - as opposed to syntactic which is easily caught by JSHint - error which only manifests itself once I am compiled the APK and tried to run it. For instance
docment instead of document (missing u)
getElmentByID instead of getElementById (missing e, wrong capitalization on ID)
The one thing I really love about Java is that the compiler stops you dead in your tracks and demands that you fix such errors first. That is not the case with JavaScript where the best one can do is test for correct syntax.
However, I am wondering - perhaps there is a way (maybe a NPP plugin that I am unaware of) to check for such errors?
Use typescript or flowtype to catch those, and many more errors. Alternatively, find a decent syntax theme that's set up to highlight DOM methods.

Eclipse Javascript how to switch off missing semicolon warning?

Having used Groovy for many years, I have developed a large node & JS v.6 project without any semicolons with Notepad++. It is a huge time saver and liberating, as, for me at least, semicolons are a complete waste of time and space. I have not yet come across a case where not having them in my Groovy nor js code has caused a single problem in 8 years.
Unfortunately, Eclipse + nodeclipse plugin don't see it that way. It complains about every line missing a semicolon. I tried switching it off in two ways:
window->preferences->Javascript->Validator->Errors/Warnings->Potential programming problems->Optional semi-colon=Ignore.
unticked "Enable javascript semantic validation"
Neither helped, plus I don't want to disable any of the other validation as this is the only benefit Eclipse + nodeclipse offers over Notepad++ (that I can find at least). In fact, Notepad++ offers significantly better completion than eclipse, as it remembers what you typed before, but eclipse does none, it only does highlighting.
Anyone have any ideas on how to stop the semicolon warnings?
Go to Configuration(alt+enter), in JSHint/Configuration , you have to set or edit the following key to tolerate Automatic Semicolon Insertion:
"asi" : true

Chrome dev tools lose syntax highlighting for TypeScript

I'm not sure if there if a way around this, or if maybe there is an issue when using mapped TypeScript files, but in many cases (larger files), I seem to lose the syntax highlighting..
As can be seen on the above image, it is ok until line 102, and from then on the rest of the file is just in red.
The above is from an Ionic 2 / Angular 2 project.
Appears to happen after the use of backtick string (but not always after the use of these)
It is not the end of the world, but the highlighting does make it easier to read. Anyone else experience this, and perhaps know a work around?
experiencing this problem all the time working with TS sourcemaps.
that's chromium engine trouble, there is also bug report about this problem
(link to report)
I gave up for this and using oldschool string concatenation.

How to enforce semicolons in JavaScript?

How best does the developer who's decided he likes semicolons at the end of his JavaScript statements enforce that expectation technically for himself?
I'm using Visual Studio (ASP.NET webapps), but I'd love to hear about solutions for any environment.
You could somehow integrate Javascript Lint into the IDE.
I sometimes run my JS through a handler that strips all new lines, comments, tabs, and extra whitespace automatically. If my JS statements don't end with a semi-colon I'll get an error (in most cases)...doing it this way is a PAIN to debug though (e.g., error on line 1 character 2654).
The other way I use is Firebug + YSlow. You can check it's built in JSLint every once in a while.
Maybe there is a file in Visual Studio for checking javascript syntax you may be able to modify like there is for (X)HTML and XML.

Firefox add-on tools for checking JavaScript syntax?

Not sure if there is any Firefox add-on tool for checking JavaScript syntax, var declaration, or even pre-compiling available?
I find out is very difficult to debug JavaScript in a web html page. I have to add some script there. When the scripts get very big or long, it stops working. Basically, there must be some bugs. It is very frustrating even the load event stop working. I do need some good tools to find out the bugs.
I have tried FireBug. It is good but not enough. Maybe I don't know all its features. Anyway, I need any good suggestions.
This page may help you a bit as it also contains a screencast.
Debugging Javascript in Firefox with Firebug
It's not strictly an Add-On (although you can obviously run it in a Firefox web page), but I've found JSLint to be helpful in exposing expression anomalies that might or might not be strictly invalid syntax (although it will catch all those, too.)
My suggestion is to check you javascript with JSLint. JSLint will show you common problems in javascript code and helps you to create strict and compatible code.
YSlow includes JSLint as Tool.
As an alternative to FireBug check this debugger: Venkman JavaScript Debugger, has been out there for a while, and it's not bad at all...
I have always been a firebug fan and it sure is one of the best debuggers out there. Any JS issue Press F12, Enable the console for catching the errors and then you can find the exact line causing the error. Add a breakpoint and you can see the exact values of variables too. Very intuitive UI..just get used to using it and it will save a lot of your time.
I HIGHLY recommend Rainbow. It's still in Beta and only works in FF3, but it offers syntax highlighting. That will get you half-way there when it comes to syntax.
I constantly use firebug with a js file that has some 15000 lines. I've had no problems with it (sometimes I have to wait a few seconds for it to scroll to the breakpoint but even then it works fine).
Unfortunately JSLint does'nt work for us. We use some third party code that while beeing "valid" has unnecessary ";" according to jsLint. The code is in the beginning of our js file and jslint stops analyzing at 3% because it thinks there are too many errors (all of them unnecessary ";".)
You're missing the point on 2 counts:
First, being presented with a gazillion unnecessary error messages will make it impossible to find the problem in the first place.
Secondly, the errors are unnecessary. I used to use JSLint religiously, but now it's become too much of a code Nazi and I can't use it.
I'm aware that many of the things it checks for can be disabled, but I just don't have enough time to research what I'd have to do.
The issue is the usability of the default configuration. I, like the original poster, am just looking for a way to find true JavaScript syntax errors very quickly, including on HTML pages. I'm sure that Firebug can do it, but as in the case with JSLint, I don't have the spare time to find out how.
I do, however, use Firebug for debugging, though the version I'm using (1.10.3) has a bad habit of displaying errors, but reporting an incorrect file and line number.
Hi Gene: you could change one variable option.maxerr inside your jslint.js file into the number you want.
The default value is 50, you could change it to 500 or 1000 to suite your taste.
I use both the following for code validation.
JSHint # http://jshint.com
JSLint FF Plugin. Get at https://addons.mozilla.org/en-us/firefox/addon/jslinter/
Alternatively, jshint and jslint plugins are available for text editors like Notepad ++, sublime etc.

Categories

Resources