Skip to content

Conversation

@stephen-carter-at-sf
Copy link
Contributor

No description provided.

Comment on lines -91 to +87
// TODO: We should remove this instantiation of new Ux in favor of possibly a new method on Display
new Ux({jsonEnabled: jsonEnabled})
.styledObject(rule, ['name', 'engine', 'runWith', 'isPilot', 'enabled', 'categories', 'rulesets', 'languages', 'description', 'message']);
private displayStyledRule(rule: DescribeStyledRule): void {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Handling this TODO right now because the testability is impossible without having this data tracked on our own Display object.

I confirmed that this did not break rule describe or rule describe --json in any way. Still outputting the same information and all of our other tests around this still pass.

column: occ.attributes.column as number,
endLine: occ.attributes.endline as number,
endColumn: occ.attributes.endcolumn as number,
line: Number(occ.attributes.line),
Copy link
Contributor Author

@stephen-carter-at-sf stephen-carter-at-sf Feb 8, 2024

Choose a reason for hiding this comment

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

It turns out that "as number" doesn't actually change the type here from string to number. So using "Number(...)" instead so that I can actually test it as a number.

}
}

export class Pmd7CommandInfo implements PmdCommandInfo {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a lot of code here at all. But I had to add quite a bit of testing (because of the poor health of our test code). All this new code is covered 100%.

// be OR'd together in this property.
defaultConfig?: ESRuleConfigValue;
url?: string;
message?: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In RuleDescribeAction, we referenced the 'message' field dynamically... but now i'm referencing it statically. This wasn't possible because we were missing the message field from our type here. So I fixed this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you help me understand what a "message" would be in a Rule object? "description" would be the description of the rule and the Violation type should have information that the engine returns, so I'm not sure what a "message" would be here.

Copy link
Contributor Author

@stephen-carter-at-sf stephen-carter-at-sf Feb 9, 2024

Choose a reason for hiding this comment

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

For example (even before my changes):
sf scanner rule describe -n ApexCRUDViolation
Would give a bunch of information including:
message: Validate CRUD permission before SOQL/DML operation or enforce user mode

const pathToCodeForCpd = path.join(codeFixturesDir, 'cpd');


describe("Tests for RunAction", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These new tests are practically end to end tests except that they do not invoke the scanner - but the action directly. Also, I removed the output processing since that is all tested separetely.

Eventually I believe we will be moving most of our end to end tests to this format - leaving only a few actual end to end tests behind to confirm that we are wired up correctly to the cli and the output processors.

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks good - thanks for adding them.

@stephen-carter-at-sf stephen-carter-at-sf merged commit c8f83ec into d/preview-pmd7 Feb 14, 2024
@stephen-carter-at-sf stephen-carter-at-sf deleted the d/W-14980290 branch February 14, 2024 23:35
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.

3 participants