Repository navigation
Add ResideInNamespaceOrBelow and Its Negated Variants - #511
Open
StefanGreve wants to merge 1 commit into
Open
StefanGreve wants to merge 1 commit into
StefanGreve wants to merge 1 commit into
Conversation
ResideInNamespace matches one namespace by full name and ResideInNamespaceMatching takes an unanchored regex, so a rule over a namespace and all of its sub-namespaces either lists each one, silently missing any added later, or needs a pattern like ^Foo\.Bar(\.|$) to avoid also matching Foo.BarBaz. Add ResideInNamespaceOrBelow and NotResideInNamespaceOrBelow to TypeConditionsDefinition, ResideInNamespaceOrBelow and DoNotResideInNamespaceOrBelow to TypePredicatesDefinition, and the matching methods in AddTypeCondition/AddTypePredicate, mirroring ResideInNamespace and NotResideInNamespace/DoNotResideInNamespace. A namespace matches when its full name equals the given name or starts with it followed by a dot, compared case-insensitively like ResideInNamespace, so "Foo.Bar" matches Foo.Bar and Foo.Bar.Baz but not Foo.BarBaz. Signed-off-by: StefanGreve <stefan.ohlsen.greve@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #511 +/- ##
==========================================
+ Coverage 86.51% 86.55% +0.04%
==========================================
Files 261 261
Lines 12610 12648 +38
Branches 1233 1236 +3
==========================================
+ Hits 10909 10947 +38
Misses 1359 1359
Partials 342 342 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
In one of my projects, an architecture test restricts the visibility of everything in a
Modelnamespace and its sub-namespaces. With the current API, the rule has to name each namespace (MyProject.ModelandMyProject.Model.Options, joined byOr), so a sub-namespace added later escapes the rule silently instead of failing it.ResideInNamespaceMatchingcan work around this with a regular expression, but at the cost of the readability a fluent API normally provides.Feature Description
Add
ResideInNamespaceOrBelowandNotResideInNamespaceOrBelowtoTypeConditionsDefinition,ResideInNamespaceOrBelowandDoNotResideInNamespaceOrBelowtoTypePredicatesDefinition, and the matching methods inAddTypeCondition/AddTypePredicate, mirroringResideInNamespaceandNotResideInNamespace/DoNotResideInNamespace.A namespace matches when its full name equals the given name or starts with it followed by a dot, compared case-insensitively like
ResideInNamespace, soFoo.BarmatchesFoo.BarandFoo.Bar.Bazbut notFoo.BarBaz: