Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

PSScriptAnalyzer disapproves the construction of any case sensitive hash table #1385

Copy link
Copy link
@iRon7

Description

@iRon7
Issue body actions

The UseLiteralInitializerForHashtable should prevent programmers to inconsiderately build hash tables with a default comparison other then the default case sensitive PowerShell behavior. It should not prevent a programmer from building a case sensitive hash table at all.
Hash tables are often used to handle program data but they might also be used to store custom input data (whether or not case sensitive) and the desired output might highly depend on the customer's used-case.

In other words, it is good that I get a warning on

$hashtable = [hashtable]::new()

and:

$hashtable = New-Object -TypeName hashtable

But if I well-considerate explicitly set the comparison mode, like:

$hashtable = [HashTable]::New(0, [StringComparer]::Ordinal)

I expect the warning to be suppressed.

see also: How to create a case sensitive Hashtable without generating a PSScriptAnalyzer warning?

Steps to reproduce

Invoke-ScriptAnalyzer -ScriptDefinition '[HashTable]::New(0, [StringComparer]::Ordinal)'

Expected behavior

No warnings

Actual behavior

Use literal initializer, @{{}}, for creating a hashtable as  they are case-insensitive by default

Environment data

PSScriptAnalyzer version: 1.18.3
Tested both Windows PowerShell (5.1) and PowerShell Core (6.2.3)

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.