Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Rules/UseConsistentWhitespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ private IEnumerable<DiagnosticRecord> FindSeparatorViolations(TokenOperations to
{
return node.Next != null
&& node.Next.Value.Kind != TokenKind.NewLine
&& node.Next.Value.Kind != TokenKind.Comment
&& node.Next.Value.Kind != TokenKind.EndOfInput // semicolon can be followed by end of input
&& !IsPreviousTokenApartByWhitespace(node.Next);
};
Expand Down
42 changes: 42 additions & 0 deletions Tests/Rules/UseConsistentWhitespace.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,48 @@ if ($true) { Get-Item `
}
}

Context "CheckSeparator" {
BeforeAll {
$ruleConfiguration.CheckInnerBrace = $false
$ruleConfiguration.CheckOpenBrace = $false
$ruleConfiguration.CheckOpenParen = $false
$ruleConfiguration.CheckOperator = $false
$ruleConfiguration.CheckPipe = $false
$ruleConfiguration.CheckSeparator = $true
}

It "Should find a violation if there is no space after a comma" {
$def = '$Array = @(1,2)'
Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -HaveCount 1
}

It "Should not find a violation if there is a space after a comma" {
$def = '$Array = @(1, 2)'
Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -Be $null
}

It "Should not find a violation if there is a new-line after a comma" {
$def = @'
$Array = @(
1,
2
)
'@
Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -Be $null
}

It "Should not find a violation if there is a comment after the separator" {
$def = @'
$Array = @(
'foo', # Comment Line 1
'FizzBuzz' # Comment Line 2
)
'@
Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -BeNullOrEmpty
}

}


Context "CheckParameter" {
BeforeAll {
Expand Down