Skip to content

Commit b519bda

Browse files
authored
Merge pull request #4419 from bclothier/ChainedWrapperEnhancement
Improve the messaging for the chained wrapper analyzer rule
2 parents b99aa13 + 0338aa5 commit b519bda

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

RubberduckCodeAnalysis/ChainedWrapperAnalyzer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ private static void AnalyzeSymbol(SyntaxNodeAnalysisContext context)
5151
if (expInterfaces.Value.Any(a => a.ToDisplayString() == "Rubberduck.VBEditor.SafeComWrappers.Abstract.ISafeComWrapper") &&
5252
nameInterfaces.Value.Any(a => a.ToDisplayString() == "Rubberduck.VBEditor.SafeComWrappers.Abstract.ISafeComWrapper"))
5353
{
54-
var diagnostic = Diagnostic.Create(ChainedWrapperRule, node.GetLocation());
54+
var targetType = context.SemanticModel.GetTypeInfo(nameValue).Type.Name;
55+
var containingType = context.SemanticModel.GetTypeInfo(node.Expression).Type.Name;
56+
var diagnostic = Diagnostic.Create(ChainedWrapperRule, node.GetLocation(), targetType, containingType, node.GetText());
57+
5558
context.ReportDiagnostic(diagnostic);
5659
}
5760
}

RubberduckCodeAnalysis/Resources.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@
121121
<value>COM Management</value>
122122
</data>
123123
<data name="ChainedWrapperDescription" xml:space="preserve">
124-
<value>Chained Wrappers</value>
124+
<value>All types derived from SafeComWrappers should not be chained as it leaks unmanaged resources. Use an explicit local variable for each chained member.</value>
125125
</data>
126126
<data name="ChainedWrapperMessageFormat" xml:space="preserve">
127-
<value>Chained Wrappers</value>
127+
<value>The type '{0}' derives from a SafeComWrapper base. It is called via other SafeComWrapper-derived type '{1}' in the expression '{2}'.</value>
128128
</data>
129129
<data name="ChainedWrapperTitle" xml:space="preserve">
130130
<value>Chained Wrappers</value>

0 commit comments

Comments
 (0)