This question is based on a previous question that is closed because it asks for a recommendation of a tool.
In Visual Studio 2022, using the Find in Files dialog (CTRL + SHIFT + F) how can I find matches for the following. First I will list the input samples then the expected matches. In the following text, a
, b
and c
are single-word tokens in ASCII encoding.
this->a->b->c;
this->a.b.c;
this->a.b->c;
this->a->b.c;
this->a;
Matches.
a->b->c
a.b.c
a.b->c
a->b.c
NO MATCH
In other words I want to find violations of Law of Demeter. The this
and ;
token should NOT be a part of the match. If an instance of a class accesses its direct field it shouldn't access any fields of that field.
What have I tried?
\((\b(?!this\b)[\s\S]*?)\)
([\s\S]*?)(this)
this(.|->)(.*(.|->).*(.|->).*)
The regex dialect is the one that C# uses because that's what Visual Studio uses.