Skip to content

Commit

Permalink
feature(): Add TooManyDependencies inspection to vb.net
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfgang Janz committed Sep 26, 2016
1 parent 3b7dc4d commit 013ae17
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions CleanCode/src/CleanCode/CleanCode.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Features\ClassTooBig\ClassTooBigCheck.cs" />
<Compile Include="Features\TooManyDependencies\TooManyDependenciesCheckVb.cs" />
<Compile Include="Features\TooManyDependencies\TooManyDependenciesHighlighting.cs">
<SubType>Code</SubType>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Linq;
using CleanCode.Settings;
using JetBrains.Application.Settings;
using JetBrains.ReSharper.Daemon.Stages.Dispatcher;
using JetBrains.ReSharper.Feature.Services.Daemon;
using JetBrains.ReSharper.Psi.VB.Tree;
using JetBrains.ReSharper.Psi.Tree;
using JetBrains.ReSharper.Psi.Util;

namespace CleanCode.Features.TooManyDependencies
{
[ElementProblemAnalyzer(typeof(IConstructorDeclaration), HighlightingTypes = new []
{
typeof(TooManyDependenciesHighlighting)
})]
public class TooManyDependenciesCheckVb : ElementProblemAnalyzer<IConstructorDeclaration>
{
protected override void Run(IConstructorDeclaration element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
{
var maxDependencies = data.SettingsStore.GetValue((CleanCodeSettings s) => s.MaximumConstructorDependencies);

var dependencies = element.ParameterDeclarations.Select(
declaration => declaration.DeclaredElement != null &&
declaration.DeclaredElement.Type.IsInterfaceType());

var dependenciesCount = dependencies.Count();
if (dependenciesCount > maxDependencies)
{
var highlighting = new TooManyDependenciesHighlighting(element.GetNameDocumentRange());
consumer.AddHighlighting(highlighting);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
using JetBrains.DocumentModel;
using JetBrains.ReSharper.Feature.Services.Daemon;
using JetBrains.ReSharper.Psi.CSharp;
using JetBrains.ReSharper.Psi.VB;

[assembly: RegisterConfigurableSeverity(TooManyDependenciesHighlighting.SeverityID, null,
CleanCodeHighlightingGroupIds.CleanCode, "Too many dependencies", "Too many dependencies passed into constructor.",
Severity.WARNING, false)]

namespace CleanCode.Features.TooManyDependencies
{
[ConfigurableSeverityHighlighting(SeverityID, CSharpLanguage.Name)]
[ConfigurableSeverityHighlighting(SeverityID, CSharpLanguage.Name + "," + VBLanguage.Name)]
public class TooManyDependenciesHighlighting : IHighlighting
{
internal const string SeverityID = "TooManyDependencies";
Expand Down

0 comments on commit 013ae17

Please sign in to comment.