Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
matching: ellipsis: Always try going deep
- Loading branch information
Showing
7 changed files
with
107 additions
and
9 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,24 @@ | ||
Fixed a regression introduced three years ago in 0.9.0, when optimizing | ||
the evaluation of `...` (ellipsis) to be faster. We made `...` only match | ||
"deeply" (inside an `if` for example) if nothing else matched, thus | ||
causing that this pattern: | ||
|
||
```python | ||
foo() | ||
... | ||
bar($A) | ||
``` | ||
|
||
would only produce a match rather than two: | ||
```python | ||
foo() | ||
if cond: | ||
bar(x) | ||
bar(y) | ||
``` | ||
|
||
Semgrep matched from `foo()` to `bar(y)`, but it did not match from | ||
`foo()` to `bar(x)`. However, if commented out `bar(y)`, then Semgrep | ||
matched `bar(x)`. | ||
|
||
Semgrep now produces the two expected matches. |
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,13 @@ | ||
# https://github.com/returntocorp/semgrep-rules/issues/660 | ||
|
||
def decorator_factory( foo ): | ||
def decorator( function ): | ||
# ok:reproducer-660 | ||
def function_wrapper( *args, **kwargs ): | ||
# Do something with 'foo'. | ||
return function( *args, **kwargs ) | ||
return function_wrapper | ||
return decorator | ||
|
||
@decorator_factory( 'bar' ) | ||
def test( ): ''' Simple reproducer. ''' |
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,29 @@ | ||
rules: | ||
- id: reproducer-660 | ||
patterns: | ||
- pattern-inside: | | ||
def $F(...): | ||
... | ||
def $FF(...): | ||
... | ||
... | ||
- pattern-not-inside: | | ||
def $F(...): | ||
... | ||
def $FF(...): | ||
... | ||
... | ||
<... $FF ...> | ||
- pattern: | | ||
def $FF(...): | ||
... | ||
- focus-metavariable: $FF | ||
message: function `$FF` is defined inside a function but never used | ||
languages: | ||
- python | ||
severity: ERROR | ||
metadata: | ||
category: maintainability | ||
technology: | ||
- python | ||
license: Commons Clause License Condition v1.0[LGPL-2.1-only] |
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 @@ | ||
|
||
foo(); | ||
|
||
obj.met(async () => { | ||
something(); | ||
// ruleid: test | ||
x = baz(); | ||
}); | ||
|
||
bar(); | ||
|
||
// ok: test | ||
y = baz(); |
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,19 @@ | ||
rules: | ||
- id: test | ||
message: > | ||
Test | ||
languages: | ||
- typescript | ||
severity: WARNING | ||
patterns: | ||
- pattern: baz() | ||
- pattern-inside: | | ||
foo(); | ||
... | ||
$X = baz(); | ||
- pattern-not-inside: | | ||
foo(); | ||
... | ||
bar(); | ||
... | ||
$X = baz(); |
Submodule semgrep-rules
updated
from 5ce59a to 70bd59