Performing Static Analysis
Use the Analyze command to run static analysis over T-SQL script or SQL Server objects.
This topic contains the following sections:
To configure which rules will be active by default, do the following:
1. Open SQL Enlight > Options dialog and go to the Analysis > Rules tab.
2. Set the checked state of each rule which you want to be active by default.
3. Optionally set default values to rule parameters.
SQL code commands
The static analysis commands are enabled only when there is an active code window as they are applied on the SQL code inside the current code editor.
There are two main analysis commands available under SQL Enlight -> Static Analysis, and SQL Editor’s context menu:
The Analyze with All Rules command can be used to analyze with all default active rules.
The Analyze with Specific Rules… command can be used to select rules which to be applied.
The command will show the following rule selector dialog:
Use the Show Details button to show rule details – see rule description and set rule parameters.
The commands will analyze the selected SQL code or the entire active document if there is no current selection.
Both commands are available on the SQL Enlight menu, SQL Enlight toolbar and SQL Editor’s context menu.
By default, only Batch scoped analysis rules will be applied when analyzing T-SQL documents using the Analyze with All Rules command.
Explicit analysis rules are directly available in the Static Analysis sub-menu.
These rules are managed in the Explicit Rules analysis group and due to their kind are available only to be used separately from the general rules.
1. Right-click an object in SQL Server Management Studio’s Object Explorer to open the context menu.
2. Use the Static Analysis menu to select SQL Enlight command, specific group, or rule. The menu will be available If the selected object or one of its children can be analyzed.
3. If the Analyze with Specific Rules… command is used, specific rules can be selected prior to running the analysis.
4. The command will script the stored procedures, functions, and triggers under the selected object in a new query window and will analyze the resulting script.
By default only Batch scoped analysis rules will be applied when analyzing T-SQL document using the Analyze with All Rules command.
1. Open Solution Explorer in SQL Server Management Studio or Visual Studio.
2. Right-click the target Solution Explorer item to open its context menu. It can be a solution, project, folder which contains SQL file(s), or a single SQL file.
3. To start the analysis use the SQL Enlight context menu item and select one of Analyze with All Rules or Analyze with Specific Rules… commands.
This way all SQL files under the selected Solution Explorer items will be analyzed and the generated rule violations will be added to the SQL Enlight Error List.
Instant Code Analysis feature provides real-time analysis and code issues feedback in the editors of SQL Server Management Studio and Visual Studio.
The analysis is fired a few seconds after a script document is opened for the first time or an opened document has its content changed.
The document is analyzed in the background using the rules in the current analysis template.
The code elements that trigger violations are highlighted in the editor and a complete list of file code issues is added and displayed in the SQL Enlight Error List tool window.
The Details pane of the Error List shows more information about the source and explains the nature of the issue.
The feature can be configured and turned on/off using SQL Enlight Settings, SQL Enlight toolbar, and SQL Enlight main menu.
If there are T-SQL script analysis rules violations, the SQL Enlight Error List Window will be displayed and the violations will be marked in the text editor.
See SQL Enlight Error List for more details.
Several of the analysis rules can be fixed automatically using the Fix context menu command of SQL Enlight Error List.
When a code rule issue is fixed, the fix is applied in the SQL document where the rule issue is found.
As for issues of database rules, a change script is written in a new document that is common for all database issue fixes.
The issues that are successfully fixed are crossed out in the SQL Enlight Error List.