Skip to content

Commit df82dc6

Browse files
authored
Merge pull request #4427 from Hosch250/features2355
Inspection for public members with underscores in names in class modules
2 parents a5480c9 + 556869c commit df82dc6

File tree

12 files changed

+245
-2
lines changed

12 files changed

+245
-2
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Rubberduck.Inspections.Abstract;
4+
using Rubberduck.Inspections.Results;
5+
using Rubberduck.Parsing.Inspections.Abstract;
6+
using Rubberduck.Resources.Inspections;
7+
using Rubberduck.Parsing.VBA;
8+
9+
namespace Rubberduck.Inspections.Concrete
10+
{
11+
public sealed class UnderscoreInPublicClassModuleMemberInspection : InspectionBase
12+
{
13+
public UnderscoreInPublicClassModuleMemberInspection(RubberduckParserState state)
14+
: base(state) { }
15+
16+
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
17+
{
18+
var interfaceMembers = State.DeclarationFinder.FindAllInterfaceImplementingMembers().ToList();
19+
var eventHandlers = State.DeclarationFinder.FindEventHandlers().ToList();
20+
21+
var names = State.DeclarationFinder.UserDeclarations(Parsing.Symbols.DeclarationType.Member)
22+
.Where(w => w.ParentDeclaration.DeclarationType == Parsing.Symbols.DeclarationType.ClassModule)
23+
.Where(w => !interfaceMembers.Contains(w) && !eventHandlers.Contains(w))
24+
.Where(w => w.Accessibility == Parsing.Symbols.Accessibility.Public || w.Accessibility == Parsing.Symbols.Accessibility.Implicit)
25+
.Where(w => w.IdentifierName.Contains('_'))
26+
.ToList();
27+
28+
return names.Select(issue =>
29+
new DeclarationInspectionResult(this, string.Format(InspectionResults.UnderscoreInPublicClassModuleMemberInspection, issue.IdentifierName), issue));
30+
}
31+
}
32+
}

Rubberduck.CodeAnalysis/QuickFixes/RenameDeclarationQuickFix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public sealed class RenameDeclarationQuickFix : QuickFixBase
1818
private readonly IMessageBox _messageBox;
1919

2020
public RenameDeclarationQuickFix(IVBE vbe, RubberduckParserState state, IMessageBox messageBox)
21-
: base(typeof(HungarianNotationInspection), typeof(UseMeaningfulNameInspection), typeof(DefaultProjectNameInspection))
21+
: base(typeof(HungarianNotationInspection), typeof(UseMeaningfulNameInspection), typeof(DefaultProjectNameInspection), typeof(UnderscoreInPublicClassModuleMemberInspection))
2222
{
2323
_vbe = vbe;
2424
_state = state;

Rubberduck.Core/Properties/Settings.Designer.cs

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.Core/Properties/Settings.settings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@
261261
&lt;CodeInspection Name="IsMissingOnInappropriateArgumentInspection" Severity="Warning" InspectionType="CodeQualityIssues" /&gt;
262262
&lt;CodeInspection Name="IsMissingWithNonArgumentParameterInspection" Severity="Warning" InspectionType="CodeQualityIssues" /&gt;
263263
&lt;CodeInspection Name="AssignmentNotUsedInspection" Severity="Suggestion" InspectionType="CodeQualityIssues" /&gt;
264+
&lt;CodeInspection Name="UnderscoreInPublicClassModuleMemberInspection" Severity="Warning" InspectionType="CodeQualityIssues" /&gt;
264265
&lt;/CodeInspections&gt;
265266
&lt;WhitelistedIdentifiers /&gt;
266267
&lt;RunInspectionsOnSuccessfulParse&gt;true&lt;/RunInspectionsOnSuccessfulParse&gt;

Rubberduck.Core/app.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@
386386
Severity="Warning" InspectionType="CodeQualityIssues" />
387387
<CodeInspection Name="AssignmentNotUsedInspection" Severity="Suggestion"
388388
InspectionType="CodeQualityIssues" />
389+
<CodeInspection Name="UnderscoreInPublicClassModuleMemberInspection" Severity="Warning"
390+
InspectionType="CodeQualityIssues" />
389391
</CodeInspections>
390392
<WhitelistedIdentifiers />
391393
<RunInspectionsOnSuccessfulParse>true</RunInspectionsOnSuccessfulParse>

Rubberduck.Resources/Inspections/InspectionInfo.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.Resources/Inspections/InspectionInfo.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@ If the parameter can be null, ignore this inspection result; passing a null valu
349349
<data name="AssignmentNotUsedInspection" xml:space="preserve">
350350
<value>An assignment is immediately overridden by another assignment or is never referenced.</value>
351351
</data>
352+
<data name="UnderscoreInPublicClassModuleMemberInspection" xml:space="preserve">
353+
<value>A class module that contains members with underscores cannot be implemented by other classes. The underscore is used as a separator between the interface/object name and the implemented member name: having an underscore in the member name confuses the compiler, which then refuses to compile the project. Avoid underscores in public member names by following a 'PascalCase' naming convention.</value>
354+
</data>
352355
<data name="ExcelMemberMayReturnNothingInspection" xml:space="preserve">
353356
<value>A procedure that returns an object may return 'Nothing'. That will cause a runtime error 91 - "Object variable or With block variable not set" on subsequent member access. Perform an 'Is Nothing' check after the 'Set' assignment to guard against runtime errors.</value>
354357
</data>

Rubberduck.Resources/Inspections/InspectionNames.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.Resources/Inspections/InspectionNames.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@
348348
<data name="AssignmentNotUsedInspection" xml:space="preserve">
349349
<value>Assignment is not used</value>
350350
</data>
351+
<data name="UnderscoreInPublicClassModuleMemberInspection" xml:space="preserve">
352+
<value>Underscore in public class module member</value>
353+
</data>
351354
<data name="ExcelMemberMayReturnNothingInspection" xml:space="preserve">
352355
<value>Member access may return 'Nothing'</value>
353356
</data>

Rubberduck.Resources/Inspections/InspectionResults.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)