semgrep / semgrep

Lightweight static analysis for many languages. Find bug variants with patterns that look like source code.

Home Page:https://semgrep.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reusable patterns

xmo-odoo opened this issue · comments

In my experience, it's pretty common for some patterns. especially metavariable-pattern, to be repeated in lots of rules to refine matches or define classes of passing / failing constructs.

It would be nice to have an easy way to define patterns possibly independent from rules, and then invoke them from rules instead of having to copy/paste the same patterns over and over.

This is somewhat related to #3758: expressing non-literal strings is a bit verbose and somewhat error prone because of yaml, the ability to define reusable metavariable patterns would allow defining a single "non-literal" pattern, and then invoke that every time we want to make that assertion.