EliziumNet/Loopz

Param Set Tool: find-InAllParameterSetsByAccident

Closed this issue ยท 1 comments

----> Parameter Set Violations Report [test-ParamInAllParameterSetsByAccident] ... 
 
      In All Parameter Sets By Accident 
      ================================= 
 
      Defining a parameter with multiple 'Parameter Blocks', some with  
      and some without a parameter set, is invalid.  
 
 
  *** Parameter 'ClaimB' (of 'Alpha'), accidentally in all Parameter Sets:  
   ๐ŸŸข Other Parameter Sets: '' 
 
  *** Parameter 'ClaimE' (of 'Alpha'), accidentally in all Parameter Sets:  
   ๐ŸŸข Other Parameter Sets: 'Beta' 
 
 
========================================================================================================================= 
>>>>> SUMMARY:  Found the following 2 violations: 
   ๐Ÿ”ถ 'In All Parameter Sets By Accident', Count: 2 
      ๐ŸŸจ Reasons:  
         ๐Ÿ’  {'ClaimB' of Alpha => } 
         ๐Ÿ’  {'ClaimE' of Alpha => Beta} 
========================================================================================================================= 

The 'Other Parameter Sets' statement can sometime show an empty parameter set name. This is clearly not correct.

The display for this rules violation needs to be checked. Currently the stragtegy is to take each parameter set, and for each one of its parameters check to see if it in multiple parameter sets and if so, is one of them the '__AllParameterSets'. If it is then the rule is violated. However, the logic behind the so called 'other' parameter sets is not clear and should probably be replaced.

All we need to show is the violating parameter set and the parameter that is causing the violation. So in this example, we have 2 violations: 'ClaimB' and 'ClaimE', so all we need to show is:

  *** Parameter 'ClaimB', accidentally in all Parameter Sets:  
   ๐ŸŸข Parameter Set: 'Alpha'   
 
  *** Parameter 'ClaimE', accidentally in all Parameter Sets:  
   ๐ŸŸข Parameter Set:  'Beta' 

and

>>>>> SUMMARY:  Found the following 2 violations: 
   ๐Ÿ”ถ 'In All Parameter Sets By Accident', Count: 2 
      ๐ŸŸจ Reasons:  
         ๐Ÿ’  { parameter 'ClaimB' of parameter set 'Alpha'} 
         ๐Ÿ’  { parameter 'ClaimE' of paraeter set 'Beta'} 

(Note: the example was copied from another test case, so the variable names dont make sense; make sure the rename the parameters so they make sense for this test)

add this test to rules.tests.ps1:

  Describe 'MustNotBeInAllParameterSetsByAccident' {
    BeforeAll {
      InModuleScope Elizium.Loopz {
        function script:test-ParamInAllParameterSetsByAccident {
          param(
            [Parameter(ValueFromPipeline = $true)]
            [object]$Chaff,

            [Parameter(ParameterSetName = 'Alpha', Mandatory, Position = 1)]
            [object]$paramA,

            [Parameter()]
            [Parameter(ParameterSetName = 'Alpha', Position = 2)]
            [object]$paramB,

            [Parameter(ParameterSetName = 'Alpha', Position = 3)]
            [object]$paramC,

            [Parameter(ParameterSetName = 'Beta', Position = 1)]
            [object]$paramD,

            [Parameter()]
            [Parameter(ParameterSetName = 'Beta', Position = 2)]
            [object]$paramE
          )
        }
      }
    }

    Context 'given: functions with violations' {
      It 'should: report violations' -Tag 'Current' {
        InModuleScope Elizium.Loopz {
          [string]$commandName = 'test-ParamInAllParameterSetsByAccident';
          [CommandInfo]$commandInfo = Get-Command $commandName;
          [RuleController]$controller = [RuleController]::new($commandInfo);
          [syntax]$syntax = New-Syntax -CommandName $commandName -Signals $_signals -Scribbler $_scribbler;
          $controller.Test($syntax).Result | Should -Be $false;

          $commandInfo | Show-ParameterSetReport;
        }
      }
    } # given: functions with violations
  }