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 and ask @ast-grep-bot to explain the rules for you line by line!
Rule List (36)(36)
- Avoid `&&` short circuit in JSXπ
kind
has
not
π οΈ Fix π TSXTry in Playground β - Avoid Duplicated Exportsπ
all
pattern
inside
has
- Avoid nested linksπ
pattern
has
- Avoid Unnecessary React Hookπ
any
pattern
+1
π‘utils
constraints
- Beware of char offset when iterate over a stringSimple Pattern Exampleπ οΈ Fix π RustTry in Playground β
- Ensure Clean Architectureπ
pattern
π‘constraints
- Extract i18n Keysπ
kind
pattern
not
π οΈ Fix π HTMLTry in Playground β - Find Import File without Extensionπ
regex
kind
any
inside
- Find Import Usageπ
kind
pattern
inside
- Find key/value and Show Messageπ
any
pattern
- 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
- Migrate action_filter in Ruby on Railsπ
any
pattern
+1
π‘transform
π οΈ Fix π RubyTry in Playground β - Migrate OpenAI SDKπ
pattern
π οΈ Fix π PythonTry in Playground β - Migrate XState to v5 from v4π
regex
pattern
+4
π‘utils
transform
π οΈ Fix π TypeScriptTry in Playground β - No `await` in `Promise.all` arrayπ
pattern
inside
π οΈ Fix π TypeScriptTry in Playground β - No `console` except in `catch` blockπ
any
pattern
+1
π‘constraints
π οΈ Fix π TypeScriptTry in Playground β - No Unused Vars in Javaπ
kind
all
has
not
- Prefer Generator Expressionsπ
pattern
kind
π‘transform
π οΈ Fix π PythonTry in Playground β - Prefer Symbol over Procπ
pattern
π‘constraints
π οΈ Fix π RubyTry in Playground β - Refactor pytest fixturesπ
kind
follows
+1
π‘utils
- Remove `async` functionπ
pattern
π‘rewriters
transform
π οΈ Fix π PythonTry in Playground β - Rename SVG Attributeπ
pattern
regex
+2
π‘transform
π οΈ Fix π TSXTry in Playground β - Reverse React Compilerβ’π
any
pattern
π οΈ Fix π TSXTry in Playground β - Rewrite `indoc!` macroSimple Pattern Exampleπ οΈ Fix π RustTry in Playground β
- Rewrite `Optional[Type]` to `Type | None`π
pattern
π οΈ Fix π PythonTry in Playground β - Rewrite Check to Yoda Conditionπ
pattern
inside
π‘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 β - Switch Chai from `should` style to `expect`π
any
pattern
π οΈ Fix π TypeScriptTry in Playground β - Unnecessary `useState` TypeSimple Pattern Exampleπ οΈ Fix π TSXTry in Playground β
- Upgrade Ant Design Vueπ
kind
regex
+2
π‘utils
constraints
π οΈ Fix π HTMLTry in Playground β - Use Walrus Operator in `if` statementπ
pattern
follows
π οΈ Fix π PythonTry in Playground β