Skip to content

Problem with formatting Hash #1219

Closed
@PrzemyslawKlys

Description

@PrzemyslawKlys

Steps to reproduce

I hvae simple .psd1 like this.

#
# Module manifest for module 'PSPublishModule'
#
# Generated by: Przemyslaw Klys
#
# Generated on: 17.04.2019
#

@{

    # Script module or binary module file associated with this manifest.
    RootModule           = 'PSPublishModule.psm1'

    # Version number of this module.
    ModuleVersion        = '0.7.1'

    # Supported PSEditions
    CompatiblePSEditions = 'Desktop', 'Core'

    # ID used to uniquely identify this module
    GUID                 = 'eb76426a-1992-40a5-82cd-6480f883ef4d'

    # Author of this module
    Author               = 'Przemyslaw Klys'

    # Company or vendor of this module
    CompanyName          = 'Evotec'

    # Copyright statement for this module
    Copyright            = '(c) 2011 - 2019 Przemyslaw Klys. All rights reserved.'

    # Description of the functionality provided by this module
    Description          = 'Simple project allowing preparing, managing and publishing modules to PowerShellGallery'

    # Minimum version of the Windows PowerShell engine required by this module
    PowerShellVersion    = '5.1'

    # Name of the Windows PowerShell host required by this module
    # PowerShellHostName = ''

    # Minimum version of the Windows PowerShell host required by this module
    # PowerShellHostVersion = ''

    # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
    # DotNetFrameworkVersion = ''

    # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
    # CLRVersion = ''

    # Processor architecture (None, X86, Amd64) required by this module
    # ProcessorArchitecture = ''

    # Modules that must be imported into the global environment prior to importing this module
    # RequiredModules = @()

    # Assemblies that must be loaded prior to importing this module
    # RequiredAssemblies = @()

    # Script files (.ps1) that are run in the caller's environment prior to importing this module.
    # ScriptsToProcess = @()

    # Type files (.ps1xml) to be loaded when importing this module
    # TypesToProcess = @()

    # Format files (.ps1xml) to be loaded when importing this module
    # FormatsToProcess = @()

    # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
    # NestedModules = @()

    # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
    FunctionsToExport    = 'New-PrepareModule', 'Remove-Comments'

    # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
    CmdletsToExport      = @()

    # Variables to export from this module
    # VariablesToExport = @()

    # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
    AliasesToExport      = @()

    # DSC resources to export from this module
    # DscResourcesToExport = @()

    # List of all modules packaged with this module
    # ModuleList = @()

    # List of all files packaged with this module
    # FileList = @()

    # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
    PrivateData          = @{

        PSData = @{

            # Tags applied to this module. These help with module discovery in online galleries.
            Tags       = 'Windows', 'MacOS', 'Linux', 'Build', 'Module'

            # A URL to the license for this module.
            # LicenseUri = ''

            # A URL to the main website for this project.
            ProjectUri = 'https://github.com/EvotecIT/PSPublishModule'

            # A URL to an icon representing this module.
            IconUri    = 'https://evotec.xyz/wp-content/uploads/2019/02/PSPublishModule.png'

            # ReleaseNotes of this module
            # ReleaseNotes = ''

        } # End of PSData hashtable

    } # End of PrivateData hashtable

    # HelpInfo URI of this module
    # HelpInfoURI = ''

    # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
    # DefaultCommandPrefix = ''

}

I've run a command that strips white chars and comments and this gives me this:

@{RootModule = 'PSPublishModule.psm1'
    ModuleVersion = '0.7.1'
    CompatiblePSEditions = 'Desktop', 'Core'
    GUID = 'eb76426a-1992-40a5-82cd-6480f883ef4d'
    Author = 'Przemyslaw Klys'
    CompanyName = 'Evotec'
    Copyright = '(c) 2011 - 2019 Przemyslaw Klys. All rights reserved.'
    Description = 'Simple project allowing preparing, managing and publishing modules to PowerShellGallery'
    PowerShellVersion = '5.1'
    ScriptsToProcess = @()
    FunctionsToExport = 'New-PrepareModule', 'Remove-Comments'
    CmdletsToExport = @()
    AliasesToExport = @()
    PrivateData = @{PSData = @{Tags = 'Windows', 'MacOS', 'Linux', 'Build', 'Module'
            ProjectUri = 'https://github.com/EvotecIT/PSPublishModule'
            IconUri = 'https://evotec.xyz/wp-content/uploads/2019/02/PSPublishModule.png'}}}

image

And during runtime of formater:

image

image

If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.17763.316
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.316
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

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

1.17.1
1.18.0
writeErrorStream      : True
PSMessageDetails      : 
Exception             : System.IndexOutOfRangeException: Index was outside the bounds of the array.
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.PlaceCloseBrace.GetIndentation(Token[] tokens, Int32 closeBracePos, Int32 openBracePos)
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.PlaceCloseBrace.GetCorrectionsForBraceShouldBeOnNewLine(Token[] tokens, Int32 closeBracePos, Int32 openBracePos, 
                        String fileName)
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.PlaceCloseBrace.GetViolationForBraceShouldBeOnNewLine(Token[] tokens, Int32 closeBracePos, Int32 openBracePos, St
                        ring fileName)
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.PlaceCloseBrace.AnalyzeScript(Ast ast, String fileName)
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer.<>c__DisplayClass82_1.<AnalyzeSyntaxTree>b__2()
TargetObject          : 
CategoryInfo          : InvalidOperation: (:) [Invoke-Formatter], IndexOutOfRangeException
FullyQualifiedErrorId : RULE_ERROR,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeFormatterCommand
ErrorDetails          : 
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at Format-Code, C:\Users\przemyslaw.klys\OneDrive - Evotec\Support\GitHub\PSPublishModule\Private\Format-PSM1.ps1: line 17
                        at Merge-Module, C:\Users\przemyslaw.klys\OneDrive - Evotec\Support\GitHub\PSPublishModule\Private\Merge-Module.ps1: line 80
                        at New-PrepareModule<Process>, C:\Users\przemyslaw.klys\OneDrive - Evotec\Support\GitHub\PSPublishModule\Public\New-PrepareModule.ps1: line 221
                        at <ScriptBlock>, C:\Users\przemyslaw.klys\OneDrive - Evotec\Support\GitHub\PSPublishModule\Publish\Manage-Module.ps1: line 143
PipelineIterationInfo : {0, 1}

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