Skip to content

PSUseCorrectCasing malfunctioning in DSC configuration #1474

Open

Description

@xtqqczze

PSUseCorrectCasing is erroneously changing Type to type in a DSC configuration.

Steps to reproduce

$settings = @{
    IncludeRules = @("PSUseCorrectCasing")
    Rules = @{
        PSUseCorrectCasing = @{
            Enable = $true
        }
    }
}

Invoke-Formatter -Settings $settings -ScriptDefinition @'
Configuration ApacheServer{
    Node localhost{
         nxFile vHostDirectory{
             DestinationPath = $VhostDir
             Type = "Directory"
             Ensure = "Present"
             Owner = "root"
             Mode = "744"
         }
     }
 }
'@

Expected behavior

Configuration ApacheServer{
    Node localhost{
         nxFile vHostDirectory{
             DestinationPath = $VhostDir
             Type = "Directory"
             Ensure = "Present"
             Owner = "root"
             Mode = "744"
         }
     }
 }

Actual behavior

Configuration ApacheServer{
    Node localhost{
         nxFile vHostDirectory{
             DestinationPath = $VhostDir
             type = "Directory"
             Ensure = "Present"
             Owner = "root"
             Mode = "744"
         }
     }
 }

Environment data

> $PSVersionTable
PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.19.0
1.18.3

Activity

  1. bergmeister commented on May 5, 2020

    @bergmeister
    Collaborator

    xtqqczze Thanks for the report. I can repro with both PSSA 1.18.3 and 1.19.0. Somehow PSSA only touches the Type property.

  2. bergmeister commented on May 5, 2020

    @bergmeister
    Collaborator

    I will need to debug this in more detail but I suspect an erroneous CommandInfo cache entry

  3. bergmeister commented on May 7, 2020

    @bergmeister
    Collaborator

    What is happening is that this is because Type is a CommandAst and since the command info cache also contains aliases, it thinks this is the type alias (a default alias for Get-Content).
    This behaviour is not new (since command name correction already existed in 1.18.3) and also happens in 1.18.3.
    Theoretically one could exclude aliases from being corrected in this rule but I am not sure that would be the best just for this special case.
    Therefore I am not sure how to proceed on this one.

  4. rjmholt commented on May 12, 2020

    @rjmholt
    Contributor

    If the rule uses a visitor, it could skip children when it sees a dynamickeywordstatementast or a configurationstatementast perhaps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions