TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Semgrep: Writing quick rules to verify ideas

62 点作者 adrianomartins超过 2 年前

3 条评论

craigds超过 2 年前
I use semgrep for semantic search (and replace, sometimes).<p>Their docs and website try very hard to suggest you should use it for some kind of CI process, but so far I haven&#x27;t found any need to do so. I can maybe see it being useful in a pre-commit hook.<p>It&#x27;s VERY handy for semantic searches though - in situations where ripgrep would be useless due to multi-line matches.<p>I set up this alias to make it a bit less verbose for Python patterns:<p><pre><code> pygrep () { pat=&quot;$1&quot; shift filez=&quot;$*&quot; bash -xc &quot;semgrep --lang=python --pattern &#x27;$pat&#x27; $filez&quot; } </code></pre> Usage is something like:<p><pre><code> pygrep &#x27;myfunc(..., needle_arg=..., ...)&#x27;</code></pre>
评论 #33239707 未加载
评论 #33239671 未加载
评论 #33239653 未加载
koyanisqatsi超过 2 年前
I was looking for something like this the other day but then ended up just using RubyVM::AbstractSyntaxTree.parse_file and then rolled my own visitor on top of the AST. It&#x27;s cool what they can do here but I think any language that exposes its AST is amenable to this kind of analysis, you just have to write some code to do it. The main bottleneck in my experience is just being familiar with the AST structure and how it maps to source syntax. It&#x27;s cool that they have abstracted a lot of the commonality among several languages, definitely gonna look into this next time I need semantic code search.
renewiltord超过 2 年前
Very cool. Thank you for writing this!