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.
Objectives
- You will learn what an AST is.
- You will learn how an AST rule works.
- You will learn how an AST rule works.
You are going to write an analysis rule that:
- Checks if the function print is called with the string parameter "foo".
- Replace the string "foo" with "bar".
- You will learn how an AST rule works.
To make a rule, we need to go through the following steps:
- Create a ruleset
- Create a rule
- Write the rule
- Add some tests
All the code in the rules is written in
JavaScriptThis is a pattern rule for
PythonClick next at the top for a walkthrough step by step.