Skip to main content

ast-grep

Structural code search via ast-grep — use when code shape and element relationships matter, not just text. E.g., "find async functions without error handling", "refactor foo(a, b) to foo({ a, b })". Use Grep for simple name lookups.

설치로 이동

소스 정보

저장소
poteto/noodle
최근 소스 활동
2026년 3월 19일 04:43
감지된 SKILL.md 언어
영어
스타
277
포크
16

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

파일 탐색기
2 개 파일

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
ast-grep
description
Structural code search via ast-grep — use when code shape and element relationships matter, not just text. E.g., "find async functions without error handling", "refactor foo(a, b) to foo({ a, b })". Use Grep for simple name lookups.
# ast-grep ## Workflow 1. Write a test snippet representing the target code 2. Write the rule (start with `pattern`, escalate to `kind` + `has`/`inside` if needed) 3. Test with `--stdin` before searching the codebase 4. Search the codebase once the rule matches ## Critical Gotchas ### Always use `stopBy: end` on relational rules Without it, `has`/`inside` stop at the first non-matching node instead of traversing the full subtree: ```yaml # WRONG — will miss deeply nested matches has: pattern: await $EXPR # RIGHT has: pattern: await $EXPR stopBy: end ``` ### Escape metavariables in shell `$VAR` gets interpreted by the shell. Either escape or single-quote: ```bash # Double-quoted: escape with backslash ast-grep scan --inline-rules "id: test language: javascript rule: pattern: await \$EXPR" . # Single-quoted: no escaping needed ast-grep scan --inline-rules 'id: test language: javascript rule: pattern: await $EXPR' . ``` ### Metavariables must be the sole content of an AST node These **don't work**: `obj.on$EVENT`, `"Hello $WORLD"`, `a $OP b`, `$jq` Use `$$OP` for unnamed nodes (operators, punctuation). Use `$$$ARGS` for zero-or-more nodes. ## Testing with --stdin ```bash echo "async function test() { await fetch(); }" | ast-grep scan --inline-rules 'id: test language: javascript rule: kind: function_declaration has: pattern: await $EXPR stopBy: end' --stdin ``` ## Debugging with --debug-query When rules don't match, inspect the AST to find correct `kind` values: ```bash ast-grep run --pattern 'your code here' --lang javascript --debug-query=cst ``` Formats: `cst` (all nodes), `ast` (named only), `pattern` (how ast-grep sees your pattern). ## Rule syntax See `references/rule_reference.md` for the full rule reference (atomic, relational, composite rules, and metavariables).
GitHub에서 보기