1. What is an AST rule
An AST rule is a set of rules that applies to specific nodes of an AST (Abstract Syntax Tree). When the code is analyzed, Codiga generates the AST of your program and applies your rule to all the nodes of a specific type. An AST is a tree data structure that best represents the syntactic structure of the source code. They are a fundamental part of the way a compiler works. When a compiler transforms code, it follows these steps:
your code
123456
import loggingimport requestsΒ def my_function():Β Β foo = 1Β Β foobar()
Lexical Analysis
The lexical analysis breaks down the source code into tokens, it is also called tokenization.
π¦
Tokens
Syntax Analysis
It converts the tokens into a tree representing the current structure of the code.