Skip to content

Tern & JSDoc support

Angelo edited this page Sep 9, 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, go at Tern project property, go at Tern project property, 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, the Lint validator is able to validate your JavaScript files by using JSDoc annotations :

Assignment validation

Here a sample with assignment type error :

Validation with JSDoc

Function call validation

Here a sample with function parameter type error:

Validation with JSDoc

Clone this wiki locally