Avoid scattering configuration defaults, validation, and loading logic across multiple functions. Instead, centralize these concerns in dedicated configuration modules or at the entry points of your application.
Avoid scattering configuration defaults, validation, and loading logic across multiple functions. Instead, centralize these concerns in dedicated configuration modules or at the entry points of your application.
Problems with scattered configuration:
Best practices:
Example of the problem:
// Scattered defaults - AVOID
function buildClient({ target = 'nodejs' }) { /* ... */ }
function generateClient({ target = 'nodejs' }) { /* ... */ }
function processConfig({ target = 'nodejs' }) { /* ... */ }
Better approach:
// Centralized configuration - PREFER
const DEFAULT_CONFIG = {
target: 'nodejs',
// other defaults...
};
function buildClient({ target = DEFAULT_CONFIG.target }) { /* ... */ }
function generateClient(options = DEFAULT_CONFIG) { /* ... */ }
This approach makes configuration changes easier to manage, reduces the risk of inconsistent defaults, and improves code maintainability by having a single source of truth for configuration values.
Enter the URL of a public GitHub repository