Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSDoc - how to check types for JavaScript in Eclipse?

I am applying JSDoc annotations:

/**
 * @param {number} millis
 * @param {function} callback
 * */
function sleep(millis, callback) {
    setTimeout(function() {
        callback();
    }, millis);
}

Then what tool would tell there is an error for line below?

sleep('aaa', 'sdsdsd');

Is JSHint aware of JSDoc type annotations? How to enable such support in Eclipse?

like image 301
Paul Verest Avatar asked Sep 07 '25 16:09

Paul Verest


2 Answers

jshint is not aware of jsdoc comments. You could however look at using eslint and writing a plugin for it that would perform type checking on function calls. Depending on how your project is set up you might end up having to pre-parse your code to extract the comments into a rules file that your eslint rule would use.

like image 70
Jason Aller Avatar answered Sep 10 '25 09:09

Jason Aller


Disclaimer, I'm the author of tern.java.

I suggest you that you install tern.java 1.0.0-SNAPSHOT. It provides the capability to validate your JavaScript files by using JSDoc annotations. Here a screenshot with the sample of this issue :

enter image description here

If you need improvement with JSDoc validation, please create issues here

like image 39
Angelo Avatar answered Sep 10 '25 08:09

Angelo