Prototype support for ast-grep rules
Going to use this branch to explore an ast-grep integration (i.e., allow users to define custom rules in YAML that can be executed via ast-grep, then automatically pick them up in Ruff).
See: #516.
One thing to note is that this basic rule takes ~1.8s, and it seems to scale ~linearly with the number of rules (very crude analysis so may well be wrong). So, there would be a conscious perf hit here vs. first-party rules.
This rule takes about ~650ms:
id: C001
message: Don't import bbbbbbbb
severity: warning
language: Python
rule:
any:
- pattern: import bbbbbbbb
So it does depend on the number and complexity of patterns and the number of occurrences.
I like the idea. Having an accessible way of writing custom lints was the reason I introduced semgrep at work, next to flake8.
The performance impact is quite huge though. If this were to be introduced, a flag to measure/report rule execution time would be helpful. I just looked at our repository at work, and running ruff cold took 200ms. flake8 needed 10s. If adding even just one of these rules can take up to 2s, it would be good to know, otherwise we're quickly in the ballpark of flake8 again. :)
@squiddy - Yeah I feel similarly on perf. It's the same reason that I didn't base the entire linter on LibCST. I need to think on what the right approach is here. It's possible that we will want to end up with code-based plugins.