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

PsShouldProcess - ShouldContinue not included #1305

Draft
wants to merge 2 commits into
base: master
from

Conversation

@JohnLBevan
Copy link

JohnLBevan commented Aug 9, 2019

fixes #1304

Bevan, John - Technical Architect added 2 commits Aug 9, 2019
Copy link
Collaborator

bergmeister left a comment

Thanks.
Code looks very clean and awesome that you added quite a few test cases :-)
I'd be very happy taking this PR.
After re-reading the docs on ShouldContinue, I have an idea for additional (optional) feature since the docs say:

Cmdlets using ShouldContinue should also offer a "bool Force" parameter which bypasses the calls to ShouldContinue and ShouldProcess.

https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.cmdlet.shouldcontinue

If we could also check for the usage of the -Force pattern (not sure how difficult or possible it is), then that would be great. Again, this could be an optional, separate, follow up PR in addition to this awesome PR, would you be interested in doing that as well (no pressure)?

@JohnLBevan
Copy link
Author

JohnLBevan commented Aug 10, 2019

Thanks @bergmeister.

I'd be happy to give it a go sometime; though my knowledge of parsers isn't great / this fix was easy to code since I could mostly steal from the existing efforts made for ShouldProcess.

FYI: There is already a rule to ensure that the Force parameter is included: PSAvoidShouldContinueWithoutForce.

However, that rule can currently be fooled by adding the switch to the function's parameters, then neglecting to use it. I've created new issue: #1308 to track this.

@bergmeister bergmeister requested review from JamesWTruher and rjmholt Jan 28, 2020
@bergmeister
Copy link
Collaborator

bergmeister commented Jan 28, 2020

@rjmholt @JamesWTruher I would be happy to merge this change in, are you ok with it as well?

Copy link
Member

rjmholt left a comment

Sorry, didn't see this PR when it was originally opened. A couple of small suggestions, but not blocking.

return functionDefinitionAst.Extent;
}

return (invokeMemberExpressionAstFound as InvokeMemberExpressionAst).Member.Extent;

This comment has been minimized.

@rjmholt

rjmholt Jan 28, 2020 Member

Suggested change
return (invokeMemberExpressionAstFound as InvokeMemberExpressionAst).Member.Extent;
return ((InvokeMemberExpressionAst)invokeMemberExpressionAstFound).Member.Extent;
/// </summary>
private static bool IsShouldContinueCall(Ast ast)
{
var invokeMemberExpressionAst = ast as InvokeMemberExpressionAst;

This comment has been minimized.

@rjmholt

rjmholt Jan 28, 2020 Member

Might be nicer to do this:

return ast is InvokeMemberExpressionAst invokeMemberExpressionAst
    && invokeMemberExpressionAst.Member is StringConstantExpressionAst memberExprAst
    && string.Equals(memberExprAst.Value, "ShouldContinue", StringComparison.OrdinalIgnoreCase);
private bool callsShouldProcessDirectly(Vertex vertex)
{
return funcDigraph.GetNeighbors(vertex).Contains(shouldProcessVertex);
}
private bool callsShouldContinueDirectly(Vertex vertex)

This comment has been minimized.

@rjmholt

rjmholt Jan 28, 2020 Member

Suggested change
private bool callsShouldContinueDirectly(Vertex vertex)
private bool callsShouldContinueDirectly(Vertex vertex)
@bergmeister
Copy link
Collaborator

bergmeister commented Jun 11, 2020

@rjmholt Should we merge this PR as-is since @JohnLBevan hasn't provided any updates and did not tick the option for other people to allow push to his branch? We could then do a follow-up PR.

@JohnLBevan JohnLBevan marked this pull request as draft Jul 31, 2020
@JohnLBevan
Copy link
Author

JohnLBevan commented Jul 31, 2020

Apologies, I missed your comments from Jan. I'm happy to make the suggested changes, though think I deleted the original branch a while back (i.e. the source of the pull request now shows as unknown repository, and I can't find a way to get it back, or to enable the allow edits from maintainers flag...
I'll try to pick this up over the weekend, maybe creating a new PR based on the current state of the code to minimise differences.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants
You can’t perform that action at this time.