-
Notifications
You must be signed in to change notification settings - Fork 383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent PSCloseBrace crash if hashtable definition start on first token and there is a PSCloseBrace violation #1235
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,19 +80,31 @@ $hashtable = @{a = 1; b = 2} | |
|
||
Context "When there is a multi-line hashtable" { | ||
BeforeAll { | ||
$def = @' | ||
$hashtable = @{ | ||
a = 1 | ||
b = 2} | ||
'@ | ||
|
||
$ruleConfiguration.'NoEmptyLineBefore' = $false | ||
$ruleConfiguration.'IgnoreOneLineBlock' = $true | ||
$ruleConfiguration.'NewLineAfter' = $false | ||
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | ||
} | ||
|
||
It "Should find a violation" { | ||
$def = @' | ||
$hashtable = @{ | ||
a = 1 | ||
b = 2} | ||
'@ | ||
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | ||
$violations.Count | Should -Be 1 | ||
} | ||
|
||
It "Should not crash when hashtable is defined on first token" { | ||
$def = @' | ||
@{ | ||
key = value } | ||
'@ | ||
|
||
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings -ErrorAction Stop | ||
$violations.Count | Should -Be 1 | ||
Invoke-Formatter -ScriptDefinition $def -ErrorAction Stop | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There doesn't seem to be an assertion here. Since the formatter uses the same rule, this seems superfluous. (do you want an explicit test for the formatter?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The assertion here is that the formatter does not throw an exception. The call to |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can also be written as follows:
and it will cause the same error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and it's a very specific set of characters. This
"@{key=1}"
doesn't cause the problem but"@{``nkey=1}"
doesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I can change it to that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done now