ReSharper Help

Code Analysis in JavaScript

The key features of ReSharper's code analysis are also supported in JavaScript. You can find the detailed information on these features in the corresponding topics of the Code Analysis section. In the main topic of the section, you can also find the feature matrix and check what exactly is supported in JavaScript.

In this topic, you can find some examples of using code analysis features in JavaScript:

Code inspection

To look through the list of available inspections for JavaScript, open the Code Inspections | Inspection Severity options page, and then switch to the JS tab.

ReSharper_by_Language__JavaScript__Highlighting__Inspection_Severity

To find out whether the opened file contains errors or warnings, look at the Status Indicator, a colored icon at the top of the Marker Bar. You can place the mouse pointer over the Status Indicator and look at the tooltip to see the number of errors in the file.

After you get the summary information, you can concentrate on concrete problems. Choose one of the markers on the status bar and place the mouse pointer over it and get a tip about the issue. Click the marker to navigate directly to the code line.

As you see parameter context is displayed in grey:

ReSharper_by_Language__JavaScript__Highlighting__Code_highlighting_01
ReSharper_by_Language__JavaScript__Highlighting__Code_highlighting_02

At any time you can change the severity level of an inspection. The visual representation of the inspection changes correspondingly. If yuu set the 'Error' severity level for this inspection, the parameter is highlighted with a curly red underline:

ReSharper_by_Language__JavaScript__Highlighting__Code_highlighting_03

Resolving global variables

ReSharper highlights usages of undefined variables as warnings. THere are cases, however, when these usages are valid. For instance, some variables can be defined directly in the markup.

One way to deal with this, is to disable or suppress the corresponding code inspection. However, you can define such variables using the // global comment. In this case, the inspection will stay active and help you to find typos in variable names.

You can place these comments either at the top of the current file or use a single file for all global variables of the project. Each variable requires a new comment, e.g.: // global variableName

Examples of quick-fixes

Terminate all unterminated statements in file
Use this quick-fix in order to terminate all unterminated JavaScript statements in current file.

ReSharper_by_Language__JavaScript__Quick-Fixes__terminate_unterminated_statements_01

Specify qualifier explicitly
In case an explicit quialifier is missing, use this quick-fix to add a qualifier.

ReSharper_by_Language__JavaScript__Quick-Fixes__specify_qualifier_explicitly_01

Remove parameter
If a parameter is not used inside function body, this quick-fix will remove the parameter from function declaration

ReSharper_by_Language__JavaScript__Quick-Fixes__remove_parameter_01

Declare local variable
When ReSharper finds out that a variable has been assigned without being declared, use this quick-fix to transform the assignment into a variable declaration.

ReSharper_by_Language__JavaScript__Quick-Fixes__declare_local_variable_01
After applying this quick-fix the statement is a proper variable declaration.
ReSharper_by_Language__JavaScript__Quick-Fixes__declare_local_variable_02

See Also

Last modified: 30 June 2015