Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHANGE: @W-17293079@: Update dependencies, refactor config command that fixes python_command issue #1691

Merged
merged 5 commits into from
Dec 5, 2024

Conversation

stephen-carter-at-sf
Copy link
Collaborator

No description provided.

@@ -62,15 +61,11 @@ export default class ConfigCommand extends SfCommand<void> implements Displayabl

protected createDependencies(outputFile?: string): ConfigDependencies {
const uxDisplay: UxDisplay = new UxDisplay(this, this.spinner);
const modelGeneratorFunction = /* istanbul ignore next - Model tested separately */ (relevantEngines: Set<string>, userContext: ConfigContext, defaultContext: ConfigContext) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an unnecessary dependency. No need to inject this dependency unless we have a reason to do so with regards to testing/etc... which we don't.

@@ -17,7 +17,6 @@ export enum BundleName {
ResultsWriter = 'results-writer',
RunAction = 'run-action',
RunCommand = 'run-command',
RunSummaryViewer = 'run-summary-viewer',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaned this up. Was unused.

private readonly config: CodeAnalyzerConfig; // TODO: It would be nice if we updated the CodeAnalyzer (in our core module) to just return its CodeAnalyzerConfig with a getter so we didn't need to pass it around
private readonly codeAnalyzer: CodeAnalyzer;
private readonly userRules: RuleSelection;
private readonly allDefaultRules: RuleSelection;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically I could have passed in a function that just gives me back the default rule since that's how we are using this. But it was easy enough to just pass this in.

But now we don't need to pass in all the values and config. So no more need for the ConfigContext stuff.

return this.toYamlUncheckedFieldWithInlineComment(fieldName, null, commentText);
} else if (JSON.stringify(userValue) === JSON.stringify(defaultValue)) {
return this.toYamlUncheckedField(fieldName, userValue);
private toYamlFieldUsingFieldDescription(fieldName: string, resolvedValue: unknown, fieldDescription: ConfigFieldDescription): string {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the name "resolvedValue" instead of "userValue" because it is post-resolution of the config... which mean it could be a calculated value like our python_command value for example.

@@ -147,7 +163,7 @@ abstract class YamlFormatter {

private getDefaultRuleFor(engineName: string, ruleName: string): Rule|null {
try {
return this.defaultContext.rules.getRule(engineName, ruleName);
return this.allDefaultRules.getRule(engineName, ruleName);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only place allDefaultRules is used. So like I said, I could have just passed in the getDefaultRuleFor method instead... but this was already here - so just keeping things as is.


let yamlCode: string = '\n' +
this.toYamlSectionHeadingComment(engineConfigDescriptor.overview!) + '\n' +
this.toYamlSectionHeadingComment(engineConfigDescriptor.overview) + '\n' +
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nice to be able to remove all these ! now that the core side has its own ConfigDescription which makes these values required (because it always fills it in).

indent(this.toYamlComment(fieldDescription), 2) + '\n' +
indent(this.toYamlField(configField, userValue, defaultValue), 2) + '\n';
indent(this.toYamlComment(fieldDescription.descriptionText), 2) + '\n' +
indent(this.toYamlFieldUsingFieldDescription(configField, userValue, fieldDescription), 2) + '\n';
}
return yamlCode.trimEnd();
}
}

class PlainYamlFormatter extends YamlFormatter {
Copy link
Collaborator Author

@stephen-carter-at-sf stephen-carter-at-sf Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There still is a bit of a code smell having to pass all these input arguments all around. Part of me thinks that we could maybe just give the Formatter the Model instead of passing the values through. But i'm on the fence because doing so means adding a bunch of getters to the model... so just leaving things as is.

(This is analogous to how our results object has a format method and the formatters inside of it then just receive the results object)

@@ -7,6 +7,6 @@
disable_engine: false

# Some description for top_field
top_field: # Modified from: null
top_field: # Modified from: {}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in a more appropriate default for this field - which is why the goldfile changed.

@@ -252,7 +249,7 @@ describe('ConfigAction tests', () => {
it.each([
{prop: 'config_root'},
{prop: 'log_folder'}
])(`When derivable property $prop input is non-null and non-default, it is rendered as-is with no comment`, async ({prop}) => {
])(`When derivable property $prop input is non-null and non-default, it is rendered as-is`, async ({prop}) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test description was incorrect. There is a comment - which is "#modified from: ". So fixed it.

const goldFileContents = (await readGoldFile(path.join(PATH_TO_COMPARISON_DIR, 'derivables-as-non-defaults', `${prop}.yml.goldfile`)))
.replace('__DUMMY_CONFIG_ROOT__', parentOfCurrentDirectory)
.replace('__DUMMY_LOG_FOLDER__', parentOfCurrentDirectory)
.replace('__DUMMY_DEFAULT_CONFIG_ROOT__', JSON.stringify(defaultConfig.getConfigRoot()))
.replace('__DUMMY_DEFAULT_LOG_FOLDER__', JSON.stringify(defaultConfig.getLogFolder()))
.replace('__DUMMY_DEFAULT_CONFIG_ROOT__', JSON.stringify(null))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only behavior change. If the user sets their own config_root or log_folder... there is no need to show the old calculated value... we just show "null" instead as I believe we should. For example, who cares if they see that by default we would have chosen a random temporary directory. So adding in the "Modified from: " here was better to just add in "null" as the value.

const goldFileContents = (await readGoldFile(path.join(PATH_TO_COMPARISON_DIR, 'derivables-as-non-defaults', `${prop}.yml.goldfile`)))
.replace('__DUMMY_CONFIG_ROOT__', parentOfCurrentDirectory)
.replace('__DUMMY_LOG_FOLDER__', parentOfCurrentDirectory)
.replace('__DUMMY_DEFAULT_CONFIG_ROOT__', JSON.stringify(defaultConfig.getConfigRoot()))
.replace('__DUMMY_DEFAULT_LOG_FOLDER__', JSON.stringify(defaultConfig.getLogFolder()))
.replace('__DUMMY_DEFAULT_CONFIG_ROOT__', JSON.stringify(null))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON.stringify(null) feels weird to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... I was a little lazy here. I could have just put 'null'.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@stephen-carter-at-sf stephen-carter-at-sf merged commit f105bfe into dev-5 Dec 5, 2024
12 checks passed
@stephen-carter-at-sf stephen-carter-at-sf deleted the sc/W-17293079 branch December 5, 2024 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants