-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Metavariable Type Extension for Semgrep Rule Syntax 2.0 (#8184)
This PR introduces the changes made in Semgrep rule syntax 1.0 to version 2.0 as well. fix #8183 PR checklist: - [ ] Purpose of the code is [evident to future readers](https://semgrep.dev/docs/contributing/contributing-code/#explaining-code) - [ ] Tests included or PR comment includes a reproducible test plan - [ ] Documentation is up-to-date - [ ] A changelog entry was [added to changelog.d](https://semgrep.dev/docs/contributing/contributing-code/#adding-a-changelog-entry) for any user-facing change - [ ] Change has no security implications (otherwise, ping security team) If you're unsure about any of this, please see: - [Contribution guidelines](https://semgrep.dev/docs/contributing/contributing-code)! - [One of the more specific guides located here](https://semgrep.dev/docs/contributing/contributing/)
- Loading branch information
Showing
8 changed files
with
135 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
feat(rule syntax): Metavariable Type Extension for Semgrep Rule Syntax 2.0 | ||
|
||
This PR introduces the changes made in Semgrep rule syntax 1.0 to version 2.0 as well. | ||
|
||
# rule syntax 2.0 | ||
rules: | ||
- id: no-string-eqeq | ||
message: find errors | ||
severity: WARNING | ||
languages: | ||
- java | ||
match: | ||
all: | ||
- not: null == (String $Y) | ||
- $X == (String $Y) | ||
|
||
# rule syntax 2.0 after proposed change | ||
rules: | ||
- id: no-string-eqeq | ||
message: find errors | ||
severity: WARNING | ||
languages: | ||
- java | ||
match: | ||
all: | ||
- not: null == $Y | ||
- $X == $Y | ||
where: | ||
- metavariable: $Y | ||
type: String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
public class Example { | ||
public int foo(String a, int b) { | ||
// ok: no-string-eqeq | ||
if ("hello" == a) return 2; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
rules: | ||
- id: no-string-eqeq | ||
message: find errors | ||
severity: WARNING | ||
languages: | ||
- java | ||
match: | ||
all: | ||
- not: null == $Y | ||
- $X == $Y | ||
where: | ||
- metavariable: $Y | ||
pattern: a | ||
type: Foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
public class Example { | ||
public int foo(String a, int b) { | ||
// ruleid: no-string-eqeq | ||
if (a == "hello") return 1; | ||
// ruleid: no-string-eqeq | ||
if ("hello" == a) return 2; | ||
// ok: no-string-eqeq | ||
if (b == 2) return -1; | ||
// ok: no-string-eqeq | ||
if (null == "hello") return 12; | ||
// ok: no-string-eqeq | ||
if ("hello" == null) return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
rules: | ||
- id: no-string-eqeq | ||
message: find errors | ||
severity: WARNING | ||
languages: | ||
- java | ||
match: | ||
all: | ||
- not: null == $Y | ||
- $X == $Y | ||
where: | ||
- metavariable: $Y | ||
type: String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
public class Example { | ||
public int foo(String a, int b) { | ||
// ok: no-string-eqeq | ||
if ("hello" == a) return 2; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
rules: | ||
- id: no-string-eqeq | ||
message: find errors | ||
severity: WARNING | ||
languages: | ||
- java | ||
match: | ||
all: | ||
- not: null == $Y | ||
- $X == $Y | ||
where: | ||
- metavariable: $Y | ||
pattern: b | ||
type: String |