searching-code-structures

Search, refactor, and lint code using ast-grep AST-based pattern matching.

Updated Dec 4, 2025
One-click install
npx skills add https://github.com/dallascrilley/dowser --skill searching-code-structures-dallascrilley
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: searching-code-structures
Source: https://github.com/dallascrilley/dowser/tree/main/skills/searching-code-structures
Command: npx skills add https://github.com/dallascrilley/dowser --skill searching-code-structures-dallascrilley

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Text-based search tools like grep cannot understand code structure, making it hard to find patterns like "async functions without error handling" or safely refactor code across a codebase. This Skill uses ast-grep to perform syntax-aware searches, structural rewrites, and custom linting based on the Abstract Syntax Tree. ## Core Features & Use Cases - Syntax-Aware Search: Find code by AST structure using patterns with meta-variables like console.log($$$ARGS) across JavaScript, TypeScript, Python, Go, Rust, and more. - Structural Refactoring: Preview and apply codebase-wide rewrites with sg run -p 'old' -r 'new' -U, including dry-run previews and file glob filtering. - Custom Linting Rules: Define YAML rules with atomic, relational, and composite logic, then enforce them via sg scan in CI/CD pipelines. - Use Case: Replace all console.log calls with a logger in production code only: preview with sg run -p 'console.log($$$ARGS)' -r 'logger.info($$$ARGS)' --globs '!**/*.test.js' --dry-run src/, then apply with -U. ## Quick Start Ask the assistant to find all async functions without error handling in the src directory using ast-grep.

Frequently Asked Questions about searching-code-structures

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I search for code patterns with ast-grep?▼

Use sg run with the -p flag and a pattern containing meta-variables, for example sg run -p 'console.log($$$)' src/. The $VAR syntax matches a single node and $$$VARS matches zero or more nodes, and you can specify the language with -l.

How do I replace code across a codebase using ast-grep?▼

Run sg run with -p for the search pattern, -r for the replacement, and -U to apply changes, such as sg run -p 'var $X = $Y' -r 'const $X = $Y' -U src/. Always preview first with --dry-run before applying changes.

What languages does ast-grep support for structural search?▼

ast-grep supports JavaScript, TypeScript, Python, Go, Rust, Java, C, C++, C#, HTML, CSS, and more. You can map custom file extensions via languageGlobs in sgconfig.yml or register fully custom languages with a tree-sitter parser.

Why is my ast-grep pattern not matching code it should?▼

Common causes are a missing language flag, overly strict patterns, wrong meta-variable types, or relational rules without stopBy: end. Debug with sg run -p 'pattern' -l javascript --debug-query=ast to see how the pattern parses, or try --strictness=relaxed.

How do I create a custom linting rule with ast-grep?▼

Write a YAML file with an id, language, and rule field containing a pattern, then run sg scan -r rules/my-rule.yml. Rules can combine atomic, relational, and composite logic, include a fix for auto-correction, and be tested with sg test.

When should I use ast-grep instead of grep or sed?▼

Use ast-grep when matches depend on code structure rather than text, such as finding function calls with specific arguments or async functions lacking try/catch. Plain grep is sufficient for literal string searches where syntax context does not matter.