One of the things that makes legacy code hard to understand is all of the extra noise. A lot of developers (myself included) will comment out a line of code rather than delete it.
I wrote this little script to clean up the comments and white space. This macro combined with the format document command in Visual Studio do wonders for readability.
Public Sub RemoveVerticalWhiteSpace()
DTE.UndoContext.Open( _
"RemoveVerticalWhitespace")
txt = DTE.ActiveDocument.Selection
lines = Split(txt.Text, vbLf)
txt.Delete()
props = DTE.Properties( _
"Environment", _
"TaskList")
tokens = props.Item("CommentTokens").Value
For Each line In lines
If ShouldPrint(line, tokens) Then
txt.Insert(line)
End If
Next
DTE.UndoContext.Close()
End Sub
Private Function ShouldPrint( _
ByVal line, _
ByVal tokens)
If String.IsNullOrEmpty(line.Trim()) Then
Return False
End If
If line.Trim.StartsWith("'") Then
If line.Trim.StartsWith("'''") Then
Return True
End If
For Each t In tokens
t = "'" & t.ToUpper().Split(":")(0)
l = line.Trim.ToUpper()
If l.StartsWith(t) Then
Return True
End If
Next
Return False
End If
Return True
End Function
0 comments:
Post a Comment