gjslint not reporting any error on file without jsdoc whatsoever - javascript

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?

Related

Why shoudl TSlint be executed after Typescript files is compiled?

According to the official TSLint, TSLint should executed only after the Typescript code is compiled. What is the reason behind this?
The official TSLint doc: https://palantir.github.io/tslint/usage/cli/
TSLint runs against a parsed AST (Abstract Syntax Tree) that it receives from TypeScript. If the AST it receives from TypeScript has errors, its rules' logic might make some incorrect assumptions.
Defining a few of those terms:
AST: Tree-like representation of your code that the linter will analyze. You can play around with astexplorer.net to see what this looks like; it's pretty nifty! 😊
Syntax errors: if you write code such as led foo = "bar"; (led instead of let). TypeScript will create a different representation of your code than you might expect.
Semantic errors: if you write code that has no syntax errors but the type checker finds issues with, such as let foo: number = "bar";.
TSLint has an issue open to discuss whether it shouldn't bother checking code that has syntax or semantic errors: https://github.com/palantir/tslint/issues/3808
Two additional points in favor of not running TSLint on invalid source files:
A lot of people have trouble differentiating between TS and TSLint errors, so it can be confusing when an invalid file results in a lot of lint errors
TS code that doesn't compile tends to have different linting issues after it gets fixed, so it's a bit of a waste to ask people to fix them along with the TS errors

Closure Compiler with Advanced Optimizations and Externs

I have downloaded the latest closure compiler jar file and followed the instructions here to see how I can get it to preserve references to JS functions defined elsewhere.
My test script, hello.js is as follows
function hello(nom)
{
alert(nom + familyName());
}
My externs are defined in the file externs.js which contains the code
function familyName(){}
I then issue the command
java -jar closure.jar --js hello.js --externs externs.js --js_output_file hello-compiled.js --compilation_level ADVANCED_OPTIMIZATIONS
Without ADVANED_OPTIMIZATIONS everything works correctly - effectively a spot of code minification. However, as soon as I put in the advanced flag the output hello_compiled.js comes out as an empty 1 byte file. Clearly, I am misunderstanding something somewhere. I'd be much obliged to anyone who might be able to put me on the right track here.
I suspect your hello.js only defines the hello function? If so, you need to add:
hello("foo");
so that something actually happens. You can try this out with the online closure compiler. The default code there is:
function hello(name) {
alert('Hello, ' + name);
}
hello('New user');
If you comment out the last line and click the "advanced" button and compile, the result is successful but it is zero bytes. This is because that code effectively does nothing, so the compiler is doing the right thing.

Syntastic with jslint for vim not executing the checker

I have set up Syntastic https://github.com/scrooloose/syntastic with vim and I would like to use it for node.js javascript linting.
I have installed jslint
$ jslint routes/index.js
routes/index.js
#1 Expected exactly one space between 'function' and '('.
module.exports = function(app) { // Line 5, Pos 26
....
And I have put this in my ~/.vimrc
let g:syntastic_jslint_checkers=['jslint']
let g:syntastic_check_on_open=1
let g:syntastic_enable_signs=1
But I get no output on :SyntasticCheck
Yet
Syntastic: active mode enabled
Syntastic info for filetype: javascript
Available checker(s): jslint
Currently enabled checker(s): jslint
I recommend JSHint as an alternative for JavaScript linting in Vim. Here is a great answer that explains how to install it.
If you want to use JSHint for creating web sites as well, I'd additionally use RequireJS. This way your JavaScript and your HTML code stay separated (JSHint can't deal with JavaScript inside HTML files).

Custom settings with jshint-rhino.js

I've been using jshint with node but just recently had to switch over to using it with Rhino.
I used to be able to do:
jshint --config=jsHintConfig.json fileToLint.js
Now, I've tried replacing that call with:
rhino jshint-rhino.js --config=jsHintConfig.json fileToLint.js
But it doesn't seem to work. I only get the following printed to the console:
Usage: jshint.js file.js
Does jshint-rhino not accept a json configuration file?
Update:
http://anton.kovalyov.net/2011/03/01/jshint-edition-update/
- Says: "Added support for providing options to JSHint as command line arguments when used with our Rhino wrapper" but doesn't say how.
https://github.com/jshint/jshint/issues/27
- Something about specifying options on the cli, but also doesn't say how.
This worked:
rhino jshint-rhino.js file1.js file2.js opt1=true,opt2=true,opt3=false global1,global2,global3
No need to put a comma between file names and it is important to not have spaces before or after the commas for the options and globals.

Running JSLint from command prompt

I would like to run jsLint from the command prompt.
At a later stage, as a task in an ANT build.
I downloaded rhino 1.7 R3 and the latest jslint.js and wrote this custom test.js which contents is:
for (var i = 0; i < 10; i++) { }
Notice that this single line of code should already cause jslint to warn:
Move 'var' declarations to the top of the function.
I used this command:
java -jar .\rhino1_7R3\js.jar .\douglascrockford-JSLint-e31fa4c\jslint.js .\test.js
Which ran for a couple of seconds and then finished without any output.
My question is -> Am I doing it right? What kind of output should I expect in case of an error?
You might find jslint4java useful as it has a command line interface, wrapping JSLint.
I don't know about Rhino etc, but when using JSLint in pure JS, it creates a JSLINT object, and you need to iterate through JSLINT.errors (which has methods JSLINT.errors[i].line, JSLINT.errors[i].reason, etc). Also, you have to pass your code as a string into the JSLINT function, not just run them both together.

Categories