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.
Related
Mysupername is the value that got printed out and not the expected output.
I already tried reinstalling it. I used npm install prompt -sync to use it with JavaScript inside Visual Studio Code but I don't know where I am going wrong. I have already added the variables in system advanced setting.
Visual Studio Code error message if I try to use prompt or alert inside and run through code runner extension:
There's a slight mistake with your code. Firstly, the reason why it is printing Mysupername to the console is because you provided console.log with a string. Instead just provide the variable name like this:
const superheroes = require('superheroes');
var Mysupername = superheroes.random();
console.log(Mysupername);
Now, the reason why prompt isn't working is because you never imported the library into your code, you can do it by the following:
const prompt = require("prompt");
Final note, alert is only available when running javascript through a browser.
I have a Lerna monorepo with 2 modules(packages): ps and cli.
ps just exports a function whatever which cli imports.
When I try to debug this code using VSCode, however, my breakpoints stop on the generated Javascript files instead of my source Typescript files.
This has bothered me for hours and I have extensively played around with my tsconfig.json and launch.json as well as using vscode-pwa-analyzer to see that VSCode is able to detect my source TS code but I cannot figure out a fix.
EDIT: I am using the following setup:
macOS Big Sur v11.1
Node.js v14.8.0
Typescript v4.1.3
And here is a dump file of my above debug you can load to vscode-pwa-analyzer.
I can see here that I get some Unbound Breakpoint errors.
I replicated the problem, but I would say that this is the expected behavior.
Actually setting a breakpoint on a function declaration makes no sense.
If you change your whatever function as a sync function (i.e. function whatever(): void) you will see that VSCode doesn't let you to break on that line.
In the special case of an async function we know that the function body is actually wrapped in a Promise. Probably in this special case the typescript debugger let us to set a breakpoint on a function declaration line to let us check what happens outside the Promise wrap.
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.
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).
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?