Rule Catalog
Get confused what ast-grep is? This is a list of rewriting rule to inspire you! Explore the power of ast-grep with these rewriting rules that can transform your code in seconds.
Feel free to join our Discord channel or ask Codemod AI to explain the rules for you line by line!
Rule List (63)(63)
- Append formatted bytes with `fmt.Appendf`📏
pattern💡constraints🛠️ Fix 📚 GoTry in Playground → - Avoid `&&` short circuit in JSX📏
kindhasnot🛠️ Fix 📚 TSXTry in Playground → - Avoid Duplicated Exports📏
allpatterninsidehas - Avoid nested links📏
patternhas - Avoid Unnecessary React Hook📏
anypattern+1💡utilsconstraints - Beware of char offset when iterate over a string📝Simple Pattern Example🛠️ Fix 📚 RustTry in Playground →
- Combine checks and trims with `CutPrefix` or `CutSuffix`📏
allpattern+2💡constraintstransform🛠️ Fix 📚 GoTry in Playground → - Detect Path Traversal Vulnerability in Rails📏
anypattern - Detect problematic defer statements with function calls📝Simple Pattern Example
- Detect problematic JSON tags with dash prefix📏
patterninside💡constraints - Ensure Clean Architecture📏
pattern💡constraints - Extract i18n Keys📏
kindpatternnot🛠️ Fix 📚 HTMLTry in Playground → - Find Dart Calls by Callee Name📏
anyallkindhas - Find Import File without Extension📏
regexkindanyinside - Find Import Identifiers📏
anyallkindhasinside+2 - Find Import Usage📏
kindpatterninside - Find key/value and Show Message📏
anypattern - Find loops that can range over an integer📏
pattern💡constraints - Find map copy loops that may use `maps.Copy`📏
pattern💡constraints - Find Struct Inheritance📝Simple Pattern Example
- Fix Format String Vulnerability📏
pattern💡constraints🛠️ Fix 📚 C++Try in Playground → - Get number of digits in a `usize`📝Simple Pattern Example🛠️ Fix 📚 RustTry in Playground →
- Match Function Call in C📏
pattern - Match Function Call in Golang📏
pattern - Match package import in Golang📏
kindhas - Migrate action_filter in Ruby on Rails📏
anypattern+1💡transform🛠️ Fix 📚 RubyTry in Playground → - Migrate OpenAI SDK📏
pattern🛠️ Fix 📚 PythonTry in Playground → - Migrate XState to v5 from v4📏
regexpattern+4💡utilstransform🛠️ Fix 📚 TypeScriptTry in Playground → - Missing Component Decorator📏
patterninside💡constraintslabels - No `await` in `Promise.all` array📏
patterninside🛠️ Fix 📚 TypeScriptTry in Playground → - No `console` except in `catch` block📏
anypattern+1💡constraints🛠️ Fix 📚 TypeScriptTry in Playground → - No Unused Vars in Java📏
kindallhasnot🛠️ Fix 📚 JavaTry in Playground → - Prefer `any` over `interface{}`📏
pattern🛠️ Fix 📚 GoTry in Playground → - Prefer `reflect.TypeFor`📏
pattern🛠️ Fix 📚 GoTry in Playground → - Prefer `slices.Clip`📏
pattern💡constraints🛠️ Fix 📚 GoTry in Playground → - Prefer `slices.Reverse`📏
pattern💡constraints🛠️ Fix 📚 GoTry in Playground → - Prefer `time.Since`📏
pattern🛠️ Fix 📚 GoTry in Playground → - Prefer Generator Expressions📏
patternkind💡transform🛠️ Fix 📚 PythonTry in Playground → - Prefer Symbol over Proc📏
pattern💡constraints🛠️ Fix 📚 RubyTry in Playground → - Recursive Rewrite Type📏
kindpattern💡rewriterstransform🛠️ Fix 📚 PythonTry in Playground → - Refactor pytest fixtures📏
kindfollows+1💡utils - Remove `async` function📏
pattern💡rewriterstransform🛠️ Fix 📚 PythonTry in Playground → - Remove redundant range-variable copies📏
allpatterninside🛠️ Fix 📚 GoTry in Playground → - Rename SVG Attribute📏
patternregex+2💡transform🛠️ Fix 📚 TSXTry in Playground → - 🛠️ Fix 📚 GoTry in Playground →
- Reverse React Compiler™📏
anypattern🛠️ Fix 📚 TSXTry in Playground → - Rewrite `indoc!` macro📝Simple Pattern Example🛠️ Fix 📚 RustTry in Playground →
- 🛠️ Fix 📚 PythonTry in Playground →
- Rewrite Check to Yoda Condition📏
patterninside💡constraints🛠️ Fix 📚 CTry in Playground → - Rewrite Method to Function Call📏
pattern💡transform🛠️ Fix 📚 CTry in Playground → - Rewrite MobX Component Style📏
pattern🛠️ Fix 📚 TSXTry in Playground → - Rewrite SQLAlchemy with Type Annotations📏
patternany💡rewriterstransform🛠️ Fix 📚 PythonTry in Playground → - Rust 2024 Let-Chain Candidate📏
matcheshas+5💡utils - Speed up Barrel Import📏
pattern💡rewriterstransform🛠️ Fix 📚 TypeScriptTry in Playground → - Stream split results with `SplitSeq` and `FieldsSeq`📏
pattern💡constraintstransform🛠️ Fix 📚 GoTry in Playground → - Switch Chai from `should` style to `expect`📏
anypattern🛠️ Fix 📚 TypeScriptTry in Playground → - Unnecessary `useState` Type📝Simple Pattern Example🛠️ Fix 📚 TSXTry in Playground →
- Unsafe Function Without Unsafe Block📏
allkindhasnot - Upgrade Ant Design Vue📏
kindregex+2💡utilsconstraints🛠️ Fix 📚 HTMLTry in Playground → - Use Logical Assignment Operators📝Simple Pattern Example
- Use Walrus Operator in `if` statement📏
patternfollows🛠️ Fix 📚 PythonTry in Playground →