Add Custom Code Rules
Custom Code Rules allow you to enforce team-specific coding standards and patterns unique to your organization. Create rules that detect specific code patterns, enforce naming conventions, or flag architectural violations that aren't covered by default checks.
What are Custom Code Rules?
Custom Code Rules are AI-powered checks that you define to match your team's specific requirements. Unlike default checks that apply general best practices, custom rules enforce standards unique to your codebase, architecture, or business logic.
Creating a Custom Code Rule
Define your rule
Navigate to Code Quality > Checks tab
Click Add Custom Code Rule
Write a clear description of what the rule should detect:
Example:
Allow only Alpine base images in Dockerfiles as base imagesGenerate and refine examples
Click Generate Examples to let AI create initial code samples
Review and modify the generated examples
Provide both compliant and non-compliant examples:
Compliant example:
# ✅ Code that follows the rule
FROM alpine:3.18
RUN apk add --no-cache nodejsNon-compliant example:
# ❌ Code that violates the rule
FROM ubuntu:latest
RUN apt-get update && apt-get install nodejsConfigure rule details
Once validated, provide additional information about your rule:
Title: Give your rule a clear, descriptive name
Use Alpine base images in Docker containersTL;DR: Write a brief summary of the issue
Non-Alpine base images increase container size and attack surfaceHow to fix: Provide actionable guidance for developers
Replace your base image with an Alpine Linux variant. For example, change 'FROM node:18' to 'FROM node:18-alpine'. You may need to adjust package installation commands from apt-get to apk.Click Save Rule to activate it
Your custom rule will now appear in the Checks tab and begin scanning new pull requests in enabled repositories.
Writing effective Custom Rules
Be specific and clear
❌ Too vague:
Use proper error handling✅ Specific and actionable:
All API endpoints must wrap database calls in try-catch blocks and return
standardized error responses with status codesFocus on patterns, not style
Custom rules work best for detecting logical patterns rather than formatting:
✅ Good custom rule candidates:
API authentication requirements
Database transaction patterns
Security header implementations
Business logic validations
❌ Better handled by linters:
Indentation and spacing
Bracket placement
Variable naming style
Common Custom Rule examples
Security rules
Architecture rules
API standards
Testing requirements
Documentation standards
Last updated
Was this helpful?