All Projects → tsqllint → Tsqllint

tsqllint / Tsqllint

Licence: mit
Configurable linting for TSQL

Projects that are alternatives of or similar to Tsqllint

Wemake Python Styleguide
The strictest and most opinionated python linter ever!
Stars: ✭ 1,714 (+1293.5%)
Mutual labels:  linter
Zoe
🌀 Zero-config ESLint toolchain with sensible defaults.
Stars: ✭ 113 (-8.13%)
Mutual labels:  linter
Surelog
SystemVerilog 2017 Pre-processor, Parser, Elaborator, UHDM Compiler. Provides IEEE Design/TB C/C++ VPI and Python AST API.
Stars: ✭ 116 (-5.69%)
Mutual labels:  linter
Swiftdi
SwiftDI the new way to use your dependency in Swift 5.1
Stars: ✭ 107 (-13.01%)
Mutual labels:  linter
Yamllint
A linter for YAML files.
Stars: ✭ 1,750 (+1322.76%)
Mutual labels:  linter
Dockle
Container Image Linter for Security, Helping build the Best-Practice Docker Image, Easy to start
Stars: ✭ 1,713 (+1292.68%)
Mutual labels:  linter
Gopherci
GopherCI was a project to help you maintain high-quality Go projects, by checking each GitHub Pull Request, for backward incompatible changes, and a suite of other third party static analysis tools.
Stars: ✭ 105 (-14.63%)
Mutual labels:  linter
Eyo
🦔 CLI for restoring the letter «ё» (yo) in russian texts
Stars: ✭ 119 (-3.25%)
Mutual labels:  linter
Abaplint
Standalone linter for ABAP
Stars: ✭ 111 (-9.76%)
Mutual labels:  linter
Dbatools
🚀 SQL Server automation and instance migrations have never been safer, faster or freer
Stars: ✭ 1,742 (+1316.26%)
Mutual labels:  mssql
Import Linter
Import Linter allows you to define and enforce rules for the internal and external imports within your Python project.
Stars: ✭ 105 (-14.63%)
Mutual labels:  linter
Next
Directus is a real-time API and App dashboard for managing SQL database content. 🐰
Stars: ✭ 111 (-9.76%)
Mutual labels:  mssql
Cfn Python Lint
CloudFormation Linter
Stars: ✭ 1,770 (+1339.02%)
Mutual labels:  linter
Npm Package Json Lint
Configurable linter for package.json files
Stars: ✭ 106 (-13.82%)
Mutual labels:  linter
Editorconfig Checker
A tool to verify that your files are in harmony with your .editorconfig
Stars: ✭ 119 (-3.25%)
Mutual labels:  linter
Doc8
Style checker for sphinx (or other) rst documentation.
Stars: ✭ 105 (-14.63%)
Mutual labels:  linter
Cargo Deadlinks
Cargo subcommand for checking your documentation for broken links
Stars: ✭ 113 (-8.13%)
Mutual labels:  linter
Liche
Fast Link Checker for Markdown and HTML in Go
Stars: ✭ 123 (+0%)
Mutual labels:  linter
Lesshint
A tool to aid you in writing clean and consistent Less.
Stars: ✭ 119 (-3.25%)
Mutual labels:  linter
Flint
Fast and configurable filesystem (file and directory names) linter
Stars: ✭ 115 (-6.5%)
Mutual labels:  linter

Build Status Coverage Status

npm version npm Gitter chat

TSQLLint

TSQLLint is a tool for describing, identifying, and reporting the presence of anti-patterns in TSQL scripts.

Installation

For OSX and Linux the recommended method of installing TSQLLint is to install the tool using homebrew.

$ brew tap tsqllint/homebrew-tsqllint
$ brew install tsqllint

TSQLLint may also be installed with NPM

This binary can be installed though the npm registry. First, install Node.js version 4 or higher, and then install using the npm install command:

npm install tsqllint -g

Usage

# lint a single file
tsqllint test.sql

# lint all files in a directory
tsqllint c:\database_scripts

# lint a list of files and directories, paths with whitespace must be enclosed in quotes
tsqllint file_one.sql file_two.sql "c:\database scripts"

# lint using wild cards
tsqllint c:\database_scripts\sp_*.sql

# print path to .tsqllintrc config file
tsqllint --print-config

# display usage info
tsqllint --help

# list the plugins loaded
tsqllint --list-plugins

Integrating TSQLLint with other Tools

Visual Studio Code Extension

In addition to the CLI tool, TSQLLint is built into a Visual Studio Code Extension. This extension can be installed from within the VS Code Extension Interface or from the VS Code Extension marketplace.

Usage Example

SQL Server Management Studio

TSQLLint uses a common message format that allows for integration into off the shelf tools. SQL Server Management Studio can use TSQLLint using SSMS's External Tools feature.

SSMS Integration Image

Configuration

TSQLLint utilizes a configuration file called .tsqllintrc. This file can be generated and edited by users to create their own configurations. To generate this file use the -i or --init flags. If no .tsqllintrc is found the tool will use a default configuration loaded in memory.

# generate a default .tsqllintrc file using the init flag (optional if just using a default configuration)
tsqllint --init

Creating custom configurations

To configure TSQLLint edit its config file, which is named .tsqllintrc. To find its location run tsqllint with the --print-confg or -p option.

