PowerShell / PowerShell/PSScriptAnalyzer

variable assignments are not aligned

Open
#2,127 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
2.2k
Forks
414
Avg merge
13h 1m
Merged PRs (30d)
2

Description

After executing the following code, the = in variable assignments are not aligned, and the = in the first hashtable are also not aligned. I tested this in PowerShell 5.1 on Windows 10.

cls
$s = @'
$hashtable = @{ property1    ="value"
    anotherProperty= "another value"
}
$hashtable = @{
    property1 = "value"
    anotherProperty = "another value"
}
$hashtable = @{
    property1              = "value"
    anotherProperty = "another value"
}
$a= "hello"
   $ccc = "world"
 $b="Hi"
function foo {
"hello"
}
'@
$settings = @{
    IncludeRules = @("PSPlaceOpenBrace", "PSUseConsistentIndentation", "PSUseConsistentWhitespace","PSAlignAssignmentStatement")
    Rules = @{
        PSPlaceOpenBrace = @{
            Enable = $true
            OnSameLine = $false
        }
        PSUseConsistentIndentation = @{
        Enable = $true
			Kind = 'tab' # space,tab
			IndentationSize = 1
			PipelineIndentation = 'NoIndentation'
        }
        PSAlignAssignmentStatement = @{
            Enable = $true
            CheckHashtable = $true
        }
    }
}
Invoke-Formatter -ScriptDefinition $s -Settings $settings

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the provided PowerShell 5.1 reproduction with PSAlignAssignmentStatement enabled, including CheckHashtable. Read the formatter behavior for that rule and compare the alignment of the assignments and hashtable entries; done means the demonstrated variable assignments and hashtable equals signs are aligned consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.