Skip to content

Commit d40aad1

Browse files
author
Kapil Borle
committed
Disable NoNewLineAfter property in PlaceCloseBrace rule
1 parent 58305c3 commit d40aad1

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

Rules/PlaceCloseBrace.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
2929
public class PlaceCloseBrace : ConfigurableScriptRule
3030
{
3131
[ConfigurableRuleProperty()]
32-
public bool Enable {get; protected set;} = false;
32+
public bool Enable { get; protected set; } = false;
33+
34+
[ConfigurableRuleProperty()]
35+
public bool NoEmptyLineBefore { get; protected set; } = false;
3336

3437
/// <summary>
3538
/// Analyzes the given ast to find the [violation]
@@ -80,9 +83,13 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
8083
AddToDiagnosticRecords(
8184
GetViolationForBraceOnSameLine(tokens, k, openBracePos, fileName),
8285
ref diagnosticRecords);
83-
AddToDiagnosticRecords(
84-
GetViolationForEmptyLineBeforeBrace(tokens, k, openBracePos, fileName),
85-
ref diagnosticRecords);
86+
87+
if (NoEmptyLineBefore)
88+
{
89+
AddToDiagnosticRecords(
90+
GetViolationForEmptyLineBeforeBrace(tokens, k, openBracePos, fileName),
91+
ref diagnosticRecords);
92+
}
8693
}
8794
else
8895
{

Tests/Rules/PlaceCloseBrace.tests.ps1

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
Import-Module PSScriptAnalyzer
22
$ruleName = "PSPlaceCloseBrace"
3+
$settings = @{
4+
IncludeRules = @("PSPlaceCloseBrace")
5+
Rules = @{
6+
PSPlaceCloseBrace = @{
7+
Enable = $true
8+
NoEmptyLineBefore = $true
9+
}
10+
}
11+
}
12+
313

414
Describe "PlaceCloseBrace" {
515
Context "When a close brace is not on a new line" {
@@ -8,7 +18,7 @@ Describe "PlaceCloseBrace" {
818
function foo {
919
Write-Output "close brace not on a new line"}
1020
'@
11-
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -IncludeRule $ruleName
21+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
1222
}
1323

1424
It "Should find a violation" {
@@ -28,7 +38,7 @@ function foo {
2838
2939
}
3040
'@
31-
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -IncludeRule $ruleName
41+
$violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings
3242
}
3343

3444
It "Should find a violation" {

0 commit comments

Comments
 (0)