TSQLLint will load its config file in the following order or precedence:

  1. The value passed with the -c command line argument, if one is passed
  2. An Environment Variable named TSQLLINTRC
  3. A file named .tsqllintrc in the same local directory in which TSQLLint is executing
  4. A file named .tsqllintrc in the user's home directory

Rule configuration

TSQLLint rules may be set to "off", "warning", or "error". Rules that are violated and are set to "error" will result in TSQLLint returning a non-zero exit code. Rules that are violated, but configured to "warning" will result in a zero exit code, but a warning message will be displayed in the shell output. Rules that are set to "off" will be completely ignored. Rules that are not present in the .tsqllintrc configuration are set to "off"

{
  "rules": {
    "conditional-begin-end": "error",
    "cross-database-transaction": "error",
    "data-compression": "error",
    "data-type-length": "error",
    "disallow-cursors": "error",
    "full-text": "error",
    "information-schema": "error",
    "keyword-capitalization": "error",
    "linked-server": "error",
    "multi-table-alias": "error",
    "named-constraint": "error",
    "non-sargable": "error",
    "object-property": "error",
    "print-statement": "error",
    "schema-qualify": "error",
    "select-star": "error",
    "semicolon-termination": "error",
    "set-ansi": "error",
    "set-nocount": "error",
    "set-quoted-identifier": "error",
    "set-transaction-isolation-level": "error",
    "set-variable": "error",
    "upper-lower": "error",
    "unicode-string": "error"
  }
}

Disabling Rules with Inline Comments

To temporarily disable all rule warnings in a script, use comments in the following format:

/* tsqllint-disable */

SELECT * FROM FOO;

/* tsqllint-enable */

To disable or enable warnings for specific rules:

/* tsqllint-disable select-star */

SELECT * FROM FOO;

/* tsqllint-enable select-star */

To disable warnings for the entire script, place a /_ tsqllint-disable _/ comment at the top of the file:

/* tsqllint-disable */

SELECT * FROM FOO;

To disable specific rule warnings for the entire script place a comment similar to the following at the top of the file:

/* tsqllint-disable select-star */

SELECT * FROM FOO;

SQL Compatibility Level

TSQLLint provides a configurable "compatibility-level" that aligns with SQL Server's Compatibility Level. The value defaults to 120 but may be changed with the following edit to the .tsqllintrc or by using inline comments within the SQL file. TSQLLint supports the following compatibility levels 80, 90, 100, 110, 120, 130, 140, and 150.

Setting a default Compatability Level using .tsqllintrc

Setting the compatability level within the .tsqllintrc file configures the default Compatability Level for all files.

{
  "rules": {
    "upper-lower": "error"
  },
  "compatability-level": 90
}

Setting Compatability Level Using Inline Comments

Setting the compatability level using inline comments configures the Compatability Level for just that file. Overrides should be placed at the top of files.

/* tsqllint-override compatability-level = 130 */

SELECT * FROM FOO;

SQL Placeholders

Many tools in the SQL ecosystem support placeholders to templatize SQL files as shown in the example below:

SELECT * FROM FOO WHERE BAR = '$(MyPlaceholderValue)';

Before applying any linting rules, TSQLLint will replace any placeholder in a SQL file with values provided via environment variables.

Plugins

You can extend the base functionality of TSQLLint by creating a custom plugin. TSQLLint plugins are Dotnet assemblies that implement the IPlugin interface from TSQLLint.Common. Ensure the plugin is targeting netcoreapp2.0.

After developing the plugin, update the .tsqllintrc file to point to its .dll.

{
  "rules": {
    "upper-lower": "error"
  },
  "plugins": {
    "my-first-plugin": "c:/users/someone/my-plugins/my-first-plugin.dll",
    "my-second-plugin": "c:/users/someone/my-plugins/my-second-plugin.dll/"
  }
}

This sample plugin notifies users that spaces should be used rather than tabs.

using System;
using TSQLLint.Common;
using System.IO;

namespace TSQLLint.Tests.UnitTests.PluginHandler
{
    public class SamplePlugin : IPlugin
    {
        public void PerformAction(IPluginContext context, IReporter reporter)
        {
            string line;
            var lineNumber = 0;

			var reader = new IO.StreamReader(File.OpenRead(context.FilePath));

            while ((line = reader.ReadLine()) != null)
            {
                lineNumber++;
                var column = line.IndexOf("\t", StringComparison.Ordinal);
                reporter.ReportViolation(new SampleRuleViolation(
                    context.FilePath,
                    "prefer-tabs",
                    "Should use spaces rather than tabs",
                    lineNumber,
                    column,
                    RuleViolationSeverity.Warning));
            }
        }
    }

    class SampleRuleViolation : IRuleViolation
    {
        public int Column { get; private set; }
        public string FileName { get; private set; }
        public int Line { get; private set; }
        public string RuleName { get; private set; }
        public RuleViolationSeverity Severity { get; private set; }
        public string Text { get; private set; }

        public SampleRuleViolation(string fileName, string ruleName, string text, int lineNumber, int column, RuleViolationSeverity ruleViolationSeverity)
        {
            FileName = fileName;
            RuleName = ruleName;
            Text = text;
            Line = lineNumber;
            Column = column;
            Severity = ruleViolationSeverity;
        }
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].