I already have some analyzer and code fix providers defined and looking to find dead code in Visual Basic to clean up our source code. I'm currently struggling to find commented code and determining if they are commented code (dead code) rather than usual comments.
Typical function commented (it could be a multiline comment too, but rarely seen in our code base):
'''' <summary>
'''' This function is unused
'''' </summary>
'''' <returns></returns>
'Public Function IsUnusedFunction() As Boolean
' ' This function always return true
' Return True
'End Function
Does anyone achieve that with Roslyn? I wish I could provide our developers with some analyzers and code fix for that.
EDIT
Here's my DiagnosticAnalyzer code bits that I'm now:
Public Overrides Sub Initialize(pContext As AnalysisContext)
pContext.RegisterSyntaxTreeAction(AddressOf AnalyzeSyntaxTree)
End Sub
Private Async Sub AnalyzeSyntaxTree(pContext As SyntaxTreeAnalysisContext)
Dim lRoot As SyntaxNode = Await pContext.Tree.GetRootAsync(pContext.CancellationToken)
Dim lCommentNodes = lRoot.DescendantTrivia().Where(Function(t) t.IsKind(SyntaxKind.CommentTrivia))
'TODO: Do some logic here to find consecutives comments (ignoring empty line) to perform action
End Sub