Skip to main content
powershell/PSAlignAssignmentStatement is a PSScriptAnalyzer diagnostic emitted by tally for PowerShell snippets embedded in Dockerfiles.

Description

Consecutive assignment statements are more readable when they’re aligned. Assignments are considered aligned when their equals signs line up vertically. This rule looks at the key-value pairs in hashtables (including DSC configurations) as well as enum definitions. Consider the following example with a hashtable and enum that isn’t aligned.
Alignment in this case would look like the following.
The rule ignores any assignments within hashtables and enums which are on the same line as others. For example, the rule ignores $h = @{a = 1; b = 2}.

Configuration

Parameters

Enable: bool (Default value is $false)

Enable or disable the rule during ScriptAnalyzer invocation.

CheckHashtable: bool (Default value is $true)

Enforce alignment of assignment statements in a hashtable and in a DSC Configuration. There is only one setting for hashtable and DSC configuration because the property value pairs in a DSC configuration are parsed as key-value pairs of a hashtable.

AlignHashtableKvpWithInterveningComment: bool (Default value is $true)

Include key-value pairs in the alignment that have an intervening comment - that is to say a comment between the key name and the equals sign. Consider the following:
With this setting disabled, the line with the comment is ignored, and it would be aligned like so:
With it enabled, the comment line is included in alignment:

CheckEnum: bool (Default value is $true)

Enforce alignment of assignment statements of an Enum definition.

AlignEnumMemberWithInterveningComment: bool (Default value is $true)

Include enum members in the alignment that have an intervening comment - that is to say a comment between the member name and the equals sign. Consider the following:
With this setting disabled, the line with the comment is ignored, and it would be aligned like so:
With it enabled, the comment line is included in alignment:

IncludeValuelessEnumMembers: bool (Default value is $true)

Include enum members in the alignment that don’t have an explicitly assigned value. Enum’s don’t need to be given a value when they’re defined. Consider the following:
With this setting disabled, the third line, which has no value, isn’t considered when choosing where to align assignments. It would be aligned like so:
With it enabled, the valueless member is included in alignment as if it had a value:

Source

This rule documentation is adapted from Microsoft’s PSScriptAnalyzer documentation for AlignAssignmentStatement, licensed under CC BY 4.0.