diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..9beb418df --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,30 @@ +{ + "version": "0.2.0", + "configurations": [ + + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceRoot}/bin/Debug//", + "args": [], + "cwd": "${workspaceRoot}", + "externalConsole": false, + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + }, + { + "name": ".NET Full Attach", + "type": "clr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} diff --git a/Engine/EditableText.cs b/Engine/EditableText.cs index 93f78d66a..5d77862d2 100644 --- a/Engine/EditableText.cs +++ b/Engine/EditableText.cs @@ -126,7 +126,7 @@ public bool IsValidRange(Range range) return range.Start.Line <= Lines.Count && range.End.Line <= Lines.Count - && range.Start.Column <= Lines[range.Start.Line - 1].Length + && range.Start.Column <= Lines[range.Start.Line - 1].Length + 1 && range.End.Column <= Lines[range.End.Line - 1].Length + 1; } diff --git a/Rules/UseConsistentWhitespace.cs b/Rules/UseConsistentWhitespace.cs index 9975036fb..f7d8d2024 100644 --- a/Rules/UseConsistentWhitespace.cs +++ b/Rules/UseConsistentWhitespace.cs @@ -315,7 +315,8 @@ private IEnumerable FindOperatorViolations(TokenOperations tok } var hasWhitespaceBefore = IsPreviousTokenOnSameLineAndApartByWhitespace(tokenNode); - var hasWhitespaceAfter = IsPreviousTokenOnSameLineAndApartByWhitespace(tokenNode.Next); + var hasWhitespaceAfter = tokenNode.Next.Value.Kind == TokenKind.NewLine + || IsPreviousTokenOnSameLineAndApartByWhitespace(tokenNode.Next); if (!hasWhitespaceAfter || !hasWhitespaceBefore) { diff --git a/Tests/Rules/UseConsistentWhitespace.tests.ps1 b/Tests/Rules/UseConsistentWhitespace.tests.ps1 index 7be2675d7..b80a0f947 100644 --- a/Tests/Rules/UseConsistentWhitespace.tests.ps1 +++ b/Tests/Rules/UseConsistentWhitespace.tests.ps1 @@ -173,6 +173,15 @@ $x = 1 '@ Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should Be $null } + + It "Should not find violation if a binary operator is followed by new line" { + $def = @' +$x = $true -and + $false +'@ + Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should Be $null + } + } Context "When a comma is not followed by a space" {