Skip to content

aiskillstore/marketplace / skills/0xdarkmatter/structural-search

structural-search

Verified

Search code by AST structure using ast-grep. Find semantic patterns like function calls, imports, class definitions instead of text patterns. Triggers on: find all calls to X, search for pattern, refactor usages, find where function is used, structural search, ast-grep, sg.

references/python-patterns.md

View on GitHub
# Python Patterns

Complete pattern library for ast-grep in Python.

## Function Definitions

```bash
# Find function definitions
sg -p 'def $NAME($$$): $$$' --lang python

# Find async function definitions
sg -p 'async def $NAME($$$): $$$' --lang python

# Find class definitions
sg -p 'class $NAME: $$$' --lang python

# Find class with inheritance
sg -p 'class $NAME($_): $$$' --lang python
```

## Decorators

```bash
# Find any decorated functions
sg -p '@$_
def $NAME($$$): $$$' --lang python

# Find pytest fixtures
sg -p '@pytest.fixture
def $NAME($$$): $$$' --lang python

# Find Flask routes
sg -p '@app.route($_)
def $NAME($$$): $$$' --lang python

# Find property decorators
sg -p '@property
def $NAME($$$): $$$' --lang python

# Find classmethod/staticmethod
sg -p '@classmethod
def $NAME($$$): $$$' --lang python
```

## Imports

```bash
# Find standard imports
sg -p 'import $_' --lang python

# Find from imports
sg -p 'from $_ import $_' --lang python

# Find aliased imports
sg -p 'import $_ as $_' --lang python

# Find wildcard imports (anti-pattern)
sg -p 'from $_ import *' --lang python
```

## Control Flow

```bash
# Find try-except blocks
sg -p 'try:
    $$$
except $_:
    $$$' --lang python

# Find with statements (context managers)
sg -p 'with $_ as $_: $$$' --lang python

# Find list comprehensions
sg -p '[$_ for $_ in $_]' --lang python

# Find dict comprehensions
sg -p '{$_: $_ for $_ in $_}' --lang python

# Find generator expressions
sg -p '($_ for $_ in $_)' --lang python
```

## String Formatting

```bash
# Find f-strings
sg -p 'f"$$$"' --lang python

# Find .format() calls
sg -p '"$$$".format($$$)' --lang python

# Find % formatting (old style)
sg -p '"$$$" % $_' --lang python
```

## Common Patterns

```bash
# Find main block
sg -p 'if __name__ == "__main__":
    $$$' --lang python

# Find dataclass definitions
sg -p '@dataclass
class $NAME:
    $$$' --lang python

# Find type hints
sg -p 'def $NAME($$$) -> $_: $$$' --lang python

# Find assert statements
sg -p 'assert $_' --lang python

# Find raise statements
sg -p 'raise $_' --lang python
```

## Testing Patterns

```bash
# Find test functions
sg -p 'def test_$NAME($$$): $$$' --lang python

# Find pytest parametrize
sg -p '@pytest.mark.parametrize($_)
def $NAME($$$): $$$' --lang python

# Find mock patches
sg -p '@patch($_)
def $NAME($$$): $$$' --lang python
```
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 322kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 322kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 322kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 322kUpdated Claude CodeCodexVerifiedInstall