-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decide on the selector expressions behavior #16
Comments
We could use Go-style operators: however, those look more verbose than the proposed |
We can't use that syntax, since it has different meaning in Go. It's a method expression. Everything inside |
What about adding a match that expresses that a specific import path is imported for that file and is not renamed? If gogrep could handle it, the import package name path could also be transparently replaced to the imported name while applying the match and the replacement. |
Is it still an active discussion? |
@sarathsp06 it is. But my main problem is the lack of time to work on it. :( |
Given the
path.Join(...)
pattern, there are multiple interpretations that can be made:path
could be a local variable (and Join is either a func-typed property or a method).path
can be a package not from stdlib (e.g.github.com/blahblah/path
).(same as 2.)path
is a stdlib package.path
is a type name,Join
is a method name,path.Join
is a method expression.Our current behavior is based on what gogrep does. It's 100% syntactical, so it matches all of them.
Here is a proposal of how we can make rules that can match the pattern with a better precision.
CodeQL doesn't have such a problem because it requires you to specify a type of all query variables in every query.
gorules
have no variable definitions concept, but we can infer their "node kind" constraint throughWhere
clause.This proposal introduces new fields of a matcher variable:
Var
,Package
andType
(there can be more later). IfType.Name
is used,m["p"]
is expected to be a type.A slightly different approach includes adding all predicates to the
fluent.Var
, as it's done in reflect package:A more radical way is to introduce non-ambigous operators:
x.f()
-f
function call from a packagex
x->f()
-f
method call from a variablex
(rare case)x::f()
-f
function call from a typex
(very rare case)This is harder to implement and makes patterns even more incompatible with Go syntax. gogrep doesn't support such syntax => custom source preprocessing will be required.
The text was updated successfully, but these errors were encountered: