Roslyn Analyzers Reference
ALPHA
The analyzer package is currently in alpha. Rule behavior and IDs may change between releases.
This page documents the currently implemented Roslyn analyzer rules in NickSoftware.Switchboard.Analyzers.
Table of Contents
Installation
Install the analyzer package into the project(s) where you write flows:
bash
dotnet add package NickSoftware.Switchboard.AnalyzersThe analyzers are intentionally shipped as a separate NuGet package.
Configuration
Use .editorconfig to tune severity:
ini
[*.cs]
dotnet_diagnostic.SWB002.severity = error
dotnet_diagnostic.SWB011.severity = warning
dotnet_diagnostic.SWB017.severity = noneRule Reference
SWB001: Flow Must Have At Least One Action
- Severity: Error
- Category: Switchboard.Design
csharp
var flow = new FlowBuilder()
.SetName("EmptyFlow")
.Build(); // ❌ SWB001SWB002: Flow Should End With Terminal Action
- Severity: Warning
- Category: Switchboard.Design
csharp
var flow = Flow.Create("IncompleteFlow")
.PlayPrompt("Welcome")
.Build(); // ⚠️ SWB002csharp
var flow = Flow.Create("CompleteFlow")
.PlayPrompt("Welcome")
.Disconnect()
.Build();Code fix: Quick Action can insert .Disconnect() before .Build().
SWB004: Flow Name Must Be Set
- Severity: Error
- Category: Switchboard.Design
csharp
var flow = new FlowBuilder()
.PlayPrompt("Welcome")
.Disconnect()
.Build(); // ❌ SWB004SWB005: Queue Name Cannot Be Empty
- Severity: Error
- Category: Switchboard.Usage
csharp
var flow = Flow.Create("BadQueue")
.PlayPrompt("Transferring...")
.TransferToQueue("") // ❌ SWB005
.Build();SWB006: Prompt Text Is Required
- Severity: Error
- Category: Switchboard.Usage
csharp
var flow = Flow.Create("BadPrompt")
.PlayPrompt(null) // ❌ SWB006
.Disconnect()
.Build();SWB011: Loop Configure Lambda Invalid
- Severity: Error
- Category: Switchboard.Usage
- Meaning:
Loop(..., loop => ...)must define what happens each iteration vialoop.WhileLooping(...).
Invalid (semantic bug): calling normal flow actions directly on loop:
csharp
Flow.Create("Loop Misuse")
.Loop(3, loop =>
{
loop.PlayPrompt("Retrying..."); // ❌ SWB011
})
.Disconnect()
.Build();Valid:
csharp
Flow.Create("Loop Correct")
.Loop(3, loop => loop
.WhileLooping(body => body.PlayPrompt("Retrying..."))
.WhenDone(done => done.Disconnect()))
.Build();SWB012: Wait Configure Lambda Invalid
- Severity: Error
- Category: Switchboard.Usage
- Meaning:
Wait(..., wait => ...)may only call Wait-scoped methods directly onwait.
csharp
Flow.Create("Wait Misuse")
.Wait(10, wait =>
{
wait.PlayPrompt("..."); // ❌ SWB012
})
.Disconnect()
.Build();SWB013: DistributeByPercentage Configure Lambda Invalid
- Severity: Error
- Category: Switchboard.Usage
- Meaning:
DistributeByPercentage(dist => ...)must define at least one routing branch viadist.WithPercentage(...)and/ordist.Otherwise(...).
csharp
Flow.Create("Dist Missing Branches")
.DistributeByPercentage(dist => { }) // ❌ SWB013
.Disconnect()
.Build();SWB014: CheckHoursOfOperation Fluent Usage Invalid
- Severity: Error
- Category: Switchboard.Usage
- Meaning:
CheckHoursOfOperation(...)must configureOnInHours(...),OnOutOfHours(...), andOnError(...)before continuing with normal flow actions.
csharp
Flow.Create("Bad Hours")
.CheckHoursOfOperation("BusinessHours")
.PlayPrompt("We are open") // ❌ SWB014
.Build();csharp
Flow.Create("Good Hours")
.CheckHoursOfOperation("BusinessHours")
.OnInHours(open => open.TransferToQueue("Support"))
.OnOutOfHours(closed => closed
.PlayPrompt("We are currently closed")
.Disconnect())
.OnError(err => err.Disconnect())
.Build();SWB015: CheckStaffing Fluent Usage Invalid
- Severity: Error
- Category: Switchboard.Usage
- Meaning:
CheckStaffing(...),CheckStaffingForQueue(...), andCheckStaffingForAgent(...)must configureOnTrue(...),OnFalse(...), andOnError(...).
SWB016: CheckQueueStatus Fluent Usage Invalid
- Severity: Error
- Category: Switchboard.Usage
- Meaning:
CheckQueueStatus*must configure:- at least one condition (
WhenTimeInQueue*/WhenQueueCapacity) OnNoMatch(...)OnError(...)
- at least one condition (
SWB017: CheckCallProgress Fluent Usage Invalid
- Severity: Error
- Category: Switchboard.Usage
- Meaning:
CheckCallProgress(...)must configure:- at least one outcome branch (
OnCallAnswered/OnVoicemailBeep/OnVoicemailNoBeep/OnNotDetected) OnError(...)
- at least one outcome branch (
Notes / Limitations
- Rules that inspect
configurelambdas analyze inline lambdas only (they don’t follow helper methods). - Some branch-builder rules require configuration to be completed within a single fluent expression.