microsoft / DSCParser

Allows the conversion of DSC scripts into PSObject for analysis purposes
MIT License
29 stars 19 forks source link

Improve logic for variables (bool, null and others) and fixes inconsistency #22

Closed PrzemyslawKlys closed 2 years ago

PrzemyslawKlys commented 2 years ago

Currently logic for variables has problems. On top-level objects, you treat variables as strings with $ character to make sure when a user checks the object they are aware it's a variable, not just getting $null. This works great for variables such as "$MyVar", "$Credentials" and so on. But then for nested objects, you no longer treat variables as variables. In the case of $True/$False you don't leave them as a string with "$True" but you explicitly convert them to bool. For Arrays, you leave them as strings again.

image

image

image

This means you have inconsistency and you treat them differently. This PR improves this logic:

  1. If it's $true or $false it explicitly uses bool
  2. If it's not $true or $false it uses your existing logic and makes them a string with $ character

It keeps it consistent across Root Object, CimInstance and Arrays.

  1. I have also applied the same logic as $true/$false to $null. For me it makes sense, but feel free to decide on that.
  2. Fixes NoisyTypes for faster code parsing (although not much difference). Was unused variables before. NewLIne is important so I left it as is.
  3. Fixes NoisyOperators - was working fine, but PSScriptAnalyzer complained as unused variable. I've explicitly defined it in functions and passed as parameter. Alternative was $Script:$NoisyOperators but thought the second one was a bit weird as it appeared from thin air