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 (47)(47)
- 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 β
- 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 Import File without Extensionπ
regexkindanyinside - Find Import Identifiersπ
anyallkindhasinside+2 - Find Import Usageπ
kindpatterninside - Find Java field declarations of type Stringπ
kindhas - Find key/value and Show Messageπ
anypattern - 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 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 β - Rename SVG Attributeπ
patternregex+2π‘transformπ οΈ Fix π TSXTry in Playground β - Reverse React Compilerβ’π
anypatternπ οΈ Fix π TSXTry in Playground β - Rewrite `indoc!` macroπSimple Pattern Exampleπ οΈ Fix π RustTry in Playground β
- Rewrite `Optional[Type]` to `Type | None`π
patternπ οΈ 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 β - Speed up Barrel Importπ
patternπ‘rewriterstransformπ οΈ Fix π TypeScriptTry in Playground β - Switch Chai from `should` style to `expect`π
anypatternπ οΈ Fix π TypeScriptTry in Playground β - Unnecessary `useState` TypeπSimple Pattern Exampleπ οΈ Fix π TSXTry in Playground β
- 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 β