SQL DBA Linter
A VSCode extension that validates SQL scripts against common DBA rules and best practices.

Features
- USE Statement Validation: Ensures scripts begin with a
USE {DATABASE} statement
- Three-Part Naming Convention: Validates that table references use
{DATABASE}.{SCHEMA}.{TABLE} format
- OR Operator Detection: Flags usage of OR operators
- ORDER BY Detection: Flags usage of ORDER BY clauses
All violations appear in the Problems panel and can be navigated using F8 (next error) and Shift+F8 (previous error).
Configuration
Configure the linter in your VSCode settings:
sqlDbaLinter.requireUseStatement: Require USE statement at script beginning (default: true)
sqlDbaLinter.requireThreePartNaming: Require three-part naming for tables (default: true)
sqlDbaLinter.disallowOrOperator: Disallow OR operators (default: true)
sqlDbaLinter.disallowOrderBy: Disallow ORDER BY clauses (default: true)
sqlDbaLinter.disallowCountStar: Disallow COUNT(*) usage in queries (default: true)
Installation
For Development
- Open this folder in VSCode
- Run
npm install
- Press F5 to launch Extension Development Host
For Distribution
- Install vsce:
npm install -g @vscode/vsce
- Package the extension:
vsce package
- Share the generated
.vsix file with your team
- Install via: Extensions view → ... menu → Install from VSIX
Usage
Open any .sql file and the linter will automatically validate it. Errors will appear:
- In the Problems panel (View → Problems)
- As squiggles in the editor
- Navigate with F8 (next) / Shift+F8 (previous)
Testing
Running Tests
Run the test suite using:
npm test
This will:
- Compile the TypeScript code
- Run ESLint
- Execute all unit tests in a VS Code test environment
Running Tests in Watch Mode
For development, you can run tests in watch mode:
npm run watch
Then press F5 in VS Code to launch the test runner.
Test Structure
Tests are located in src/test/suite/ and follow the naming convention *.test.ts. The test suite uses:
- Mocha - Test framework
- VS Code Test API - For testing extension code in a real VS Code environment
Writing New Tests
- Create a new file in
src/test/suite/ with the suffix .test.ts
- Import the necessary modules and the code to test
- Use Mocha's
suite() and test() functions to organize tests
- Run
npm test to execute your tests
Example:
import * as assert from 'assert';
import * as vscode from 'vscode';
suite('My Test Suite', () => {
test('My test case', () => {
assert.strictEqual(1 + 1, 2);
});
});