/
ModuleWithoutFolderInspection.cs
51 lines (48 loc) · 1.89 KB
/
ModuleWithoutFolderInspection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Collections.Generic;
using System.Linq;
using Rubberduck.Inspections.Abstract;
using Rubberduck.Inspections.Results;
using Rubberduck.Parsing.Inspections.Abstract;
using Rubberduck.Resources.Inspections;
using Rubberduck.Parsing.VBA;
using Rubberduck.Parsing.Annotations;
using Rubberduck.Inspections.Inspections.Extensions;
namespace Rubberduck.Inspections.Concrete
{
/// <summary>
/// Indicates that a user module is missing a @Folder Rubberduck annotation.
/// </summary>
/// <why>
/// Modules without a custom @Folder annotation will be grouped under the default folder in the Code Explorer toolwindow.
/// By specifying a custom @Folder annotation, modules can be organized by functionality rather than simply listed.
/// </why>
/// <example hasResults="true">
/// <![CDATA[
/// Option Explicit
/// ' ...
/// ]]>
/// </example>
/// <example hasResults="false">
/// <![CDATA[
/// '@Folder("Foo")
/// Option Explicit
/// ' ...
/// ]]>
/// </example>
public sealed class ModuleWithoutFolderInspection : InspectionBase
{
public ModuleWithoutFolderInspection(RubberduckParserState state)
: base(state)
{}
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
{
var modulesWithoutFolderAnnotation = State.DeclarationFinder.UserDeclarations(Parsing.Symbols.DeclarationType.Module)
.Where(w => !w.Annotations.OfType<FolderAnnotation>().Any())
.ToList();
return modulesWithoutFolderAnnotation
.Where(declaration => !declaration.IsIgnoringInspectionResultFor(AnnotationName))
.Select(declaration =>
new DeclarationInspectionResult(this, string.Format(InspectionResults.ModuleWithoutFolderInspection, declaration.IdentifierName), declaration));
}
}
}