Skip to content

Commit b2cdfdf

Browse files
author
Wolfgang Janz
committed
feature(): Add MethodTooLong inspection to vb.net
1 parent 02fbf7d commit b2cdfdf

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

CleanCode/src/CleanCode/CleanCode.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@
178178
<Compile Include="Features\HollowNames\HollowNamesCheck.cs" />
179179
<Compile Include="Features\MethodNameNotMeaningful\MethodNameNotMeaningfulHighlighting.cs" />
180180
<Compile Include="Features\MethodNameNotMeaningful\MethodNameNotMeaningfulCheck.cs" />
181+
<Compile Include="Features\MethodTooLong\MethodTooLongCheckVb.cs" />
181182
<Compile Include="Features\MethodTooLong\MethodTooLongHighlighting.cs">
182183
<SubType>Code</SubType>
183184
</Compile>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using CleanCode.Settings;
2+
using JetBrains.Application.Settings;
3+
using JetBrains.ReSharper.Daemon.Stages.Dispatcher;
4+
using JetBrains.ReSharper.Feature.Services.Daemon;
5+
using JetBrains.ReSharper.Psi.VB.Tree;
6+
using JetBrains.ReSharper.Psi.Tree;
7+
8+
namespace CleanCode.Features.MethodTooLong
9+
{
10+
[ElementProblemAnalyzer(typeof(IMethodDeclaration), HighlightingTypes = new []
11+
{
12+
typeof(MethodTooLongHighlighting)
13+
})]
14+
public class MethodTooLongCheckVb : ElementProblemAnalyzer<IMethodDeclaration>
15+
{
16+
protected override void Run(IMethodDeclaration element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
17+
{
18+
var maxStatements = data.SettingsStore.GetValue((CleanCodeSettings s) => s.MaximumMethodStatements);
19+
var maxDeclarations = data.SettingsStore.GetValue((CleanCodeSettings s) => s.MaximumDeclarationsInMethod);
20+
21+
var statementCount = element.CountChildren<IStatement>();
22+
if (statementCount <= maxStatements)
23+
{
24+
// Only look in the method body for declarations, otherwise we see
25+
// parameters + type parameters. We can ignore arrow expressions, as
26+
// they must be a single expression and won't have declarations
27+
var declarationCount = element.Block?.CountChildren<IDeclaration>() ?? 0;
28+
if (declarationCount <= maxDeclarations)
29+
return;
30+
}
31+
32+
var highlighting = new MethodTooLongHighlighting(element.GetNameDocumentRange());
33+
consumer.AddHighlighting(highlighting);
34+
}
35+
}
36+
}

CleanCode/src/CleanCode/Features/MethodTooLong/MethodTooLongHighlighting.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
using JetBrains.DocumentModel;
55
using JetBrains.ReSharper.Feature.Services.Daemon;
66
using JetBrains.ReSharper.Psi.CSharp;
7+
using JetBrains.ReSharper.Psi.VB;
78

89
[assembly: RegisterConfigurableSeverity(MethodTooLongHighlighting.SeverityID, null,
910
CleanCodeHighlightingGroupIds.CleanCode, "Method too long", "The method is bigger than it should be.",
1011
Severity.SUGGESTION, false)]
1112

1213
namespace CleanCode.Features.MethodTooLong
1314
{
14-
[ConfigurableSeverityHighlighting(SeverityID, CSharpLanguage.Name)]
15+
[ConfigurableSeverityHighlighting(SeverityID, CSharpLanguage.Name + VBLanguage.Name)]
1516
public class MethodTooLongHighlighting : IHighlighting
1617
{
1718
internal const string SeverityID = "MethodTooLong";

0 commit comments

Comments
 (0)