Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitd831fba

Browse files
liamjpetersandyleejordan
authored andcommitted
Rules>PSAlignAssignmentStatement: Treat single kvp hashtables as being on a single line, and not checked for violations.
1 parentaa7a582 commitd831fba

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

‎Rules/AlignAssignmentStatement.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ private static List<Tuple<IScriptExtent, IScriptExtent>> GetExtents(
314314

315315
privateboolHasPropertiesOnSeparateLines(IEnumerable<Tuple<IScriptExtent,IScriptExtent>>tuples)
316316
{
317+
if(tuples.Count()==1)
318+
{
319+
// If the hashtable has just a single key-value pair, it does not have properties on separate lines
320+
returnfalse;
321+
}
317322
varlines=newHashSet<int>();
318323
foreach(varkvpintuples)
319324
{

‎Tests/Rules/AlignAssignmentStatement.tests.ps1‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,33 @@ $x = @{ }
7575
Invoke-ScriptAnalyzer-ScriptDefinition$def-Settings$settings|Get-Count| Should-Be0
7676

7777
}
78+
79+
It"Should ignore if a hashtable has a single key-value pair on a single line" {
80+
$def=@'
81+
$x = @{ 'key'="value" }
82+
'@
83+
Invoke-ScriptAnalyzer-ScriptDefinition$def-Settings$settings|Get-Count| Should-Be0
84+
85+
}
86+
87+
It"Should ignore if a hashtable has a single key-value pair across multiple lines" {
88+
$def=@'
89+
$x = @{
90+
'key'="value"
91+
}
92+
'@
93+
Invoke-ScriptAnalyzer-ScriptDefinition$def-Settings$settings|Get-Count| Should-Be0
94+
95+
}
96+
97+
It"Should ignore if a hashtable has multiple key-value pairs on a single line" {
98+
$def=@'
99+
$x = @{ 'key'="value"; 'key2'="value2"; 'key3WithLongerName'="value3" }
100+
'@
101+
Invoke-ScriptAnalyzer-ScriptDefinition$def-Settings$settings|Get-Count| Should-Be0
102+
103+
}
104+
78105
}
79106

80107
Context"When assignment statements are in DSC Configuration" {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp