FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

PSUseConsistentWhitespace: Ignore whitespace between separator and comment by liamjpeters · Pull Request #2065 · PowerShell/PSScriptAnalyzer · GitHub

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

Filter by extension

Filter by extension .cs  (1) .ps1  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 1 addition & 0 deletions Rules/UseConsistentWhitespace.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL