Tutorials

Create Pattern Rules

BackNext

4. Write your rule

Now, it's time to write your rule! When there is a match for your pattern, the function visit is invoked by the static analyzer. This function is the one that reports errors in your code.

Let's first look at the function signature of the analysis rule:

1function visit(pattern, filename, code)
  1. pattern: this value represent the pattern that matches.
  2. filename: the filename being analyzed. For example, if the user edits the file foo/bar.py in their IDE, the value "foo/bar.py" will be passed for filename.
  3. code: the code as a text.

Let's go!

Start interacting with the tutorial!

my-new-rule.js

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.