Flag Naming Conventions
Consistent naming conventions make your feature flags easier to understand, search, and manage. This guide covers best practices for naming flags and how to enforce conventions using Flagsmith's built-in validation.
Why naming conventions matterβ
Feature flag names serve as identifiers throughout your codebase and within Flagsmith. A clear, consistent naming approach helps your team:
- Find flags quickly when searching in the dashboard or code
- Understand flag purpose at a glance without reading documentation
- Avoid naming conflicts as your flag count grows
- Maintain consistency across teams and projects
Features cannot be renamed after creation. Choose names carefully, as you'll need to create a new flag and migrate if you want to change a name later.
Naming best practicesβ
Use descriptive, self-explanatory namesβ
Flag names should communicate their purpose clearly. Anyone reading the name should understand what the flag controls without needing additional context.
| Recommended | Not recommended | Why |
|---|---|---|
show_beta_dashboard | flag1 | Describes what the flag controls |
enable_stripe_payments | payments | Specifies the integration being toggled |
max_upload_size_mb | size | Indicates the value type and unit |
allow_guest_checkout | gc | Avoids cryptic abbreviations |
Choose a consistent formatβ
Pick a naming format and apply it consistently across your project. Common conventions include:
| Format | Example | Notes |
|---|---|---|
snake_case | enable_dark_mode | Most common, easy to read |
kebab-case | enable-dark-mode | Common in web development |
camelCase | enableDarkMode | Matches JavaScript conventions |
SCREAMING_SNAKE_CASE | ENABLE_DARK_MODE | Often used for constants |
Consider prefixes and suffixes for organisationβ
Prefixes and suffixes can help group related flags and make searching easier:
Common prefixes:
feature_for new functionality:feature_new_checkout_flowexperiment_for A/B tests:experiment_pricing_page_variantops_for operational flags:ops_maintenance_modekill_for kill switches:kill_external_api_calls
Common suffixes:
_enabledfor feature availability flags:fb_ads_enabled,dark_mode_enabled_limitor_maxfor configuration values:upload_size_limit,retry_max
Keep names concise but meaningfulβ
Aim for names that are long enough to be descriptive but short enough to be practical. A good rule of thumb is 2-5 words.
Think about impact and contextβ
When naming a flag, consider what information future maintainers need to know. A well-chosen name should help answer:
- Which feature does this flag relate to?
- What happens when the flag is changed?
- Which users are affected by this flag?
- Which components or services use this flag?
For example, checkout_guest_users_enabled clearly indicates it affects the checkout feature, relates to guest users, and can be toggled on or off.
Add descriptions to your flagsβ
Whilst flag names cannot be changed after creation, descriptions can be updated at any time. Use the description field to provide context that doesn't fit in the name:
- Purpose: Why was this flag created?
- Scope: Which features, services, or components does it affect?
- Timeline: Is this temporary or permanent?
- Dependencies: Does it relate to other flags or external systems?
A clear description helps team members understand the flag's purpose even after 6 months, reducing the need to search through code or documentation.
Treat flag descriptions like code commentsβthey should explain the "why" and "what", not just repeat the flag name.
Enforcing naming conventionsβ
Flagsmith allows you to enforce naming conventions at the project level using regular expressions. When configured, new flags must match the pattern before they can be created.
Configuring regex validationβ
- Navigate to Project Settings β General
- Enable Feature Name RegEx
- Enter your regex pattern
- Click Save
Once configured, any attempt to create a flag that doesn't match the pattern will be rejected with a validation error.
Example regex patternsβ
Here are common patterns you can use or adapt:
| Pattern | Description | Valid examples |
|---|---|---|
^[a-z][a-z0-9_]*$ | Lowercase snake_case | enable_feature, max_retries |
^[a-z][a-z0-9-]*$ | Lowercase kebab-case | enable-feature, max-retries |
^[a-z][a-zA-Z0-9]*$ | camelCase starting lowercase | enableFeature, maxRetries |
^[A-Z][A-Z0-9_]*$ | SCREAMING_SNAKE_CASE | ENABLE_FEATURE, MAX_RETRIES |
^(feature|experiment|ops)_[a-z0-9_]+$ | Required prefix with snake_case | feature_checkout, ops_debug |
Test your regex pattern using the Test RegEx button before saving. This lets you verify the pattern works as expected with example flag names.
Pattern requirementsβ
The regex validation in Flagsmith:
- Automatically anchors patterns with
^at the start and$at the end - Uses standard JavaScript regex syntax
- Applies only to new flags (existing flags are not affected)
Tag naming conventionsβ
In addition to flag names, consider establishing conventions for tags. Tags help you categorise and filter flags, so consistent naming makes them more useful.
Common tag conventions:
- Use lowercase with hyphens:
backend,mobile-app,q1-2024 - Group by purpose:
team-payments,team-auth,deprecated - Include lifecycle stage:
rollout-complete,ready-to-remove
Further readingβ
- Feature Flag Lifecycles - understanding when to remove flags
- Structuring Your Projects - organising flags across projects
- Tagging - using tags to categorise flags