Skip to content

Enhance PSShouldProcess rule to check for ShouldProcess in nested functions #625

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 19 commits into from
Oct 4, 2016

Conversation

kapilmb
Copy link

@kapilmb kapilmb commented Sep 29, 2016

Resolves #521
Resolves #608
Resolves #194


This change is Reviewable

Kapil Borle added 12 commits September 28, 2016 11:07
The new implementation adds ability to check if a nested function calls shouldprocess/shouldcontinue when an upstream function declares SupportsShouldProcess attribute.
If a cmdlet declares SupportsShouldProcess attribute, it must call ShouldProcess but calling ShouldContinue is optional.
@@ -3555,4 +3555,239 @@ public object VisitUsingExpression(UsingExpressionAst usingExpressionAst)
return null;
}
}

/// Class to represent a directed graph
public class Digraph<T>

Choose a reason for hiding this comment

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

Consider making this an internal class for now. We can open it up as public as the scenarios evolve.

Copy link
Author

Choose a reason for hiding this comment

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

We use Pester for our testing purposes. If I make it internal, how do I go about testing? I do not think I will be able find the type in Pester tests if it is internal.

}

/// <summary>
/// Construct digraph with an EqualityComparer used for comparing type T

Choose a reason for hiding this comment

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

Is it possible for you to give more details in the summary

/// Check if the given vertex is part of the graph.
///
/// If the vertex is null, it will throw an ArgumentNullException.
/// If the vertex is non-null but not present in the graph, it will throw an ArgumentOutOfRangeException

Choose a reason for hiding this comment

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

Why not just return null in this case instead of throwing an exception

Copy link
Author

Choose a reason for hiding this comment

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

Line 3608 is not applicable for this method (ContainsVertex). I will remove it. The method ContainsVertex expects a non-null object for comparison and returns a bool type.

/// <returns>True if the vertices are conneted, otherwise false</returns>
private bool IsConnected(int fromIdx, int toIdx, ref bool[] visited)
{
visited[fromIdx] = true;

Choose a reason for hiding this comment

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

I understand you are doing the marking here..but i dont see where the cleanup happens.

Copy link
Author

Choose a reason for hiding this comment

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

visited is cleaned up when public bool IsConnected(T vertex1, T vertex2) returns.

Context "Where ShouldProcess is called in nested function" {
It "finds no violation" {
$scriptDef = @'
function Outer

Choose a reason for hiding this comment

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

have a testcase related to recursion

@kapilmb kapilmb merged commit b69b813 into development Oct 4, 2016
@kapilmb kapilmb deleted the kapilmb/PSShouldProcessNestedFunctions branch October 4, 2016 20:55
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