Enable suppression of PSAvoidAssignmentToAutomaticVariable for specific variable or parameter by fflaten · Pull Request #1896 · PowerShell/PSScriptAnalyzer

@fflaten

PR Summary

Enables suppression for specific variable/parameter with rule PSAvoidAssignmentToAutomaticVariable.
Fix #1589

PR Checklist

@fflaten

bergmeister

Choose a reason for hiding this comment

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

Awesome, thanks for improving it, change looks good to me, can you please add one test case for it though?
If possible a test case for each line that was changed, that can return a diagnostic record, but I can understand if that is too much for you, therefore consider this optional.

@fflaten

Intentionally skipped it because suppression was only tested in a general test and not per rule.

Can try to add some later today if you want.

@fflaten

fflaten

$testCases_ReadOnlyAutomaticVariables = $testCases_AutomaticVariables | Where-Object { $_.IsReadonly }

It "Variable <VariableName> produces warning of Severity <ExpectedSeverity>" -TestCases $testCases_AutomaticVariables {
param ($VariableName, $ExpectedSeverity)

Choose a reason for hiding this comment

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

Tip: Param-blocks are no longer needed in Pester v5. Some keep them to make the testcase-contract visible so didn't remove them :)

fflaten


Describe "AvoidAssignmentToAutomaticVariables" {
Context "ReadOnly Variables" {
BeforeDiscovery {

Choose a reason for hiding this comment

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

Added per best practice in Pester v5. Only cosmetic and more explicit in this case.

@fflaten

In case it didn't show up - ready for review again 🙂

JamesWTruher

Choose a reason for hiding this comment

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

bergmeister

@fflaten fflaten deleted the autovariable-ruleid branch

September 17, 2023 18:40

This was referenced

Mar 16, 2024