用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/Mte90/dotfiles --skill ast-grep命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Django authentication - local accounts, social OAuth, registration, email verification, MFA, session management
django-filter - Django filtering library for querysets with Django REST Framework integration
Build modern dynamic web applications with Django and htmx - partial rendering, HTMX-specific responses, and seamless frontend integration
正在显示 SKILL.md
| name | ast-grep |
| description | ast-grep - Fast structural code search, linting, and rewriting CLI tool |
| metadata | {"author":"mte90","version":"1.0.0","tags":["ast-grep","code-search","linting","refactoring","cli","ast"]} |
Fast and user-friendly tool for large-scale code searching, linting, and rewriting using AST patterns.
ast-grep (sg) is a CLI tool that searches code based on Abstract Syntax Tree patterns, similar to syntax-aware grep/sed. It supports multiple languages and can perform automated code refactoring.
all, any, and not operatorsinside, has, precedes# Via cargo
cargo install ast-grep
# Via npm
npm install -g ast-grep
# Via pip
pip install ast-grep
# Download pre-built binary
curl -L https://github.com/ast-grep/ast-grep/releases/download/nightly/ast-grep-x86_64-unknown-linux-musl.tar.gz | tar xz
# Basic pattern search - find all console.log calls
ast-grep run --pattern 'console.log($ARG)' --lang javascript src/
# Short form with language inference from file extensions
ast-grep -p 'console.log($ARG)' src/
# Search with multiple arguments using multi-metavariable
ast-grep -p 'console.log($$$ARGS)' src/
# Search for function declarations
ast-grep -p 'function $NAME($$$PARAMS) { $$$ }' --lang typescript src/
# Debug pattern parsing
ast-grep -p 'console.log($A)' --lang javascript --debug-query=ast
# Show context around matches
ast-grep -p 'TODO' --context 3 src/
# Search and rewrite - add optional chaining
ast-grep -p '$OBJ.val && $OBJ.val()' --rewrite '$OBJ.val?.()' src/
# Interactive mode - confirm each replacement
ast-grep -p '$PROP && $PROP()' -r '$PROP?.()' --interactive src/
# Apply all rewrites without confirmation
ast-grep -p 'var $X' -r 'let $X' --update-all src/
# Output results as JSON for piping to other tools
ast-grep -p 'import $$$' --json src/ | jq '.[] | .text'
# Scan with a single rule file
ast-grep scan --rule rules/no-console.yml src/
# Scan with project configuration (sgconfig.yml)
ast-grep scan --config sgconfig.yml src/
# Scan with inline rule (no file needed)
ast-grep scan --inline-rules '
id: no-debugger
language: JavaScript
rule:
pattern: debugger
' src/
# Filter rules by ID pattern
ast-grep scan --filter 'security-*' src/
# Output in SARIF format for CI integration
ast-grep scan --format sarif src/
# Set rule severity via CLI
ast-grep scan --error=no-console --warning=prefer-const src/
# GitHub Actions compatible output
ast-grep scan --format github src/
$VAR - Matches single AST node$$$VARGS - Matches zero or more AST nodes (variadic)# JavaScript/TypeScript
'console.log($MSG)' # Single argument
'console.log($$$ARGS)' # Multiple arguments
'function $NAME($$$PARAMS) { $$$ }' # Function declaration
'const $X = $Y' # Variable declaration
'$X && $X()' # Conditional call
# Python
'def $FUNC($$$ARGS): $$$' # Function definition
'class $NAME($$$BASE): $$$' # Class definition
'import $X from $Y' # Named import
'from $X import $$$' # From import
'for $X in $Y: $$$' # For loop
# Explicit language
ast-grep -p 'pattern' --lang typescript src/
# Auto-detect from file extension
ast-grep -p 'pattern' src/
# rules/no-console.yml
id: no-console
message: "Do not use console.log in production"
severity: warning
language: JavaScript
rule:
pattern: console.log($ARG)
# sgconfig.yml
rules:
- id: no-var
message: "Use let/const instead of var"
severity: warning
language: JavaScript
rule:
pattern: var $X
fix:
rewrite: let $X
- id: prefer-const
message: "Use const for variables not reassigned"
severity: warning
language: JavaScript
rule:
pattern: let $X = $Y
from: $Y
where:
- $Y
fix:
rewrite: const $X = $Y
id: security-no-inner-html
message: "Setting innerHTML can lead to XSS attacks"
severity: error
language: TypeScript
rule:
pattern: |
$EL.innerHTML = $SOURCE
fix:
rewrite: |
$EL.textContent = $SOURCE
scope: script
# .github/workflows/lint.yml
name: ast-grep
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run ast-grep
uses: ast-grep/ast-grep-action@latest
with:
args: scan --format github src/
# .pre-commit-config.yaml
repos:
- repo: https://github.com/ast-grep/ast-grep
rev: stable
hooks:
- id: ast-grep
args: ['--config', 'sgconfig.yml', 'scan']
Install from VS Code Marketplace: ast-grep
Features:
ast-grep -p 'TODO' --lang typescript src/
ast-grep -p 'console.log($$$ARGS)' --rewrite '' --update-all src/
ast-grep -p 'var $X' -r 'const $X' --lang javascript --update-all src/
ast-grep -p 'class $NAME extends React.Component { $$$ }' \
--rewrite 'class $NAME extends React.Component {
componentDidCatch(error, info) {
console.error(error, info);
}
$$$ }' \
--lang javascript --update-all src/
# Define rule in YAML
# rules/no-unused-vars.yml
id: no-unused-vars
language: TypeScript
rule:
pattern: |
const $NAME = $VALUE
where:
- $VALUE
scope: code
# Find fetch calls inside useEffect
id: fetch-in-useeffect
language: TypeScript
rule:
all:
- pattern: 'fetch($ARGS)'
- inside:
pattern: 'useEffect(() => { $$$ }, $$$)'
# Find async functions that use await but lack try-catch
id: async-without-try
language: TypeScript
rule:
all:
- pattern: 'async function $F($$$) { $$$ }'
- has:
pattern: 'await $EXPR'
- not:
inside:
pattern: 'try { $$$ } catch { $$$ }'
# Detect eval() usage
id: no-eval
language: JavaScript
message: "eval() is dangerous - potential code injection"
severity: error
rule:
pattern: 'eval($ARG)'
# Detect hardcoded passwords
id: hardcoded-secret
language: Python
message: "Hardcoded credentials detected"
severity: error
rule:
pattern: |
password = '$PASS'
# Test pattern without rewriting
ast-grep -p 'pattern' src/
# Then run with --dry-run equivalent (no --update-all)
ast-grep -p 'pattern' --rewrite 'new_pattern' --interactive src/
# Explicit language avoids ambiguity
ast-grep -p '$X' --lang python src/
ast-grep -p 'console.log' --json src/ | jq '.[] | .file_path'
# Find files modified in git and search
git diff --name-only HEAD~1 | xargs ast-grep -p 'pattern'
# Search and format
ast-grep -p 'pattern' --json src/ | jq -r '.[].file_path' | xargs prettier --write
ast-grep run --pattern before applying fixes--interactive mode for important rewritessgconfig.yml for project-wide rules--lang flag to avoid ambiguity--update-all without testing pattern first