Skip to content

CHANGE: @W-16092798@: Introduce Workspace and update rule selection to take in a workspace #32

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

Merged
merged 2 commits into from
Jun 26, 2024

Conversation

stephen-carter-at-sf
Copy link
Collaborator

No description provided.

@stephen-carter-at-sf stephen-carter-at-sf force-pushed the sc/W-16092798 branch 3 times, most recently from 8ce56f2 to ec3c582 Compare June 26, 2024 19:43
this.uniqueIdGenerator = uniqueIdGenerator;
}

public async createWorkspace(filesAndFolders: string[]): Promise<Workspace> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Clients will need to use this to create a workspace first before they can call selectRules or runRules.

Comment on lines +29 to +34
async getExpandedFiles(): Promise<string[]> {
if (!this.expandedFiles) {
this.expandedFiles = await expandToListAllFiles(this.filesAndFolders);
}
return this.expandedFiles as 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.

This is where we get a big win. Instead of having each engine to do this themselves, the workspace object that they receive will be able to do this for them and cache the information so that other engines won't have to do it yet again.

@@ -16,3 +18,42 @@ export function changeWorkingDirectoryToPackageRoot() {
process.chdir(original_working_directory);
});
}

export class WorkspaceForTesting implements Workspace {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Eventually all these test tools for each of the various engines should probably end up in their own package. At that point maybe we'd call it @salesforce/code-analyzer-engine-test-helpers or something. Until then I'm fine living with the redundant code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Question: How feasible would it be to move these into the core module instead? Yeah, it's not their final destination, but it still cuts down the redundant code and minimizes the risk of divergence.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The engines don't and shouldn't depend on core. So either we move these into the engine-api or we put it into a test package. But yeah maybe the engine-api can have test helpers. I try not to bloat an api module though... so we'll defer this decision for now.

@stephen-carter-at-sf stephen-carter-at-sf changed the title CHANGE: @W-16092798@: Update rule selection to include workspace files CHANGE: @W-16092798@: Introduce Workspace and update rule selection to take in a workspace Jun 26, 2024
@@ -13,4 +13,16 @@ export class RealClock implements Clock {
now(): Date {
return new Date();
}
}

export interface UniqueIdGenerator {
Copy link
Contributor

Choose a reason for hiding this comment

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

I've typically used uuid for this sort of thing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The issue with uuid or any other utility is that for testing, I might need to fix the generated ids when doing equality checking. Same issue with clock or random number generator. Have to be able to fix things. Because I needed an interface anyway, a so I went with a simple counter approach.


expect(() => selection.getRule('stubEngine1', 'doesNotExist')).toThrow(
getMessage('RuleDoesNotExistInSelection', 'doesNotExist', 'stubEngine1'));
expect(() => selection.getRule('oopsEngine', 'stub1RuleD')).toThrow(
getMessage('RuleDoesNotExistInSelection', 'stub1RuleD', 'oopsEngine'));
});

it('When an engine returns multiple rules with the same name, then error', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm understanding correctly, this test got moved from add-engines to here because adding engines no longer intrinsically fetches all the rules from the engine the way it used to?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's right. I didn't remove any tests actually - they all got moved. And your understanding is spot on.

@@ -16,3 +18,42 @@ export function changeWorkingDirectoryToPackageRoot() {
process.chdir(original_working_directory);
});
}

export class WorkspaceForTesting implements Workspace {
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: How feasible would it be to move these into the core module instead? Yeah, it's not their final destination, but it still cuts down the redundant code and minimizes the risk of divergence.

@stephen-carter-at-sf stephen-carter-at-sf merged commit b38cffc into dev Jun 26, 2024
9 checks passed
@stephen-carter-at-sf stephen-carter-at-sf deleted the sc/W-16092798 branch June 26, 2024 20:41
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