T-SQL Rule Implementer
Implement a new linting rule from scratch using TDD methodology.
Workflow
- •Understand the requirement: Clarify what SQL pattern should be detected and why
- •Check for existing rules: Search
src/TsqlRefine.Rules/Rules/to avoid duplicating existing rules - •Study a similar rule: Read the most similar existing rule and its tests for patterns to follow
- •Write tests first in
tests/TsqlRefine.Rules.Tests/{Category}/{RuleName}RuleTests.cs- •Include SQL that should trigger violations (positive cases)
- •Include SQL that should NOT trigger violations (negative cases)
- •Check expected diagnostic count, message, and position
- •Implement the rule in
src/TsqlRefine.Rules/Rules/{Category}/{RuleName}Rule.cs- •Prefer AST-based (visitor pattern) over token-based
- •Use helpers from
src/TsqlRefine.Rules/Helpers/— never duplicate common logic - •See
.claude/rules/rules-development.mdfor templates and helper reference
- •Register the rule in
src/TsqlRefine.Rules/BuiltinRuleProvider.cs - •Add sample SQL in
samples/sql/{rule-id}.sql - •Run specific tests:
dotnet test --filter "FullyQualifiedName~{RuleName}Tests" - •Run full suite:
dotnet test src/TsqlRefine.sln -c Release - •Smoke test via CLI:
echo "<test SQL>" | dotnet run --project src/TsqlRefine.Cli -c Release -- lint --stdin --output json
Naming
| Type | Pattern | Example |
|---|---|---|
| Rule class | PascalCase + "Rule" | AvoidSelectStarRule |
| Test class | PascalCase + "RuleTests" | AvoidSelectStarRuleTests |
| Rule ID | kebab-case | avoid-select-star |
| Visitor | Private nested + "Visitor" | AvoidSelectStarVisitor |
Rules
- •Always write tests before implementation (TDD)
- •All tests must pass before considering the task done
- •Use
FrozenSet/FrozenDictionaryfor static lookup collections