Skip to content

Commit a8be747

Browse files
Simplify comments for config based fields
1 parent 219e83a commit a8be747

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/lib/models/ConfigModel.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,23 @@ abstract class YamlFormatter {
8686
return yamlCode.replace(/(\r?\n|$)/, ` ${comment}$1`);
8787
}
8888

89-
private toYamlFieldUsingFieldDescription(fieldName: string, resolvedValue: unknown, fieldDescription: ConfigFieldDescription): string {
89+
private toYamlFieldWithFieldDescription(fieldName: string, resolvedValue: unknown, fieldDescription: ConfigFieldDescription): string {
9090
const resolvedValueJson: string = JSON.stringify(resolvedValue);
9191
const defaultValueJson: string = JSON.stringify(fieldDescription.defaultValue);
9292

93+
let yamlField: string;
9394
if (!fieldDescription.wasSuppliedByUser && resolvedValueJson !== defaultValueJson) {
9495
// Whenever the user did not supply the value themselves but the resolved value is different from the
9596
// default value, this means the value was not a "fixed" value but a value "calculated" at runtime.
9697
// Since "calculated" values often depend on the specific environment, we do not want to actually hard code
9798
// this value into the config since checking in the config to CI/CD system may create a different value.
9899
const commentText: string = getMessage(BundleName.ConfigModel, 'template.last-calculated-as', [resolvedValueJson]);
99-
return this.toYamlUncheckedFieldWithInlineComment(fieldName, fieldDescription.defaultValue, commentText);
100+
yamlField = this.toYamlUncheckedFieldWithInlineComment(fieldName, fieldDescription.defaultValue, commentText);
101+
} else {
102+
yamlField = this.toYamlField(fieldName, resolvedValue, fieldDescription.defaultValue);
100103
}
101104

102-
return this.toYamlField(fieldName, resolvedValue, fieldDescription.defaultValue);
105+
return this.toYamlComment(fieldDescription.descriptionText) + "\n" + yamlField
103106
}
104107

105108
private toYamlField(fieldName: string, resolvedValue: unknown, defaultValue: unknown): string {
@@ -119,12 +122,10 @@ abstract class YamlFormatter {
119122
const topLevelDescription: ConfigDescription = this.config.getConfigDescription();
120123
return this.toYamlSectionHeadingComment(topLevelDescription.overview) + '\n' +
121124
'\n' +
122-
this.toYamlComment(topLevelDescription.fieldDescriptions.config_root.descriptionText) + '\n' +
123-
this.toYamlFieldUsingFieldDescription('config_root', this.config.getConfigRoot(),
125+
this.toYamlFieldWithFieldDescription('config_root', this.config.getConfigRoot(),
124126
topLevelDescription.fieldDescriptions.config_root) + '\n' +
125127
'\n' +
126-
this.toYamlComment(topLevelDescription.fieldDescriptions.log_folder.descriptionText) + '\n' +
127-
this.toYamlFieldUsingFieldDescription('log_folder', this.config.getLogFolder(),
128+
this.toYamlFieldWithFieldDescription('log_folder', this.config.getLogFolder(),
128129
topLevelDescription.fieldDescriptions.log_folder) + '\n' +
129130
'\n' +
130131
this.toYamlComment(topLevelDescription.fieldDescriptions.rules.descriptionText) + '\n' +
@@ -206,8 +207,7 @@ abstract class YamlFormatter {
206207
const resolvedValue = userEngineConfig[configField] ?? fieldDescription.defaultValue;
207208
// Add a leading newline to visually break up the property from the previous one.
208209
yamlCode += '\n' +
209-
indent(this.toYamlComment(fieldDescription.descriptionText), 2) + '\n' +
210-
indent(this.toYamlFieldUsingFieldDescription(configField, resolvedValue, fieldDescription), 2) + '\n';
210+
indent(this.toYamlFieldWithFieldDescription(configField, resolvedValue, fieldDescription), 2) + '\n';
211211
}
212212
return yamlCode.trimEnd();
213213
}

0 commit comments

Comments
 (0)