moai-tool-ast-grep

Search and transform code patterns across languages using AST-Grep.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/binee108/PasteTrader --skill moai-tool-ast-grep-binee108
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: moai-tool-ast-grep
Source: https://github.com/binee108/PasteTrader/tree/main/.claude/skills/moai-tool-ast-grep
Command: npx skills add https://github.com/binee108/PasteTrader --skill moai-tool-ast-grep-binee108

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill enables developers to perform fast, language-agnostic structural code searches and transformations using AST-Grep (sg) patterns, helping teams enforce security, refactor across codebases, and migrate APIs.

Core Features & Use Cases

  • Pattern-based search: find code patterns across languages using sg patterns.
  • Code transformations: apply codemods with fix blocks to refactor at scale.
  • Security scanning & quality checks: detect risky patterns and deprecated APIs across repositories.
  • Use Case: Migrate a legacy codebase to modern syntax across multiple services with minimal manual edits.

Quick Start

Use sg to search and transform code patterns across a codebase. For example: sg run --pattern 'console.log($$$ARGS)' --lang javascript src/ sg run --pattern 'var $NAME = $VALUE' --rewrite 'const $NAME = $VALUE' --lang javascript src/ sg scan --config sgconfig.yml

Frequently Asked Questions about moai-tool-ast-grep

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

FAQPage Schema
How do I refactor var declarations to const across a large codebase?

Use ast-grep (sg) to apply pattern-based code transformations and codemods at scale. By running sg with a rewrite rule like 'var $NAME = $VALUE' to 'const $NAME = $VALUE', you can refactor legacy syntax across large repositories with minimal manual edits.

What is structural code search and how does ast-grep pattern matching work?

Structural code search finds code patterns by matching abstract syntax trees rather than plain text. Ast-grep (sg) performs language-agnostic pattern matching, allowing you to identify and transform code structures across multiple languages with relational rule constraints like inside, has, follows, and precedes.

Can I run security scanning and detect deprecated APIs across multiple languages?

Yes, you can run security scanning and quality checks across repositories using sg scan with a defined sgconfig.yml. It detects risky code patterns and deprecated APIs language-agnostically by applying structural pattern matching rules configured in your modules.

How do I find and remove console.log statements in JavaScript files?

You can find console.log statements by running an sg pattern search like 'console.log($$$ARGS)' with the JavaScript language flag on your source directory. This structural search identifies matching AST nodes across the codebase for targeted removal or refactoring.

Does ast-grep support codemod transformations for API migrations?

Yes, ast-grep supports codemod transformations using fix blocks defined in rule files. This allows you to migrate legacy codebases to modern syntax or new APIs across multiple services structurally, ensuring consistent and automated code refactoring.