5

I know javascript (or at least a version of it) can be compiled into .NET provided certain conditions are met. How can i do a compile time or static syntax check on javascript i am writing? The catch is, it must support jquery

Cause someone will ask, to compile (with ms .net) is

C:\Windows\Microsoft.NET\Framework\v2.0.50727\jsc thefile.js

writing package thenamespace { class ClassName{ around where necessary. Then you can add this as a normal reference. From experience the references are not always compatible with mono.

1 Answers1

4

I'm not sure if there are any static analyzers which can check the validity of jQuery code in depth, but for the Javascript syntax itself, there are non-web versions of Javascript Lint and JSLint you could use.

If you're using Visual Studio, you could also give JSLint.VS a try for better integration.

UPDATE: Since I wrote this, JSHint and ESLint have taken over as the most popular members of the JSLint family.

Also, TypeScript is gaining popularity. It's a superset of JavaScript with optional static types which compiles to plain JavaScript. (For those who have used MyPy for Python, it's similar. Valid JavaScript is also valid TypeScript, but you can incrementally add type annotations and the compiler will use them to catch bugs.)

ssokolow
  • 14,938
  • 7
  • 52
  • 57
  • 1
    AFAIK all lints just check syntax and occasional bad or good practice. Does any of these keep the type in mind ? –  Nov 29 '10 at 23:48
  • I've never run across a static analyzer which could make any kind of reliable attempt at managing types in an implicitly-typed, dynamically-typed language like Javascript. (Or Python, for that matter, which I also use.) – ssokolow Nov 30 '10 at 00:13