Skip to content

Commit e300691

Browse files
committed
2 parents 171becf + 7149649 commit e300691

17 files changed

+147
-47
lines changed

RetailCoder.VBE/App.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@ public App(VBE vbe, AddIn addIn)
3030
var constructorInfo = type.GetConstructor(Type.EmptyTypes);
3131
return constructorInfo != null ? constructorInfo.Invoke(Type.EmptyTypes) : null;
3232
})
33+
.Where(syntax => syntax != null)
3334
.Cast<ISyntax>()
3435
.ToList();
3536

3637
_inspections = Assembly.GetExecutingAssembly()
3738
.GetTypes()
38-
.Where(type => type.GetInterfaces().Contains(typeof(IInspection)))
39+
.Where(type => type.BaseType == typeof(CodeInspection))
3940
.Select(type =>
4041
{
4142
var constructor = type.GetConstructor(Type.EmptyTypes);
4243
return constructor != null ? constructor.Invoke(Type.EmptyTypes) : null;
4344
})
45+
.Where(inspection => inspection != null)
4446
.Cast<IInspection>()
4547
.ToList();
4648

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.Collections.Generic;
2+
using System.Runtime.InteropServices;
3+
using Rubberduck.VBA.Parser;
4+
5+
namespace Rubberduck.Inspections
6+
{
7+
[ComVisible(false)]
8+
public abstract class CodeInspection : IInspection
9+
{
10+
protected CodeInspection(string name, string message, CodeInspectionType type, CodeInspectionSeverity severity)
11+
{
12+
_name = name;
13+
_message = message;
14+
_inspectionType = type;
15+
Severity = severity;
16+
}
17+
18+
private readonly string _name;
19+
public string Name { get { return _name; } }
20+
21+
private readonly string _message;
22+
public string QuickFixMessage { get { return _message; } }
23+
24+
private readonly CodeInspectionType _inspectionType;
25+
public CodeInspectionType InspectionType { get { return _inspectionType; } }
26+
27+
public CodeInspectionSeverity Severity { get; set; }
28+
public bool IsEnabled { get; set; }
29+
30+
/// <summary>
31+
/// Inspects specified tree node, searching for code issues.
32+
/// </summary>
33+
/// <param name="node"></param>
34+
/// <returns></returns>
35+
public abstract IEnumerable<CodeInspectionResultBase> Inspect(SyntaxTreeNode node);
36+
}
37+
}

RetailCoder.VBE/Inspections/CodeInspectionResultBase.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@ namespace Rubberduck.Inspections
77
[ComVisible(false)]
88
public abstract class CodeInspectionResultBase
99
{
10-
public CodeInspectionResultBase(Instruction instruction, CodeInspectionSeverity type, string message)
10+
public CodeInspectionResultBase(string inspection, Instruction instruction, CodeInspectionSeverity type, string message)
1111
{
12+
_name = inspection;
1213
_instruction = instruction;
1314
_type = type;
1415
_message = message;
1516
}
1617

18+
private readonly string _name;
19+
/// <summary>
20+
/// Gets a string containing the name of the code inspection.
21+
/// </summary>
22+
public string Name { get { return _name; } }
23+
1724
private readonly Instruction _instruction;
1825
/// <summary>
1926
/// Gets the <see cref="Instruction"/> containing a code issue.

RetailCoder.VBE/Inspections/CodeInspectionSeverity.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ namespace Rubberduck.Inspections
55
[ComVisible(false)]
66
public enum CodeInspectionSeverity
77
{
8+
DoNotShow,
9+
Hint,
810
Suggestion,
9-
Warning
11+
Warning,
12+
Error
1013
}
1114
}

RetailCoder.VBE/Inspections/ObsoleteCommentSyntaxInspection.cs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,24 @@
77
namespace Rubberduck.Inspections
88
{
99
[ComVisible(false)]
10-
public class ObsoleteCommentSyntaxInspection : IInspection
10+
public class ObsoleteCommentSyntaxInspection : CodeInspection
1111
{
1212
/// <summary>
1313
/// Parameterless constructor required for discovery of implemented code inspections.
1414
/// </summary>
1515
public ObsoleteCommentSyntaxInspection()
16+
: base("Use of obsolete Rem comment syntax",
17+
"Replace Rem reserved keyword with single quote.",
18+
CodeInspectionType.MaintainabilityAndReadabilityIssues,
19+
CodeInspectionSeverity.Suggestion)
1620
{
17-
_name = "Use of obsolete Rem comment syntax";
18-
_quickFixMessage = "Replace Rem reserved keyword with single quote.";
19-
_inspectionType = CodeInspectionType.MaintainabilityAndReadabilityIssues;
20-
_severity = CodeInspectionSeverity.Suggestion;
2121
}
2222

23-
private readonly string _name;
24-
public string Name { get { return _name; } }
25-
26-
private readonly string _quickFixMessage;
27-
public string QuickFixMessage { get { return _quickFixMessage; } }
28-
29-
private readonly CodeInspectionType _inspectionType;
30-
public CodeInspectionType InspectionType { get { return _inspectionType; } }
31-
32-
private readonly CodeInspectionSeverity _severity;
33-
public CodeInspectionSeverity Severity { get { return _severity; } }
34-
35-
public bool IsEnabled { get; set; }
36-
37-
public IEnumerable<CodeInspectionResultBase> Inspect(SyntaxTreeNode node)
23+
public override IEnumerable<CodeInspectionResultBase> Inspect(SyntaxTreeNode node)
3824
{
39-
return node.FindAllComments()
40-
.Where(instruction => instruction.Value == ReservedKeywords.Rem)
41-
.Select(instruction => new ObsoleteCommentSyntaxInspectionResult(instruction, _severity, _quickFixMessage));
25+
var comments = node.FindAllComments();
26+
var remComments = comments.Where(instruction => instruction.Value.Trim().StartsWith(ReservedKeywords.Rem));
27+
return remComments.Select(instruction => new ObsoleteCommentSyntaxInspectionResult(Name, instruction, Severity, QuickFixMessage));
4228
}
4329
}
4430
}

RetailCoder.VBE/Inspections/ObsoleteCommentSyntaxInspectionResult.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ namespace Rubberduck.Inspections
66
{
77
public class ObsoleteCommentSyntaxInspectionResult : CodeInspectionResultBase
88
{
9-
public ObsoleteCommentSyntaxInspectionResult(Instruction instruction, CodeInspectionSeverity type, string message)
10-
: base(instruction, type, message)
9+
public ObsoleteCommentSyntaxInspectionResult(string inspection, Instruction instruction, CodeInspectionSeverity type, string message)
10+
: base(inspection, instruction, type, message)
1111
{
1212
}
1313

RetailCoder.VBE/Properties/Resources.Designer.cs

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

RetailCoder.VBE/Properties/Resources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,10 @@
166166
<data name="TestManager_8590_32" type="System.Resources.ResXFileRef, System.Windows.Forms">
167167
<value>..\Resources\Microsoft\TestManager_8590_32.bmp;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
168168
</data>
169+
<data name="ListsofTests_8643_24" type="System.Resources.ResXFileRef, System.Windows.Forms">
170+
<value>..\Resources\ListsofTests_8643_24.bmp;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
171+
</data>
172+
<data name="Step_RunTest_8814_32" type="System.Resources.ResXFileRef, System.Windows.Forms">
173+
<value>..\Resources\Step-RunTest_8814_32.bmp;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
174+
</data>
169175
</root>
822 Bytes
Binary file not shown.
822 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)