{"id":13594301,"url":"https://github.com/tsqllint/tsqllint","last_synced_at":"2025-04-07T05:06:57.946Z","repository":{"id":22504478,"uuid":"91122741","full_name":"tsqllint/tsqllint","owner":"tsqllint","description":"Configurable linting for TSQL","archived":false,"fork":false,"pushed_at":"2024-09-18T11:51:33.000Z","size":4753,"stargazers_count":214,"open_issues_count":16,"forks_count":74,"subscribers_count":12,"default_branch":"main","last_synced_at":"2024-10-30T04:49:49.263Z","etag":null,"topics":["linter","mssql","tsql"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tsqllint.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.MD","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-12T19:19:15.000Z","updated_at":"2024-10-06T02:11:17.000Z","dependencies_parsed_at":"2023-02-10T19:31:29.649Z","dependency_job_id":"7c58fe54-b0ad-4370-90dd-264a94f26734","html_url":"https://github.com/tsqllint/tsqllint","commit_stats":{"total_commits":364,"total_committers":30,"mean_commits":"12.133333333333333","dds":0.6318681318681318,"last_synced_commit":"00cda7aee6edd7ba6c4991ee03c8d681ebaa0afc"},"previous_names":[],"tags_count":55,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsqllint%2Ftsqllint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsqllint%2Ftsqllint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsqllint%2Ftsqllint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsqllint%2Ftsqllint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tsqllint","download_url":"https://codeload.github.com/tsqllint/tsqllint/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247438086,"owners_count":20938861,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["linter","mssql","tsql"],"created_at":"2024-08-01T16:01:31.481Z","updated_at":"2025-04-07T05:06:57.929Z","avatar_url":"https://github.com/tsqllint.png","language":"C#","funding_links":[],"categories":["C#","C\\#","SQL Server Web Resources","SQL"],"sub_categories":["Analyzers"],"readme":"\n[![CircleCI](https://circleci.com/gh/tsqllint/tsqllint/tree/main.svg?style=svg)](https://circleci.com/gh/tsqllint/tsqllint/tree/main)\n[![Coverage Status](https://coveralls.io/repos/github/tsqllint/tsqllint/badge.svg?branch=main)](https://coveralls.io/github/tsqllint/tsqllint?branch=main)\n[![npm version](https://badge.fury.io/js/tsqllint.svg)](https://badge.fury.io/js/tsqllint)\n[![npm](https://img.shields.io/npm/dt/tsqllint.svg)](https://www.npmjs.com/package/tsqllint)\n\n# TSQLLint\n\nTSQLLint is a tool for describing, identifying, and reporting the presence of anti-patterns in TSQL scripts.\n\n## Installation\n\nTSQLLint currently officially supports installation with dotnet-tool, Homebrew, and NPM.\n\n### Install with dotnet tool\n\n```\n$ dotnet tool install --global TSQLLint\n```\n\n### Install with Homebrew\n\nFor OSX and Linux the recommended method of installing TSQLLint is to install the tool using homebrew.\n\n```shell\n$ brew tap tsqllint/homebrew-tsqllint\n$ brew install tsqllint\n```\n\n### Upgrade with Homebrew\n\n```shell\n$ brew upgrade tsqllint \n```\n\n### Install with NPM\n\nTSQLLint may also be installed with NPM\n\nThis binary can be installed though [the `npm` registry](https://www.npmjs.com/). First, install [Node.js version 4 or higher](https://nodejs.org/en/download/), and then install using the [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):\n\n```bash\nnpm install tsqllint -g\n```\n\n## Usage\n\n```bash\n# lint a single file\ntsqllint test.sql\n\n# fix all auto-fixable problems (--fix or -x)\ntsqllint --fix test.sql\n\n# lint all files in a directory\ntsqllint c:\\database_scripts\n\n# lint a list of files and directories, paths with whitespace must be enclosed in quotes\ntsqllint file_one.sql file_two.sql \"c:\\database scripts\"\n\n# lint using wild cards\ntsqllint c:\\database_scripts\\sp_*.sql\n\n# print path to .tsqllintrc config file\ntsqllint --print-config\n\n# display usage info\ntsqllint --help\n\n# list the plugins loaded\ntsqllint --list-plugins\n```\n\n## Integrating TSQLLint with other Tools\n\n### Visual Studio Code Extension\n\nIn addition to the CLI tool, TSQLLint is built into a [Visual Studio Code Extension](https://marketplace.visualstudio.com/items?itemName=tsqllint.tsqllint). This extension can be installed from within the VS Code Extension Interface or from the VS Code Extension marketplace.\n\n![Usage Example](documentation/usage-animation.gif?raw=true)\n\n### SQL Server Management Studio\n\nTSQLLint 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.\n\n![SSMS Integration Image](documentation/SSMSIntegrationScreenshot.PNG)\n\n## Configuration\n\nTSQLLint 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.\n\n```bash\n# generate a default .tsqllintrc file using the init flag (optional if just using a default configuration)\ntsqllint --init\n```\n\n## Creating custom configurations\n\nTo configure TSQLLint edit its config file, which is named `.tsqllintrc`. To find its location run `tsqllint` with the `--print-confg` or `-p` option.\n\nTSQLLint will load its config file in the following order or precedence:\n\n1. The value passed with the `-c` command line argument, if one is passed\n2. An Environment Variable named `TSQLLINTRC`\n3. A file named `.tsqllintrc` in the same local directory in which TSQLLint is executing\n4. A file named `.tsqllintrc` in the user's home directory\n\n## Rule configuration\n\nTSQLLint 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\"\n\n```json\n{\n  \"rules\": {\n    \"case-sensitive-variables\": \"error\",\n    \"conditional-begin-end\": \"error\",\n    \"count-star\": \"error\",\n    \"cross-database-transaction\": \"error\",\n    \"data-compression\": \"error\",\n    \"data-type-length\": \"error\",\n    \"delete-where\": \"error\",\n    \"disallow-cursors\": \"error\",\n    \"full-text\": \"error\",\n    \"information-schema\": \"error\",\n    \"keyword-capitalization\": \"error\",\n    \"linked-server\": \"error\",\n    \"multi-table-alias\": \"error\",\n    \"named-constraint\": \"error\",\n    \"non-sargable\": \"error\",\n    \"object-property\": \"error\",\n    \"print-statement\": \"error\",\n    \"schema-qualify\": \"error\",\n    \"select-star\": \"error\",\n    \"semicolon-termination\": \"error\",\n    \"set-ansi\": \"error\",\n    \"set-nocount\": \"error\",\n    \"set-quoted-identifier\": \"error\",\n    \"set-transaction-isolation-level\": \"error\",\n    \"set-variable\": \"error\",\n    \"update-where\": \"error\",\n    \"upper-lower\": \"error\",\n    \"unicode-string\": \"error\"\n  }\n}\n```\n\n## Disabling Rules with Inline Comments\n\nTo temporarily disable all rule warnings in a script, use comments in the following format:\n\n```tsql\n/* tsqllint-disable */\n\nSELECT * FROM FOO;\n\n/* tsqllint-enable */\n```\n\nTo disable or enable warnings for specific rules:\n\n```tsql\n/* tsqllint-disable select-star */\n\nSELECT * FROM FOO;\n\n/* tsqllint-enable select-star */\n```\n\nTo disable warnings for the entire script, place a /_ tsqllint-disable _/ comment at the top of the file:\n\n```tsql\n/* tsqllint-disable */\n\nSELECT * FROM FOO;\n```\n\nTo disable specific rule warnings for the entire script place a comment similar to the following at the top of the file:\n\n```tsql\n/* tsqllint-disable select-star */\n\nSELECT * FROM FOO;\n```\n\n## SQL Compatibility Level\n\nTSQLLint provides a configurable \"compatibility-level\" that aligns with [SQL Server's Compatibility Level](http://docs.microsoft.com/en-us/sql/relational-databases/databases/view-or-change-the-compatibility-level-of-a-database). 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.\n\n### Setting a default Compatibility Level using .tsqllintrc\n\nSetting the compatibility level within the `.tsqllintrc` file configures the default Compatibility Level for all files.\n\n```json\n{\n  \"rules\": {\n    \"upper-lower\": \"error\"\n  },\n  \"compatibility-level\": 90\n}\n```\n\n### Setting Compatibility Level Using Inline Comments\n\nSetting the compatibility level using inline comments configures the Compatibility Level for just that file. Overrides should be placed at the top of files.\n\n```tsql\n/* tsqllint-override compatibility-level = 130 */\n\nSELECT * FROM FOO;\n```\n\n## SQL Placeholders\n\nMany tools in the SQL ecosystem support placeholders to templatize SQL files as shown in the example below:\n\n```tsql\nSELECT * FROM FOO WHERE BAR = '$(MyPlaceholderValue)';\n```\n\nBefore applying any linting rules, TSQLLint will replace any placeholder in a SQL file with values provided via environment variables.\n\n## Plugins\n\nYou 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](https://www.nuget.org/packages/TSQLLint.Common/). Ensure the plugin is targeting `net6.0`.\n\nAfter developing the plugin, update the .tsqllintrc file to point to its `.dll`.\n\n```json\n{\n  \"rules\": {\n    \"upper-lower\": \"error\"\n  },\n  \"plugins\": {\n    \"my-first-plugin\": \"c:/users/someone/my-plugins/my-first-plugin.dll\",\n    \"my-second-plugin\": \"c:/users/someone/my-plugins/my-second-plugin.dll/\"\n  }\n}\n```\n\nThis sample plugin notifies users that spaces should be used rather than tabs.\n\n```csharp\nusing System;\nusing System.Collections.Generic;\nusing System.IO;\nusing Microsoft.SqlServer.TransactSql.ScriptDom;\nusing TSQLLint.Common;\n\nnamespace TSQLLint_Sample_Plugin\n{\n    public class SamplePlugin : IPlugin\n    {\n        // This method is required but can be a no-op if using the GetRules method to parse code through the plugin's rules.\n        public void PerformAction(IPluginContext context, IReporter reporter)\n        {\n            string line;\n            var lineNumber = 0;\n\n\t\t\tvar reader = new IO.StreamReader(File.OpenRead(context.FilePath));\n\n            while ((line = reader.ReadLine()) != null)\n            {\n                lineNumber++;\n                var column = line.IndexOf(\"\\t\", StringComparison.Ordinal);\n                reporter.ReportViolation(new SampleRuleViolation(\n                    context.FilePath,\n                    \"prefer-tabs\",\n                    \"Should use spaces rather than tabs\",\n                    lineNumber,\n                    column,\n                    RuleViolationSeverity.Warning));\n            }\n        }\n\n        // Starting with TSQLLint.Common version 3.3.0, this method can be used to return rules to be used by the TSQLLint parser.\n        public IDictionary\u003cstring, ISqlLintRule\u003e GetRules() =\u003e new Dictionary\u003cstring, ISqlLintRule\u003e\n        {\n            [\"sample-plugin-rule\"] = new SampleRule((Action\u003cstring, string, int, int\u003e)null)\n        };\n    }\n\n    class SampleRuleViolation : IRuleViolation\n    {\n        public int Column { get; set; }\n        public string FileName { get; private set; }\n        public int Line { get; set; }\n        public string RuleName { get; private set; }\n        public RuleViolationSeverity Severity { get; private set; }\n        public string Text { get; private set; }\n\n        public SampleRuleViolation(string fileName, string ruleName, string text, int lineNumber, int column, RuleViolationSeverity ruleViolationSeverity)\n        {\n            FileName = fileName;\n            RuleName = ruleName;\n            Text = text;\n            Line = lineNumber;\n            Column = column;\n            Severity = ruleViolationSeverity;\n        }\n    }\n\n    class SampleRule : TSqlFragmentVisitor, ISqlLintRule\n    {\n        protected readonly Action\u003cstring, string, int, int\u003e ErrorCallback;\n\n        public SampleRule(Action\u003cstring, string, int, int\u003e errorCallback)\n        {\n            ErrorCallback = errorCallback;\n        }\n\n        public string RULE_NAME =\u003e \"sample-plugin-rule\";\n        public string RULE_TEXT =\u003e \"Sample plugin rule message text\";\n        public RuleViolationSeverity RULE_SEVERITY =\u003e RuleViolationSeverity.Warning;\n\n        public override void Visit(TSqlScript node)\n        {\n            var line = 0;\n            var column = 0;\n\n            // Logic for testing TSQL code for rule goes here.\n\n            ErrorCallback(RULE_NAME, RULE_TEXT, line, column);\n        }\n\n        public void FixViolation(List\u003cstring\u003e fileLines, IRuleViolation ruleViolation, FileLineActions actions)\n        {\n            // Logic for fixing rule violation goes here.\n        }\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsqllint%2Ftsqllint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftsqllint%2Ftsqllint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsqllint%2Ftsqllint/lists"}