Skip to content

Commit 163713e

Browse files
committed
Module without folder annotation
1 parent 935944b commit 163713e

File tree

6 files changed

+105
-0
lines changed

6 files changed

+105
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
using Rubberduck.Parsing.Annotations;
9+
10+
namespace Rubberduck.Inspections.Concrete
11+
{
12+
public sealed class ModuleWithoutFolderInspection : InspectionBase
13+
{
14+
public ModuleWithoutFolderInspection(RubberduckParserState state)
15+
: base(state)
16+
{
17+
}
18+
19+
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
20+
{
21+
var modulesWithoutFolderAnnotation = State.DeclarationFinder.UserDeclarations(Parsing.Symbols.DeclarationType.Module)
22+
.Where(w => w.Annotations.All(a => a.AnnotationType != AnnotationType.Folder))
23+
.ToList();
24+
25+
return modulesWithoutFolderAnnotation.Select(declaration =>
26+
new DeclarationInspectionResult(this, string.Format(InspectionResults.ModuleWithoutFolderInspection, declaration.IdentifierName), declaration));
27+
}
28+
}
29+
}

Rubberduck.CodeAnalysis/Rubberduck.CodeAnalysis.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
<Compile Include="Inspections\Concrete\EmptyForEachBlockInspection.cs" />
8282
<Compile Include="Inspections\Concrete\EmptyForLoopBlockInspection.cs" />
8383
<Compile Include="Inspections\Concrete\BooleanAssignedInIfElseInspection.cs" />
84+
<Compile Include="Inspections\Concrete\ModuleWithoutFolderInspection.cs" />
8485
<Compile Include="Inspections\Concrete\EmptyWhileWendBlockInspection.cs" />
8586
<Compile Include="Inspections\Concrete\ObsoleteCallingConventionInspection.cs" />
8687
<Compile Include="Inspections\Concrete\ObsoleteErrorSyntaxInspection.cs" />

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
@@ -363,4 +363,7 @@
363363
<data name="DuplicatedAnnotationInspection" xml:space="preserve">
364364
<value>Annotation '{0}' is duplicated.</value>
365365
</data>
366+
<data name="ModuleWithoutFolderInspection" xml:space="preserve">
367+
<value>Module '{0}' has no '@Folder' annotation</value>
368+
</data>
366369
</root>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using NUnit.Framework;
2+
using Rubberduck.Inspections.Concrete;
3+
using RubberduckTests.Mocks;
4+
using System.Linq;
5+
using System.Threading;
6+
7+
namespace RubberduckTests.Inspections
8+
{
9+
[TestFixture]
10+
public class ModuleWithoutFolderInspectionTests
11+
{
12+
[Test]
13+
[Category("Inspections")]
14+
public void Module_NoFolderAnnotation()
15+
{
16+
const string inputCode = "Option Explicit";
17+
18+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
19+
using (var state = MockParser.CreateAndParse(vbe.Object))
20+
{
21+
var inspection = new ModuleWithoutFolderInspection(state);
22+
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);
23+
24+
Assert.AreEqual(1, inspectionResults.Count());
25+
}
26+
}
27+
28+
[Test]
29+
[Category("Inspections")]
30+
public void Module_FolderAnnotation()
31+
{
32+
const string inputCode = @"'@Folder Foo.Bar
33+
Option Explicit";
34+
35+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
36+
using (var state = MockParser.CreateAndParse(vbe.Object))
37+
{
38+
var inspection = new ModuleWithoutFolderInspection(state);
39+
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);
40+
41+
Assert.AreEqual(0, inspectionResults.Count());
42+
}
43+
}
44+
45+
[Test]
46+
[Category("Inspections")]
47+
public void Module_NonFolderAnnotation()
48+
{
49+
const string inputCode = @"'@IgnoreModule
50+
Option Explicit";
51+
52+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _);
53+
using (var state = MockParser.CreateAndParse(vbe.Object))
54+
{
55+
var inspection = new ModuleWithoutFolderInspection(state);
56+
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);
57+
58+
Assert.AreEqual(1, inspectionResults.Count());
59+
}
60+
}
61+
}
62+
}

RubberduckTests/RubberduckTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
<Compile Include="CodeAnalysis\CodeMetrics\LineCountTests.cs" />
111111
<Compile Include="CodeExplorer\CodeExplorerTests.cs" />
112112
<Compile Include="Inspections\ImplicitDefaultMemberAssignmentInspectionTests.cs" />
113+
<Compile Include="Inspections\ModuleWithoutFolderInspectionTests.cs" />
113114
<Compile Include="Inspections\UnreachableCase\ExpressionFilterUnitTests.cs" />
114115
<Compile Include="Inspections\UnreachableCase\ParseTreeExpressionEvaluatorUnitTests.cs" />
115116
<Compile Include="Inspections\UnreachableCase\ParseTreeValueUnitTests.cs" />

0 commit comments

Comments
 (0)