Tuning JavaScript analysis

Tuning allows you to make JavaScript analysis respect specifics of the project and bring it closer to the project context. You can tune your JavaScript analysis by giving the parameters to the engine, so it can produce better analysis results about your code system.

The tuning mechanism is implemented by passing arguments to a particular <error>. Every JavaScript checker has a list of parameters that are supported; you can define these parameters and import it into your project configuration.

Adding parameters and importing them into Klocwork involves the following steps:

  • Find the documentation of the relevant checker that you want to tune; there is a list of parameters that can be tuned. If there are no parameters listed, then the checker cannot be tuned.

  • Create a '.pconf' checker configuration file and add parameters for the <error> tag. JavaScript parameters are positional and should be named with the arg<number> approach (for example, “arg1”). Parameters are numbered starting from “1” and the number refers to the position of the parameter in eslint checker configuration.

  • Import the '.pconf' file into the project.

Example

/*eslint indent: ["error", 2, { "SwitchCase": 1 }] */

Should be added to the '.pconf' file as follows:

Copy
<error id="JS.BASE.INDENT" enabled="true">
    <parameter name="arg1" value="2"/>
    <parameter name="arg2" value="{&quot;SwitchCase&quot;: 1}" />
</error>

Note: The parameter value should be xml-escaped.

Import the .pconf file into your project. For example, using the kwadmin import-config command:

kwadmin import-config myProject C:\Klocwork\JavaScriptchecker.pconf