0

I read somewhere that with jsdoc in your JavaScript and the google closure tool gjslint you can strongly type your javascript. It's not really strongly typed but the tool will report on uncommented variables and or parameters.

Here is the test file:

var keywordLists = {
  hello: function($obj) {
    this.something = 22;
  }
};

After gjslint reporting on whitespace errors it passes the file; the following command:

c:\Python27\Scripts\gjslint.exe --strict --jsdoc js\test.js

gives output:

1 files checked, no errors found.

I would like use this as sort of compile time check but all it does is give me headaches about wrong whitespaces. I'd like it to ignore the white spacing and check for jsdoc and calls to functions having valid/strong typed parameters.

I'm using this on windows 7-64 with pythod 2.3.7 (python 3 didn't work at all on Windows because it won't install without tons of errors and then can't even print a gjslint --help afterwords).

Does anyone know what I am doing wrong here?

HMR
  • 37,593
  • 24
  • 91
  • 160
  • Just tried it on Fedora 17 with the same file but other than crying about white space it doesn't seem to do anything. It says it's supposed to check jsdoc but don't see how. – HMR Mar 11 '13 at 10:23
  • Looks like jslint is just there to complain about the format not the jsdoc. Trying compile.js from closure compiler and looks like it checks variable types. – HMR Mar 11 '13 at 11:26
  • 1
    lint does complain when docs are missing, but as you rightly observe the compiler does type checking. on a side note, if you are not using the compiler command line on a 64 bit machine I would recommend running the java processes in client mode, it will give you some speed ups, if however you are running the compiler as a longstanding service, don't – lennel Mar 12 '13 at 10:44
  • Thank you lennel, I am just trying to figure this out and would like to use it for future projects. Working on an AIR application now and trying to implement it for the non AIR or DOM interacting "classes". Still have to check how to not include stuff without closure compiler removing functions (since they're called by files I can't/don't care to make a externs files for). So will try this: https://developers.google.com/closure/compiler/docs/api-tutorial3#export – HMR Mar 12 '13 at 11:03
  • I would use goog.dom instead of something like jquery for dom interaction as well. The method you linked to there is NOT my preferred method for exporting things, i would advise goog.exportProperty() and goog.exportSymbol() – lennel Mar 12 '13 at 11:50
  • Will have to look into goog.dom, code can maybe be optimised better if more code is included. Got hooked on jQuery though and loving the code assist in eclipse and VisualStudio. I'm trying to keep my DOM traversing/manipulating/reading in one place not only for closure compiler but also because the design and layouts of the pages might change (it's AIR and we don't use templates). Don't like to look through many files of code if there is a $ in there or a val(), html() ... – HMR Mar 12 '13 at 16:56
  • the closure templates work in air since they are compiled before hand and don't require you to eval or function.call. in air if you wish to use templates like handlebars which you have to compile on the client and require function.call you can do it before the dom is ready, eval obviously won't work. i can recommend the closure model of component development, quite similar in some ways to flex. – lennel Mar 12 '13 at 20:34
  • Now I'm starting to see the fuller picture. Using closure libraries and compiling them gets you only the functions of the library that you use. If I have more time I'll look into it. The site https://developers.google.com/closure/library/ has "hello world" documentation and the api doc. Thank you for pointing that one out, feel silly for not knowing about those libraries sooner :-( – HMR Mar 13 '13 at 03:33

0 Answers0