File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -451,6 +451,7 @@ private IEnumerable<DiagnosticRecord> FindSeparatorViolations(TokenOperations to
451451 {
452452 return node . Next != null
453453 && node . Next . Value . Kind != TokenKind . NewLine
454+ && node . Next . Value . Kind != TokenKind . Comment
454455 && node . Next . Value . Kind != TokenKind . EndOfInput // semicolon can be followed by end of input
455456 && ! IsPreviousTokenApartByWhitespace ( node . Next ) ;
456457 } ;
Original file line number Diff line number Diff line change @@ -514,6 +514,48 @@ if ($true) { Get-Item `
514514 }
515515 }
516516
517+ Context " CheckSeparator" {
518+ BeforeAll {
519+ $ruleConfiguration.CheckInnerBrace = $false
520+ $ruleConfiguration.CheckOpenBrace = $false
521+ $ruleConfiguration.CheckOpenParen = $false
522+ $ruleConfiguration.CheckOperator = $false
523+ $ruleConfiguration.CheckPipe = $false
524+ $ruleConfiguration.CheckSeparator = $true
525+ }
526+
527+ It " Should find a violation if there is no space after a comma" {
528+ $def = ' $Array = @(1,2)'
529+ Invoke-ScriptAnalyzer - ScriptDefinition $def - Settings $settings | Should - HaveCount 1
530+ }
531+
532+ It " Should not find a violation if there is a space after a comma" {
533+ $def = ' $Array = @(1, 2)'
534+ Invoke-ScriptAnalyzer - ScriptDefinition $def - Settings $settings | Should - Be $null
535+ }
536+
537+ It " Should not find a violation if there is a new-line after a comma" {
538+ $def = @'
539+ $Array = @(
540+ 1,
541+ 2
542+ )
543+ '@
544+ Invoke-ScriptAnalyzer - ScriptDefinition $def - Settings $settings | Should - Be $null
545+ }
546+
547+ It " Should not find a violation if there is a comment after the separator" {
548+ $def = @'
549+ $Array = @(
550+ 'foo', # Comment Line 1
551+ 'FizzBuzz' # Comment Line 2
552+ )
553+ '@
554+ Invoke-ScriptAnalyzer - ScriptDefinition $def - Settings $settings | Should - BeNullOrEmpty
555+ }
556+
557+ }
558+
517559
518560 Context " CheckParameter" {
519561 BeforeAll {
You can’t perform that action at this time.
0 commit comments