We already have an EmptyStringLiteralListener:
````csharp
public class EmptyStringLiteralListener : VBAParserBaseListener
{
private readonly IList
new List
public IEnumerable<VBAParser.LiteralExpressionContext> Contexts { get { return _contexts; } }
public override void ExitLiteralExpression(VBAParser.LiteralExpressionContext context)
{
var literal = context.STRINGLITERAL();
if (literal != null && literal.GetText() == "\"\"")
{
_contexts.Add(context);
}
}
}
````
Trivial, right? Right now the only thing interested in literals is the EmptyStringLiteralInspection. If we expanded this listener to capture more literal tokens, we could have an inspection that detects repeated literals in a given scope, or across multiple scopes, and suggests introducing procedure or module level constants.
Do you have any specific examples of inspections you'd like done? This is an extremely vague issue.
Here's a simple procedure and module level example:
'Module1
Public Sub Foo()
Dim sourceFileName As String
Dim targetFileName As String
sourceFileName = "SalesReport" & Format$(Now(), "YYYYMMDD") & ".xlsm"
targetFileName = "SummaryReport" & Format$(Now(), "YYYYMMDD") & ".xlsm"
DoSomething sourceFileName, targetFileName
End Sub
Sub Bar()
Debug.Print Format$(Now(), "YYYYMMDD"), "Bar was called"
End Sub
Would become:
Private Const ISODateFormat = "YYYYMMDD"
Public Sub Foo()
Const XLSMExtension = ".xlsm"
Dim sourceFileName As String
Dim targetFileName As String
sourceFileName = "SalesReport" & Format$(Now(), ISODateFormat) & XLSMExtension
targetFileName = "SummaryReport" & Format$(Now(), ISODateFormat) & XLSMExtension
DoSomething sourceFileName, targetFileName
End Sub
Sub Bar()
Debug.Print Format$(Now(), ISODateFormat), "Bar was called"
End Sub
But the scope of the ISODateFormat constant would need to change if say, Bar() was in Module2.
Ideally the user would be prompted for:
Most helpful comment
Here's a simple procedure and module level example:
Would become:
But the scope of the
ISODateFormatconstant would need to change if say,Bar()was inModule2.Ideally the user would be prompted for: