Skip to content

Commit f19e04e

Browse files
committed
Inspection for public members with underscores in names in class modules
1 parent 2a47a4d commit f19e04e

File tree

11 files changed

+208
-1
lines changed

11 files changed

+208
-1
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 names = State.DeclarationFinder.UserDeclarations(Parsing.Symbols.DeclarationType.Member)
19+
.Where(w => w.ParentDeclaration.DeclarationType == Parsing.Symbols.DeclarationType.ClassModule)
20+
.Where(w => w.Accessibility == Parsing.Symbols.Accessibility.Public)
21+
.Where(w => w.IdentifierName.Contains('_'))
22+
.ToList();
23+
24+
return names.Select(issue =>
25+
new DeclarationInspectionResult(this, string.Format(InspectionResults.UnderscoreInPublicClassModuleMemberInspection, issue.IdentifierName), issue));
26+
}
27+
}
28+
}

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
@@ -284,6 +284,7 @@
284284
&lt;CodeInspection Name="IsMissingOnInappropriateArgumentInspection" Severity="Warning" InspectionType="CodeQualityIssues" /&gt;
285285
&lt;CodeInspection Name="IsMissingWithNonArgumentParameterInspection" Severity="Warning" InspectionType="CodeQualityIssues" /&gt;
286286
&lt;CodeInspection Name="AssignmentNotUsedInspection" Severity="Suggestion" InspectionType="CodeQualityIssues" /&gt;
287+
&lt;CodeInspection Name="UnderscoreInPublicClassModuleMemberInspection" Severity="Warning" InspectionType="CodeQualityIssues" /&gt;
287288
&lt;/CodeInspections&gt;
288289
&lt;WhitelistedIdentifiers /&gt;
289290
&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
@@ -412,6 +412,8 @@
412412
Severity="Warning" InspectionType="CodeQualityIssues" />
413413
<CodeInspection Name="AssignmentNotUsedInspection" Severity="Suggestion"
414414
InspectionType="CodeQualityIssues" />
415+
<CodeInspection Name="UnderscoreInPublicClassModuleMemberInspection" Severity="Warning"
416+
InspectionType="CodeQualityIssues" />
415417
</CodeInspections>
416418
<WhitelistedIdentifiers />
417419
<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,4 +349,7 @@ 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 with public members with underscores cannot implement interfaces that do not expose said member.</value>
354+
</data>
352355
</root>

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,4 +348,7 @@
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
</root>

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.

Rubberduck.Resources/Inspections/InspectionResults.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,4 +378,7 @@
378378
<data name="AssignmentNotUsedInspection" xml:space="preserve">
379379
<value>An assignment is immediately overridden by another assignment or is never referenced.</value>
380380
</data>
381+
<data name="UnderscoreInPublicClassModuleMemberInspection" xml:space="preserve">
382+
<value>Public member '{0}' has underscore in name.</value>
383+
</data>
381384
</root>

0 commit comments

Comments
 (0)