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.
Write a rule
Section titled “Write a rule”-
Open the Review rules tab
Go to Review Settings and open the Review rules tab.
-
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. -
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.
How a rule changes a review
Section titled “How a rule changes a review”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.
Example rules
Section titled “Example rules”From your style guide
Section titled “From your style guide”Path patterns: **
Every new public function needs a docstring that explains its purpose. Flag any new public function without one.
From your naming conventions
Section titled “From your naming conventions”Path patterns: src/**/*.tsx
Custom React hooks must be named with a
useprefix and live insrc/hooks. Flag any hook declared elsewhere or named without the prefix.
From your architecture rules
Section titled “From your architecture rules”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.
From a migration in flight
Section titled “From a migration in flight”Path patterns: **/*.py
We are migrating from
requeststohttpx. Flag any new code that importsrequestsand suggest thehttpxequivalent.
Each one says what to flag and what you want instead.