Best Practices

Follow these guidelines to create maintainable and user-friendly settings.


Naming Conventions

Use Descriptive IDs

IDs should be clear and avoid conflicts with other expansions.

// ✅ Good - Descriptive and namespaced
{ id: "my-expansion-api-key", label: "API Key" }
{ id: "my-expansion-enable-sync", label: "Enable Sync" }
{ id: "my-expansion-max-items", label: "Maximum Items" }

// ❌ Bad - Generic and prone to conflicts
{ id: "key", label: "API Key" }
{ id: "enabled", label: "Enable Sync" }
{ id: "max", label: "Maximum Items" }

Follow Naming Patterns

Be consistent across your extension.

// ✅ Good - Consistent pattern
"expansion-api-key"
"expansion-api-endpoint"
"expansion-api-timeout"

// ❌ Bad - Inconsistent
"expansionAPIKey"
"api_endpoint"
"timeout-expansion"

Default Values

Always Provide Defaults

Every setting should have a sensible default value.

Choose Sensible Defaults

Defaults should work well for most users.


User Experience

Add Helpful Descriptions

Help users understand what each setting does.

Use Appropriate Element Types

Choose the right element for the data type.

Add Validation

Prevent invalid input with constraints.


Organization

Use Categories

Group related settings under category headers.

Use Separators

Add visual breaks between logical groups.

Order Logically

Place most important/common settings first.


Error Handling

Provide Fallback Values

Always handle missing or invalid settings.

Handle Async Errors

Properly handle errors when reading project settings.


Performance

Cache Settings

Don't read settings repeatedly in loops.

Use Event Listeners

React to changes instead of polling.


Security

Don't Expose Sensitive Data

Be careful with API keys and credentials.

Validate Input

Don't trust user input blindly.


Documentation

Add Placeholders

Show expected format in placeholders.

Use Hints

Provide additional context with hints.

Document Complex Settings

For advanced settings, provide clear explanations.


Testing

Test Default Values

Ensure defaults work correctly.

Test Edge Cases

Validate behavior with unusual inputs.


Common Mistakes to Avoid

❌ Not Providing Defaults

❌ Hardcoding Values

❌ Ignoring Types

❌ Not Validating Input


Quick Checklist

Before publishing your settings:


Next Steps

  • See complete examples →

  • Learn about custom elements →

  • Read API methods reference →

Last updated