Team Foundation Server Check-in Policies

SQL Enlight provides a Static Code Analysis Check-in policy, which can be used to control and improve the quality of SQL code that is checked into the codebase.

This topic contains the following sections:

Install and Configure
Note Note

Team Foundation Server check-in policies are evaluated client-side and have to be installed separately on each developers’ machine.

On the other hand, the configuration of a TFS check-in policy can be configured only once as it is stored on the TFS server with the project’s configuration.

The Static Code Analysis Check-in policy is installed and registered in Visual Studio during a typical SQL Enlight installation, but can be removed from the installation using the Custom setup option.

To configure the SQL Enlight policy, do the following:

  1. Make sure SQL Enlight is installed on the machine where the policy is being configured.
  2. Start Visual Studio 2017/2019 and from the main menu select View->Team Explorer.
  3. Select a project in Team Explorer and select from the project’s context menu Team Project Setting->Source Control.
  4. Go to the Check-in Policy tab and add the SQL Enlight Code Analysis Policy.

    policy-5
  5. If SQL Enlight is successfully added, the Policy Settings form should appear. Edit button of the Source Control Settings dialog can also be used to bring the Policy Settings form.

    policy-1
  6. Browse and select an existing analysis template.
  7. The analysis template will be loaded and its rules will appear in the Analysis Rules list.

  8. Select rules that to be used by the policy. Optionally rule parameters can be shown and configured by using the Show Details button.

    Later the selected rules can be modified by using the Edit button of the Source Control Settings dialog.

  9. Optionally configure Include and Exclude regular expression patterns for the policy target files.

    policy-2

    If an Include pattern is provided, the code analysis policy is applied only on the files, which match the pattern, otherwise, all SQL files are included.

    If an Exclude pattern is provided, all the code analysis policy target files, which match the pattern are ignored.

    More than one regular expression patterns can be provided on separate lines. When the pattern is applied, the absolute path of each SQL file under the root source folder is tested.

    For example, both regular expressions will match all SQL files under “SQL Scripts” folder:

    1SQLs+Scripts

    1.*SQLs+Scripts.*.sql

  10. Close the Policy Settings form.

The policy is now configured.

Applying Policy

The configured policy will be activated when any .sql files are being checked-in.

When the policy is activated, a progress window showing the status of the analysis will appear.

If any policy violations are found, they will appear in the Policy Warnings tab.

policy-4

Double-clicking a warning will open the file at the line of the rule violation.