Closed LaurentDardenne closed 1 year ago
Filter
function Get-Square2 { $_ * $_ }; Filter Get-Square2 { $_ * $_ }
A function with a particular behavior.
@LaurentDardenne would you have a proposal for what explanations for these should look like?
Please note that function
and filter
both do not have an explanation in the code base yet.
>>would you have a proposal for what explanations for these should look like? I was thinking of a note associated with the statement definition. For the following example:
[void]$T.Add(1) ; $T.Add(2) > $null
The objective is identical but the syntax is different, here it is more an intention that needs to be explained, it is a recognition of instruction patterns.
A good suggestion I think.
For the [void] type, that would be easy to do I think, as the only possible intent can be to suppress output, and only TypeConstraintAst is in play.
For the ... > $null
situation, which is similar to $null = ...
and ... | Out-Null
, the intent is the same, but will be harder to catch to provide the correct explanation, because at least two Ast's together produce the intent. Out-Null already has a description that conveys this intent. That only leaves $null with an assignment and $null with a redirection. I think we can handle this at the variableExpressionAst -> if the variable name is 'null', check parent Ast's. If it is either assignment (left hand side) or redirection (right hand side), add text to the description to explain the intent of suppressing output.
Could be done.
>>For the ... > $null situation, which is similar to $null = ... and ... | Out-Null, the intent is the same, >> but will be harder to catch to provide the correct explanation, Yes, this is similar to the analyzes of PSSA.
For Out-null the documentation is explicit and logically an Out-xxx cmdlet should be the last statement in a pipeline.
[Void]
Here [void] is not only a cast but modifies the emission of a data in the pipeline and avoids a side effect, so it is a behavior to be aware of. See "This type cannot be instantiated. It provides a means to discard a value explicitly using the cast operator"
Comma operator with Return
For the 'Return' instruction, the comma operator avoids enumerating the collection (cf. Write-Output -NoEnumerate), in this case we want to retrieve the type of the collection and its content and not just the content of the collection, it is therefore a behavior to be aware of.
There is also this specific case (rare) :
Because of the method signature :
Variable name with space
Switch parameter and a value