Prioritize code readability by using clearer control structures, extracting complex expressions into descriptive variables, and choosing simpler syntax when available. This improves maintainability and makes code easier to understand for other developers.
Prioritize code readability by using clearer control structures, extracting complex expressions into descriptive variables, and choosing simpler syntax when available. This improves maintainability and makes code easier to understand for other developers.
Key practices:
<></>
instead of <React.Fragment>
when keys aren’t neededExample of improved readability:
// Instead of multiple if-else chains:
if (type === 'git' || type === 'oci') {
if (source.hasOwnProperty('chart')) {
source.path = source.chart;
delete source.chart;
source.targetRevision = 'HEAD';
}
} else if (type === 'helm') {
if (source.hasOwnProperty('path')) {
source.chart = source.path;
delete source.path;
source.targetRevision = '';
}
}
// Use switch statement:
switch (type) {
case 'git':
case 'oci':
if ('chart' in source) {
source.path = source.chart;
delete source.chart;
source.targetRevision = 'HEAD';
}
break;
case 'helm':
if ('path' in source) {
source.chart = source.path;
delete source.path;
source.targetRevision = '';
}
break;
}
// Extract complex expressions:
// Instead of inline complex logic:
const selectedApp = apps.find(app => AppUtils.appQualifiedName(app, useAuthSettingsCtx?.appsInAnyNamespaceEnabled) === val);
// Use descriptive temporary variable:
const qualifiedName = AppUtils.appQualifiedName(app, useAuthSettingsCtx?.appsInAnyNamespaceEnabled);
const selectedApp = apps?.find(app => qualifiedName === val);
Enter the URL of a public GitHub repository