Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/ReferenceCop/Detectors/ProjectPathViolationDetector.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ReferenceCop
namespace ReferenceCop
{
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -46,7 +46,32 @@ public IEnumerable<Violation> GetViolationsFrom(IEnumerable<ReferenceEvaluationC

public IEnumerable<Violation> GetViolationsFromExperimental(IEnumerable<ReferenceEvaluationContext<string>> references)
{
return this.GetViolationsFrom(references);
var fromProjectPath = this.projectPathProvider.GetRelativePath(this.projectFilePath);

var matchingRules = this.rules.Where(r => fromProjectPath.StartsWith(r.FromPath)).ToList();
if (matchingRules.Count == 0)
{
yield break;
}

foreach (var referenceContext in references)
{
if (referenceContext.IsWarningSuppressed)
{
continue;
}

var toProjectPath = this.projectPathProvider.GetRelativePath(referenceContext.Reference);

foreach (var rule in matchingRules)
{
if (toProjectPath.StartsWith(rule.ToPath))
{
yield return new Violation(rule, referenceContext.Reference);
break;
}
}
}
}

private void LoadRulesFrom(ReferenceCopConfig config)
Expand Down
34 changes: 32 additions & 2 deletions src/ReferenceCop/Detectors/ProjectTagViolationDetector.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ReferenceCop
namespace ReferenceCop
{
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -46,7 +46,37 @@ public IEnumerable<Violation> GetViolationsFrom(IEnumerable<ReferenceEvaluationC

public IEnumerable<Violation> GetViolationsFromExperimental(IEnumerable<ReferenceEvaluationContext<string>> references)
{
return this.GetViolationsFrom(references);
var fromProjectTag = this.projectTagProvider.GetProjectTag(this.projectFilePath);

var matchingRules = this.rules.Where(r => r.FromProjectTag == fromProjectTag).ToList();
if (matchingRules.Count == 0)
{
yield break;
}

var blockedTagToRule = new Dictionary<string, ReferenceCopConfig.ProjectTag>();
foreach (var rule in matchingRules)
{
if (!blockedTagToRule.ContainsKey(rule.ToProjectTag))
{
blockedTagToRule[rule.ToProjectTag] = rule;
}
}

foreach (var referenceContext in references)
{
if (referenceContext.IsWarningSuppressed)
{
continue;
}

var toTag = this.projectTagProvider.GetProjectTag(referenceContext.Reference);

if (blockedTagToRule.TryGetValue(toTag, out var matchedRule))
{
yield return new Violation(matchedRule, referenceContext.Reference);
}
}
}

private void LoadRulesFrom(ReferenceCopConfig config)
Expand Down
Loading