Skip to content

Commit 088b27b

Browse files
author
Kapil Borle
authored
Merge pull request #815 from PowerShell/kapilmb/fix-formatter
Fix formatter crash
2 parents fdb0499 + 0637a36 commit 088b27b

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

.vscode/launch.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
5+
{
6+
"name": ".NET Core Launch (console)",
7+
"type": "coreclr",
8+
"request": "launch",
9+
"preLaunchTask": "build",
10+
"program": "${workspaceRoot}/bin/Debug/<target-framework>/<project-name.dll>",
11+
"args": [],
12+
"cwd": "${workspaceRoot}",
13+
"externalConsole": false,
14+
"stopAtEntry": false,
15+
"internalConsoleOptions": "openOnSessionStart"
16+
},
17+
{
18+
"name": ".NET Core Attach",
19+
"type": "coreclr",
20+
"request": "attach",
21+
"processId": "${command:pickProcess}"
22+
},
23+
{
24+
"name": ".NET Full Attach",
25+
"type": "clr",
26+
"request": "attach",
27+
"processId": "${command:pickProcess}"
28+
}
29+
]
30+
}

Engine/EditableText.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public bool IsValidRange(Range range)
126126

127127
return range.Start.Line <= Lines.Count
128128
&& range.End.Line <= Lines.Count
129-
&& range.Start.Column <= Lines[range.Start.Line - 1].Length
129+
&& range.Start.Column <= Lines[range.Start.Line - 1].Length + 1
130130
&& range.End.Column <= Lines[range.End.Line - 1].Length + 1;
131131
}
132132

Rules/UseConsistentWhitespace.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ private IEnumerable<DiagnosticRecord> FindOperatorViolations(TokenOperations tok
315315
}
316316

317317
var hasWhitespaceBefore = IsPreviousTokenOnSameLineAndApartByWhitespace(tokenNode);
318-
var hasWhitespaceAfter = IsPreviousTokenOnSameLineAndApartByWhitespace(tokenNode.Next);
318+
var hasWhitespaceAfter = tokenNode.Next.Value.Kind == TokenKind.NewLine
319+
|| IsPreviousTokenOnSameLineAndApartByWhitespace(tokenNode.Next);
319320

320321
if (!hasWhitespaceAfter || !hasWhitespaceBefore)
321322
{

Tests/Rules/UseConsistentWhitespace.tests.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,15 @@ $x = 1
173173
'@
174174
Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should Be $null
175175
}
176+
177+
It "Should not find violation if a binary operator is followed by new line" {
178+
$def = @'
179+
$x = $true -and
180+
$false
181+
'@
182+
Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should Be $null
183+
}
184+
176185
}
177186

178187
Context "When a comma is not followed by a space" {

0 commit comments

Comments
 (0)