Live data from Hacker News

Semgrep: Semantic grep for code

semgrep.dev

31–40 of 110 posts

Re: Semgrep: Semantic grep for code

#31

This is an excellent tool to have as a security consultant, and it just keeps getting better and better. When approaching a large codebase, it enables you to write custom rules that match on certain antipatterns you've spotted that may be unique to the codebase. That's the real value of the tool, but the repository of per-language rules is also convenient for quickly finding low-hanging fruit (like every use of a pot…

Python you can probably do that just from the standard library. ast.parse and all that.

Re: Semgrep: Semantic grep for code

#32

The name "Semantic Grep" does not give a good idea for what this tool is and what it does. The web page states: "Static analysis at ludicrous speed. Find bugs and enforce code standards" "grep" is short for "global regular expression print". It finds matches for the given regular expression and prints them. "Semantic Grep" is a static analyzer with configurable rules, style checks, etc. It does much more than search…

The literal meaning of "grep" is not the only meaning. It also means “find snippet in files.”

Re: Semgrep: Semantic grep for code

#33
post #30
post #23

Earlier quoted context omitted.

It does seem potentially good for enforcing standards where the participants are willing. But you can work around it fairly easily. Like the example "python no-prints" rule: https://semgrep.dev/s/sabihb:no-prints Lots of workarounds it wouldn't find, like: import builtins builtins.print("whee")

I'm guessing the value with the rules system is, you can add new rules easily. So during a code review, if you see somebody using your example, you could create a new rule to catch that. I don't think you can go in with the mindset that it will catch everything, but rather, it's about being able to iterate quickly with your rules.

Sure. I raised it because it keeps using the word "static analysis", which at least wouldn't be fooled by builtins.print(). It's more than grep, for sure, but something less than static analysis tools I've used. And I don't mean that as a knock. It's working across a lot of languages, so I see the tradeoff.

Re: Semgrep: Semantic grep for code

#34

This is an excellent tool to have as a security consultant, and it just keeps getting better and better. When approaching a large codebase, it enables you to write custom rules that match on certain antipatterns you've spotted that may be unique to the codebase. That's the real value of the tool, but the repository of per-language rules is also convenient for quickly finding low-hanging fruit (like every use of a pot…

Python you can probably do that just from the standard library. ast.parse and all that.

Perhaps, but this tool has a syntax and common interface for multiple languages. This is a huge resource for IT/security. I could imagine this being a helpful refactoring tool as well for CLI.

Re: Semgrep: Semantic grep for code

#35

The name "Semantic Grep" does not give a good idea for what this tool is and what it does. The web page states: "Static analysis at ludicrous speed. Find bugs and enforce code standards" "grep" is short for "global regular expression print". It finds matches for the given regular expression and prints them. "Semantic Grep" is a static analyzer with configurable rules, style checks, etc. It does much more than search…

There is the common, if informal, definition that grep means "command line text search tool". I read this as "semantic/syntax search tool".

Re: Semgrep: Semantic grep for code

#36

The name "Semantic Grep" does not give a good idea for what this tool is and what it does. The web page states: "Static analysis at ludicrous speed. Find bugs and enforce code standards" "grep" is short for "global regular expression print". It finds matches for the given regular expression and prints them. "Semantic Grep" is a static analyzer with configurable rules, style checks, etc. It does much more than search…

[deleted]

Re: Semgrep: Semantic grep for code

#38
post #28

No Windows support yet: https://github.com/returntocorp/semgrep/issues/1330

From the thread you link it looks like they're getting close, there's been activity in the past few days.

(I'm guessing from your comment that this is important to you (i.e. WSL/Docker is not a solution).)

Re: Semgrep: Semantic grep for code

#39
I currently use a highly opinionated ESLint config (based on the airbnb one) together with strict checking in my TypeScript config, and it is configured to run on every commit with husky git hooks. The example given on the Semgrep homepage is an exact match to one that exists in my ESLint config (eslint's no-console rule).

How does Semgrep compare to ESLint+a strict tsconfig?

Re: Semgrep: Semantic grep for code

#40
post #28

No Windows support yet: https://github.com/returntocorp/semgrep/issues/1330

Kind of crazy that you can make a tool like this in the modern age that isn't cross platform. Maybe they just can't face the Python packaging nightmare on Windows.

Also kind of surprising it's written in Python given that they advertise its speed.

Post reply on HN