Skip to content

Tern & JSDoc support

angelozerr edited this page Jun 19, 2015 · 15 revisions

tern.js provides the doc_comment tern plugin which gives a support for JSDoc.

After installing and converting your project as Tern Project (see Tern-Eclipse-IDE), open Project Properties, click on Tern / Modules item and select the JSDoc Support tern plugin :

Check JSDoc Plugin

After that, tern can use the JSDoc tags. Here a sample which assign the test variable as String type by using @type :

JSDoc String type

Options

The JSDoc support can be configured with several options.

strong option

The strong option can be set to true to assign a higher-than-default weight to the types it finds in comments, and thus overrides inferred types.

Takes a sample. If you assign the test variable with a number value, test has 2 types :

  • String coming from the JSDoc.
  • Number coming from the written code assignment.

Several types without strong

If you wish to ignore the type coming from the written code assignment and just use the type coming from the JSDoc, you must check the strong option :

Check Strong option

After that, your test variable will have just types coming from JSDoc (the toExponential method doesn't appear in the completion popup):

Several types with strong

Validation

To validate your JavaScript files with JSDoc annotations, you must :

After that you tern-lint will use JSDoc annotations to validate your JavaScript files :

Validation with JSDoc

Clone this wiki locally