Create AST Rules


Get Started

This tutorial explains how to write an AST rule for Python. An AST rule let you target nodes in an Abstract Syntax Tree, which is the most accurate way to check the content of a program while avoiding false positives.


  1. You will learn what an AST is.
  2. You will learn how an AST rule works.
  3. You will learn how an AST rule works.

You are going to write an analysis rule that:

  1. Checks if the function print is called with the string parameter "foo".
  2. Replace the string "foo" with "bar".
  3. You will learn how an AST rule works.

To make a rule, we need to go through the following steps:

  1. Create a ruleset
  2. Create a rule
  3. Write the rule
  4. Add some tests

All the code in the rules is written in


This is a pattern rule for


Click next at the top for a walkthrough step by step.

Codiga Logo
Codiga Hub
  • Rulesets
  • Playground
  • Snippets
  • Cookbooks
soc-2 icon

We are SOC-2 Compliance Certified

G2 high performer medal

Codiga – All rights reserved 2022.