Skip to content

Commit

Permalink
TooManyDependencies as EPA
Browse files Browse the repository at this point in the history
  • Loading branch information
citizenmatt committed Sep 6, 2016
1 parent 24dc249 commit 8ccc782
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 41 deletions.
8 changes: 0 additions & 8 deletions CleanCode/src/CleanCode/CleanCodeDaemonStageProcess.cs
@@ -1,5 +1,4 @@
using System;
using CleanCode.Features.TooManyDependencies;
using CleanCode.Features.TooManyMethodArguments;
using JetBrains.Application.Settings;
using JetBrains.ReSharper.Daemon.CSharp.Stages;
Expand All @@ -13,7 +12,6 @@ public class CleanCodeDaemonStageProcess : CSharpDaemonStageProcessBase
{
private readonly IContextBoundSettingsStore settingsStore;
private readonly TooManyMethodArgumentsCheck tooManyArgumentsCheck;
private readonly TooManyDependenciesCheck tooManyDependenciesCheck;

public CleanCodeDaemonStageProcess(IDaemonProcess daemonProcess, ICSharpFile file, IContextBoundSettingsStore settingsStore)
: base(daemonProcess, file)
Expand All @@ -22,7 +20,6 @@ public CleanCodeDaemonStageProcess(IDaemonProcess daemonProcess, ICSharpFile fil

// TODO: This is starting to feel like a beach of Benidorm in July. Refactoring needed.
tooManyArgumentsCheck = new TooManyMethodArgumentsCheck(settingsStore);
tooManyDependenciesCheck = new TooManyDependenciesCheck(settingsStore);
}

public override void Execute(Action<DaemonStageResult> commiter)
Expand All @@ -34,10 +31,5 @@ public override void VisitMethodDeclaration(IMethodDeclaration methodDeclaration
{
tooManyArgumentsCheck.ExecuteIfEnabled(methodDeclaration, context);
}

public override void VisitConstructorDeclaration(IConstructorDeclaration constructorDeclaration, IHighlightingConsumer context)
{
tooManyDependenciesCheck.ExecuteIfEnabled(constructorDeclaration, context);
}
}
}
@@ -1,47 +1,34 @@
using System.Linq;
using CleanCode.Resources;
using CleanCode.Settings;
using JetBrains.Application.Settings;
using JetBrains.ReSharper.Daemon.Stages.Dispatcher;
using JetBrains.ReSharper.Feature.Services.Daemon;
using JetBrains.ReSharper.Psi.CSharp.Tree;
using JetBrains.ReSharper.Psi.Tree;
using JetBrains.ReSharper.Psi.Util;

namespace CleanCode.Features.TooManyDependencies
{
public class TooManyDependenciesCheck : MonoValueCheck<IConstructorDeclaration, int>
[ElementProblemAnalyzer(typeof(IConstructorDeclaration), HighlightingTypes = new []
{
public TooManyDependenciesCheck(IContextBoundSettingsStore settingsStore)
: base(settingsStore)
{
}

protected override void ExecuteCore(IConstructorDeclaration constructorDeclaration, IHighlightingConsumer consumer)
typeof(TooManyDependenciesHighlighting)
})]
public class TooManyDependenciesCheck : ElementProblemAnalyzer<IConstructorDeclaration>
{
protected override void Run(IConstructorDeclaration element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
{
var maxDependencies = Value;
var maxDependencies = data.SettingsStore.GetValue((CleanCodeSettings s) => s.TooManyDependenciesMaximum);

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

var dependenciesCount = dependencies.Count();

if (dependenciesCount > maxDependencies)
{
var highlighting = new Highlighting(Warnings.TooManyDependencies,
constructorDeclaration.GetNameDocumentRange());
var highlighting = new TooManyDependenciesHighlighting(element.GetNameDocumentRange());
consumer.AddHighlighting(highlighting);
}
}

protected override int Value
{
get { return SettingsStore.GetValue((CleanCodeSettings s) => s.TooManyDependenciesMaximum); }
}

protected override bool IsEnabled
{
get { return SettingsStore.GetValue((CleanCodeSettings s) => s.TooManyDependenciesMaximumEnabled); }
}
}
}
@@ -1,24 +1,24 @@
using CleanCode;
using CleanCode.Features.TooManyDependencies;
using CleanCode.Resources;
using JetBrains.DocumentModel;
using JetBrains.ReSharper.Feature.Services.Daemon;
using JetBrains.ReSharper.Psi.CSharp;

[assembly: RegisterConfigurableSeverity(Highlighting.SeverityID, null,
HighlightingGroupIds.CodeSmell, "Too Many Dependencies", "Too many dependencies passed into constructor.",
[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)]
public class Highlighting : IHighlighting
public class TooManyDependenciesHighlighting : IHighlighting
{
internal const string SeverityID = "TooManyDependencies";
private readonly string tooltip;
private readonly DocumentRange documentRange;

public Highlighting(string toolTip, DocumentRange documentRange)
public TooManyDependenciesHighlighting(DocumentRange documentRange)
{
tooltip = toolTip;
this.documentRange = documentRange;
}

Expand All @@ -29,12 +29,12 @@ public DocumentRange CalculateRange()

public string ToolTip
{
get { return tooltip; }
get { return Warnings.TooManyDependencies; }
}

public string ErrorStripeToolTip
{
get { return tooltip; }
get { return ToolTip; }
}

public bool IsValid()
Expand Down
2 changes: 1 addition & 1 deletion CleanCode/src/CleanCode/Resources/Warnings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion CleanCode/src/CleanCode/Resources/Warnings.resx
Expand Up @@ -118,7 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="TooManyDependencies" xml:space="preserve">
<value>There are too many interfaces being passed in to this constructor. You might be violating SRP.</value>
<value>There are too many interfaces being passed in to this constructor. You might be violating the Single Responsibility Principle.</value>
</data>
<data name="TooManyMethodArguments" xml:space="preserve">
<value>This method requires too many arguments.</value>
Expand Down

0 comments on commit 8ccc782

Please sign in to comment.