Skip to content

Write review rules

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

A review rule is one of your team’s conventions, written in plain language and scoped to the files it applies to. Sourcery checks every pull request against it. Start with the things you keep repeating in review.

Rules live on the Review rules tab of Review Settings. They’re available on all plans, and were previously called custom rules.

  1. Open the Review rules tab

    Go to Review Settings and open the Review rules tab.

  2. Set the path patterns

    Add one or more globs under Path patterns, such as src/api/**. The rule applies only to files that match. Not sure how narrow to go? Leave it broad to apply everywhere.

  3. Write the rule

    Describe what Sourcery should check in the Rule field, which takes up to 3,000 characters of free-form text. Say what you want to see and what you want flagged.

Sourcery checks the rule against every changed file its path patterns match. Where the code breaks the rule, Sourcery posts an ordinary inline comment on the line in question. It has the same type (area): prefix as the rest of the review and quotes the rule underneath.

A rule adds checks to a review. Sourcery still raises the bugs and issues it would have raised on those files anyway. A rule only looks at the lines the pull request changes.

Path patterns: **

Every new public function needs a docstring that explains its purpose. Flag any new public function without one.

Path patterns: src/**/*.tsx

Custom React hooks must be named with a use prefix and live in src/hooks. Flag any hook declared elsewhere or named without the prefix.

Path patterns: src/api/**

Endpoints must validate request input before using it. Flag any handler that reads request data without validating it first, and suggest the validation to add.

Path patterns: **/*.py

We are migrating from requests to httpx. Flag any new code that imports requests and suggest the httpx equivalent.

Each one says what to flag and what you want instead.