From 993e119b3cc15ce6599d5e9fd4eaef9ab1d05c02 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Mon, 10 Feb 2020 09:24:19 +0000 Subject: [PATCH 1/6] Split CheckPipe feature of trimming redundant whitespace out into option CheckPipeForRedundantWhiteSpace --- Engine/Settings/CodeFormatting.psd1 | 17 +++--- Engine/Settings/CodeFormattingAllman.psd1 | 17 +++--- Engine/Settings/CodeFormattingOTBS.psd1 | 17 +++--- Engine/Settings/CodeFormattingStroustrup.psd1 | 19 ++++--- RuleDocumentation/UseConsistentWhitespace.md | 17 +++--- Rules/UseConsistentWhitespace.cs | 54 +++++++++++------- Tests/Rules/UseConsistentWhitespace.tests.ps1 | 56 +++++++++++++++++-- 7 files changed, 131 insertions(+), 66 deletions(-) diff --git a/Engine/Settings/CodeFormatting.psd1 b/Engine/Settings/CodeFormatting.psd1 index 24b4d52e3..2520d1af7 100644 --- a/Engine/Settings/CodeFormatting.psd1 +++ b/Engine/Settings/CodeFormatting.psd1 @@ -31,14 +31,15 @@ } PSUseConsistentWhitespace = @{ - Enable = $true - CheckInnerBrace = $true - CheckOpenBrace = $true - CheckOpenParen = $true - CheckOperator = $true - CheckPipe = $true - CheckSeparator = $true - CheckParameter = $false + Enable = $true + CheckInnerBrace = $true + CheckOpenBrace = $true + CheckOpenParen = $true + CheckOperator = $true + CheckPipe = $true + CheckPipeForRedundantWhiteSpace = $false + CheckSeparator = $true + CheckParameter = $false } PSAlignAssignmentStatement = @{ diff --git a/Engine/Settings/CodeFormattingAllman.psd1 b/Engine/Settings/CodeFormattingAllman.psd1 index bb398e8f9..2d4bae7f4 100644 --- a/Engine/Settings/CodeFormattingAllman.psd1 +++ b/Engine/Settings/CodeFormattingAllman.psd1 @@ -31,14 +31,15 @@ } PSUseConsistentWhitespace = @{ - Enable = $true - CheckInnerBrace = $true - CheckOpenBrace = $true - CheckOpenParen = $true - CheckOperator = $true - CheckPipe = $true - CheckSeparator = $true - CheckParameter = $false + Enable = $true + CheckInnerBrace = $true + CheckOpenBrace = $true + CheckOpenParen = $true + CheckOperator = $true + CheckPipe = $true + CheckPipeForRedundantWhiteSpace = $false + CheckSeparator = $true + CheckParameter = $false } PSAlignAssignmentStatement = @{ diff --git a/Engine/Settings/CodeFormattingOTBS.psd1 b/Engine/Settings/CodeFormattingOTBS.psd1 index c75ba18bd..0d7eb9780 100644 --- a/Engine/Settings/CodeFormattingOTBS.psd1 +++ b/Engine/Settings/CodeFormattingOTBS.psd1 @@ -31,14 +31,15 @@ } PSUseConsistentWhitespace = @{ - Enable = $true - CheckInnerBrace = $true - CheckOpenBrace = $true - CheckOpenParen = $true - CheckOperator = $true - CheckPipe = $true - CheckSeparator = $true - CheckParameter = $false + Enable = $true + CheckInnerBrace = $true + CheckOpenBrace = $true + CheckOpenParen = $true + CheckOperator = $true + CheckPipe = $true + CheckPipeForRedundantWhiteSpace = $false + CheckSeparator = $true + CheckParameter = $false } PSAlignAssignmentStatement = @{ diff --git a/Engine/Settings/CodeFormattingStroustrup.psd1 b/Engine/Settings/CodeFormattingStroustrup.psd1 index 1d13df6c5..12bd4445d 100644 --- a/Engine/Settings/CodeFormattingStroustrup.psd1 +++ b/Engine/Settings/CodeFormattingStroustrup.psd1 @@ -31,15 +31,16 @@ IndentationSize = 4 } - PSUseConsistentWhitespace = @{ - Enable = $true - CheckInnerBrace = $true - CheckOpenBrace = $true - CheckOpenParen = $true - CheckOperator = $true - CheckPipe = $true - CheckSeparator = $true - CheckParameter = $false + PSUseConsistentWhitespace = @{ + Enable = $true + CheckInnerBrace = $true + CheckOpenBrace = $true + CheckOpenParen = $true + CheckOperator = $true + CheckPipe = $true + CheckPipeForRedundantWhiteSpace = $false + CheckSeparator = $true + CheckParameter = $false } PSAlignAssignmentStatement = @{ diff --git a/RuleDocumentation/UseConsistentWhitespace.md b/RuleDocumentation/UseConsistentWhitespace.md index f24267a85..a40c04c8d 100644 --- a/RuleDocumentation/UseConsistentWhitespace.md +++ b/RuleDocumentation/UseConsistentWhitespace.md @@ -13,14 +13,15 @@ ```powershell Rules = @{ PSUseConsistentWhitespace = @{ - Enable = $true - CheckInnerBrace = $true - CheckOpenBrace = $true - CheckOpenParen = $true - CheckOperator = $true - CheckPipe = $true - CheckSeparator = $true - CheckParameter = $false + Enable = $true + CheckInnerBrace = $true + CheckOpenBrace = $true + CheckOpenParen = $true + CheckOperator = $true + CheckPipe = $true + CheckPipeForRedundantWhiteSpace = $false + CheckSeparator = $true + CheckParameter = $false } } ``` diff --git a/Rules/UseConsistentWhitespace.cs b/Rules/UseConsistentWhitespace.cs index 75b14fca3..eddd6ee92 100644 --- a/Rules/UseConsistentWhitespace.cs +++ b/Rules/UseConsistentWhitespace.cs @@ -48,6 +48,9 @@ private List>> violationFind [ConfigurableRuleProperty(defaultValue: true)] public bool CheckPipe { get; protected set; } + [ConfigurableRuleProperty(defaultValue: false)] + public bool CheckPipeForRedundantWhiteSpace { get; protected set; } + [ConfigurableRuleProperty(defaultValue: true)] public bool CheckOpenParen { get; protected set; } @@ -73,7 +76,7 @@ public override void ConfigureRule(IDictionary paramValueMap) violationFinders.Add(FindInnerBraceViolations); } - if (CheckPipe) + if (CheckPipe || CheckPipeForRedundantWhiteSpace) { violationFinders.Add(FindPipeViolations); } @@ -260,7 +263,7 @@ private IEnumerable FindInnerBraceViolations(TokenOperations t continue; } - if (!IsNextTokenApartByWhitespace(lCurly)) + if (!IsNextTokenApartByWhitespace(lCurly, out bool redundantWhitespace)) { yield return new DiagnosticRecord( GetError(ErrorKind.AfterOpeningBrace), @@ -314,16 +317,19 @@ private IEnumerable FindPipeViolations(TokenOperations tokenOp continue; } - if (!IsNextTokenApartByWhitespace(pipe)) + if (!IsNextTokenApartByWhitespace(pipe, out bool redundantWhitespace)) { - yield return new DiagnosticRecord( - GetError(ErrorKind.AfterPipe), - pipe.Value.Extent, - GetName(), - GetDiagnosticSeverity(), - tokenOperations.Ast.Extent.File, - null, - GetCorrections(pipe.Previous.Value, pipe.Value, pipe.Next.Value, true, false).ToList()); + if (CheckPipeForRedundantWhiteSpace && redundantWhitespace || CheckPipe && !redundantWhitespace) + { + yield return new DiagnosticRecord( + GetError(ErrorKind.AfterPipe), + pipe.Value.Extent, + GetName(), + GetDiagnosticSeverity(), + tokenOperations.Ast.Extent.File, + null, + GetCorrections(pipe.Previous.Value, pipe.Value, pipe.Next.Value, true, false).ToList()); + } } } @@ -339,9 +345,11 @@ private IEnumerable FindPipeViolations(TokenOperations tokenOp continue; } - if (!IsPreviousTokenApartByWhitespace(pipe)) + if (!IsPreviousTokenApartByWhitespace(pipe, out bool redundantWhitespace)) { - yield return new DiagnosticRecord( + if (CheckPipeForRedundantWhiteSpace && redundantWhitespace || CheckPipe && !redundantWhitespace) + { + yield return new DiagnosticRecord( GetError(ErrorKind.BeforePipe), pipe.Value.Extent, GetName(), @@ -349,6 +357,7 @@ private IEnumerable FindPipeViolations(TokenOperations tokenOp tokenOperations.Ast.Extent.File, null, GetCorrections(pipe.Previous.Value, pipe.Value, pipe.Next.Value, false, true).ToList()); + } } } } @@ -467,16 +476,23 @@ private bool IsKeyword(Token token) return openParenKeywordWhitelist.Contains(token.Kind); } - private bool IsPreviousTokenApartByWhitespace(LinkedListNode tokenNode) + private static bool IsPreviousTokenApartByWhitespace(LinkedListNode tokenNode) + { + return IsPreviousTokenApartByWhitespace(tokenNode, out _); + } + + private static bool IsPreviousTokenApartByWhitespace(LinkedListNode tokenNode, out bool hasRedundantWhitespace) { - return whiteSpaceSize == - (tokenNode.Value.Extent.StartColumnNumber - tokenNode.Previous.Value.Extent.EndColumnNumber); + var actualWhitespaceSize = tokenNode.Value.Extent.StartColumnNumber - tokenNode.Previous.Value.Extent.EndColumnNumber; + hasRedundantWhitespace = actualWhitespaceSize - whiteSpaceSize > 0; + return whiteSpaceSize == actualWhitespaceSize; } - private bool IsNextTokenApartByWhitespace(LinkedListNode tokenNode) + private static bool IsNextTokenApartByWhitespace(LinkedListNode tokenNode, out bool hasRedundantWhitespace) { - return whiteSpaceSize == - (tokenNode.Next.Value.Extent.StartColumnNumber - tokenNode.Value.Extent.EndColumnNumber); + var actualWhitespaceSize = tokenNode.Next.Value.Extent.StartColumnNumber - tokenNode.Value.Extent.EndColumnNumber; + hasRedundantWhitespace = actualWhitespaceSize - whiteSpaceSize > 0; + return whiteSpaceSize == actualWhitespaceSize; } private bool IsPreviousTokenOnSameLineAndApartByWhitespace(LinkedListNode tokenNode) diff --git a/Tests/Rules/UseConsistentWhitespace.tests.ps1 b/Tests/Rules/UseConsistentWhitespace.tests.ps1 index fb7864d7a..a12dd8a64 100644 --- a/Tests/Rules/UseConsistentWhitespace.tests.ps1 +++ b/Tests/Rules/UseConsistentWhitespace.tests.ps1 @@ -237,6 +237,7 @@ $x = "abc"; $ruleConfiguration.CheckOpenParen = $false $ruleConfiguration.CheckOperator = $false $ruleConfiguration.CheckPipe = $true + $ruleConfiguration.CheckPipeForRedundantWhiteSpace = $false $ruleConfiguration.CheckSeparator = $false } @@ -246,22 +247,20 @@ $x = "abc"; Test-CorrectionExtentFromContent $def $violations 1 '' ' ' } - It "Should find a violation if there is no space before pipe" { + It "Should not find a violation if there is no space before pipe" { $def = 'Get-Item| foo' $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings Test-CorrectionExtentFromContent $def $violations 1 '' ' ' } - It "Should find a violation if there is one space too much before pipe" { + It "Should not find a violation if there is one space too much before pipe" { $def = 'Get-Item | foo' - $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings - Test-CorrectionExtentFromContent $def $violations 1 ' ' ' ' + Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -BeNullOrEmpty } It "Should find a violation if there is one space too much after pipe" { $def = 'Get-Item | foo' - $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings - Test-CorrectionExtentFromContent $def $violations 1 ' ' ' ' + Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -BeNullOrEmpty } It "Should not find a violation if there is 1 space before and after a pipe" { @@ -294,6 +293,51 @@ foo } } + Context "CheckPipeForRedundantWhiteSpace" { + BeforeAll { + $ruleConfiguration.CheckInnerBrace = $false + $ruleConfiguration.CheckOpenBrace = $false + $ruleConfiguration.CheckOpenParen = $false + $ruleConfiguration.CheckOperator = $false + $ruleConfiguration.CheckPipe = $false + $ruleConfiguration.CheckPipeForRedundantWhiteSpace = $true + $ruleConfiguration.CheckSeparator = $false + } + + It "Should not find a violation if there is no space around pipe" { + $def = 'foo|bar' + $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -BeNullOrEmpty + } + + It "Should not find a violation if there is exactly one space around pipe" { + $def = 'foo | bar' + $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -BeNullOrEmpty + } + + It "Should find a violation if there is one space too much before pipe" { + $def = 'foo | bar' + $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings + Test-CorrectionExtentFromContent $def $violations 1 ' ' ' ' + } + + It "Should find a violation if there is two spaces too much before pipe" { + $def = 'foo | bar' + $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings + Test-CorrectionExtentFromContent $def $violations 1 ' ' ' ' + } + + It "Should find a violation if there is one space too much after pipe" { + $def = 'foo | bar' + $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings + Test-CorrectionExtentFromContent $def $violations 1 ' ' ' ' + } + + It "Should find a violation if there is two spaces too much after pipe" { + $def = 'foo | bar' + $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings + Test-CorrectionExtentFromContent $def $violations 1 ' ' ' ' + } + } Context "CheckInnerBrace" { BeforeAll { From ffbec6c66fa115b66db64628c82027a4365c6c9b Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Mon, 10 Feb 2020 09:40:19 +0000 Subject: [PATCH 2/6] docs and naming tweaks --- RuleDocumentation/UseConsistentWhitespace.md | 6 +++++- Rules/UseConsistentWhitespace.cs | 15 ++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/RuleDocumentation/UseConsistentWhitespace.md b/RuleDocumentation/UseConsistentWhitespace.md index a40c04c8d..2efc1b5b2 100644 --- a/RuleDocumentation/UseConsistentWhitespace.md +++ b/RuleDocumentation/UseConsistentWhitespace.md @@ -54,7 +54,11 @@ Checks if a comma or a semicolon is followed by a space. E.g. `@(1, 2, 3)` or `@ #### CheckPipe: bool (Default value is `$true`) -Checks if a pipe is surrounded on both sides by a space. E.g. `foo | bar` instead of `foo|bar`. +Checks if a pipe is surrounded on both sides by a space but ignores redundant whitespace. E.g. `foo | bar` instead of `foo|bar`. + +#### CheckPipeForRedundantWhiteSpace: bool (Default value is `$false`) + +Checks if a pipe is surrounded by redundant whitespace (i.e. more than 1 whitespace). E.g. `foo | bar` instead of `foo|bar`. #### CheckParameter: bool (Default value is `$false` at the moment due to the setting being new) diff --git a/Rules/UseConsistentWhitespace.cs b/Rules/UseConsistentWhitespace.cs index eddd6ee92..8387b430f 100644 --- a/Rules/UseConsistentWhitespace.cs +++ b/Rules/UseConsistentWhitespace.cs @@ -263,7 +263,7 @@ private IEnumerable FindInnerBraceViolations(TokenOperations t continue; } - if (!IsNextTokenApartByWhitespace(lCurly, out bool redundantWhitespace)) + if (!IsNextTokenApartByWhitespace(lCurly)) { yield return new DiagnosticRecord( GetError(ErrorKind.AfterOpeningBrace), @@ -317,9 +317,9 @@ private IEnumerable FindPipeViolations(TokenOperations tokenOp continue; } - if (!IsNextTokenApartByWhitespace(pipe, out bool redundantWhitespace)) + if (!IsNextTokenApartByWhitespace(pipe, out bool hasRedundantWhitespace)) { - if (CheckPipeForRedundantWhiteSpace && redundantWhitespace || CheckPipe && !redundantWhitespace) + if (CheckPipeForRedundantWhiteSpace && hasRedundantWhitespace || CheckPipe && !hasRedundantWhitespace) { yield return new DiagnosticRecord( GetError(ErrorKind.AfterPipe), @@ -345,9 +345,9 @@ private IEnumerable FindPipeViolations(TokenOperations tokenOp continue; } - if (!IsPreviousTokenApartByWhitespace(pipe, out bool redundantWhitespace)) + if (!IsPreviousTokenApartByWhitespace(pipe, out bool hasRedundantWhitespace)) { - if (CheckPipeForRedundantWhiteSpace && redundantWhitespace || CheckPipe && !redundantWhitespace) + if (CheckPipeForRedundantWhiteSpace && hasRedundantWhitespace || CheckPipe && !hasRedundantWhitespace) { yield return new DiagnosticRecord( GetError(ErrorKind.BeforePipe), @@ -488,6 +488,11 @@ private static bool IsPreviousTokenApartByWhitespace(LinkedListNode token return whiteSpaceSize == actualWhitespaceSize; } + private static bool IsNextTokenApartByWhitespace(LinkedListNode tokenNode) + { + return IsNextTokenApartByWhitespace(tokenNode, out _); + } + private static bool IsNextTokenApartByWhitespace(LinkedListNode tokenNode, out bool hasRedundantWhitespace) { var actualWhitespaceSize = tokenNode.Next.Value.Extent.StartColumnNumber - tokenNode.Value.Extent.EndColumnNumber; From dec55175fd98927f1aeaebb0eea2c0f86077d2e4 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Mon, 10 Feb 2020 09:42:18 +0000 Subject: [PATCH 3/6] casing --- Engine/Settings/CodeFormatting.psd1 | 2 +- Engine/Settings/CodeFormattingAllman.psd1 | 2 +- Engine/Settings/CodeFormattingOTBS.psd1 | 2 +- Engine/Settings/CodeFormattingStroustrup.psd1 | 2 +- RuleDocumentation/UseConsistentWhitespace.md | 4 ++-- Rules/UseConsistentWhitespace.cs | 8 ++++---- Tests/Rules/UseConsistentWhitespace.tests.ps1 | 6 +++--- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Engine/Settings/CodeFormatting.psd1 b/Engine/Settings/CodeFormatting.psd1 index 2520d1af7..f4c456e2d 100644 --- a/Engine/Settings/CodeFormatting.psd1 +++ b/Engine/Settings/CodeFormatting.psd1 @@ -37,7 +37,7 @@ CheckOpenParen = $true CheckOperator = $true CheckPipe = $true - CheckPipeForRedundantWhiteSpace = $false + CheckPipeForRedundantWhitespace = $false CheckSeparator = $true CheckParameter = $false } diff --git a/Engine/Settings/CodeFormattingAllman.psd1 b/Engine/Settings/CodeFormattingAllman.psd1 index 2d4bae7f4..b0689e461 100644 --- a/Engine/Settings/CodeFormattingAllman.psd1 +++ b/Engine/Settings/CodeFormattingAllman.psd1 @@ -37,7 +37,7 @@ CheckOpenParen = $true CheckOperator = $true CheckPipe = $true - CheckPipeForRedundantWhiteSpace = $false + CheckPipeForRedundantWhitespace = $false CheckSeparator = $true CheckParameter = $false } diff --git a/Engine/Settings/CodeFormattingOTBS.psd1 b/Engine/Settings/CodeFormattingOTBS.psd1 index 0d7eb9780..0109a1afe 100644 --- a/Engine/Settings/CodeFormattingOTBS.psd1 +++ b/Engine/Settings/CodeFormattingOTBS.psd1 @@ -37,7 +37,7 @@ CheckOpenParen = $true CheckOperator = $true CheckPipe = $true - CheckPipeForRedundantWhiteSpace = $false + CheckPipeForRedundantWhitespace = $false CheckSeparator = $true CheckParameter = $false } diff --git a/Engine/Settings/CodeFormattingStroustrup.psd1 b/Engine/Settings/CodeFormattingStroustrup.psd1 index 12bd4445d..578483081 100644 --- a/Engine/Settings/CodeFormattingStroustrup.psd1 +++ b/Engine/Settings/CodeFormattingStroustrup.psd1 @@ -38,7 +38,7 @@ CheckOpenParen = $true CheckOperator = $true CheckPipe = $true - CheckPipeForRedundantWhiteSpace = $false + CheckPipeForRedundantWhitespace = $false CheckSeparator = $true CheckParameter = $false } diff --git a/RuleDocumentation/UseConsistentWhitespace.md b/RuleDocumentation/UseConsistentWhitespace.md index 2efc1b5b2..6b90832b6 100644 --- a/RuleDocumentation/UseConsistentWhitespace.md +++ b/RuleDocumentation/UseConsistentWhitespace.md @@ -19,7 +19,7 @@ CheckOpenParen = $true CheckOperator = $true CheckPipe = $true - CheckPipeForRedundantWhiteSpace = $false + CheckPipeForRedundantWhitespace = $false CheckSeparator = $true CheckParameter = $false } @@ -56,7 +56,7 @@ Checks if a comma or a semicolon is followed by a space. E.g. `@(1, 2, 3)` or `@ Checks if a pipe is surrounded on both sides by a space but ignores redundant whitespace. E.g. `foo | bar` instead of `foo|bar`. -#### CheckPipeForRedundantWhiteSpace: bool (Default value is `$false`) +#### CheckPipeForRedundantWhitespace : bool (Default value is `$false`) Checks if a pipe is surrounded by redundant whitespace (i.e. more than 1 whitespace). E.g. `foo | bar` instead of `foo|bar`. diff --git a/Rules/UseConsistentWhitespace.cs b/Rules/UseConsistentWhitespace.cs index 8387b430f..760c4f67e 100644 --- a/Rules/UseConsistentWhitespace.cs +++ b/Rules/UseConsistentWhitespace.cs @@ -49,7 +49,7 @@ private List>> violationFind public bool CheckPipe { get; protected set; } [ConfigurableRuleProperty(defaultValue: false)] - public bool CheckPipeForRedundantWhiteSpace { get; protected set; } + public bool CheckPipeForRedundantWhitespace { get; protected set; } [ConfigurableRuleProperty(defaultValue: true)] public bool CheckOpenParen { get; protected set; } @@ -76,7 +76,7 @@ public override void ConfigureRule(IDictionary paramValueMap) violationFinders.Add(FindInnerBraceViolations); } - if (CheckPipe || CheckPipeForRedundantWhiteSpace) + if (CheckPipe || CheckPipeForRedundantWhitespace ) { violationFinders.Add(FindPipeViolations); } @@ -319,7 +319,7 @@ private IEnumerable FindPipeViolations(TokenOperations tokenOp if (!IsNextTokenApartByWhitespace(pipe, out bool hasRedundantWhitespace)) { - if (CheckPipeForRedundantWhiteSpace && hasRedundantWhitespace || CheckPipe && !hasRedundantWhitespace) + if (CheckPipeForRedundantWhitespace && hasRedundantWhitespace || CheckPipe && !hasRedundantWhitespace) { yield return new DiagnosticRecord( GetError(ErrorKind.AfterPipe), @@ -347,7 +347,7 @@ private IEnumerable FindPipeViolations(TokenOperations tokenOp if (!IsPreviousTokenApartByWhitespace(pipe, out bool hasRedundantWhitespace)) { - if (CheckPipeForRedundantWhiteSpace && hasRedundantWhitespace || CheckPipe && !hasRedundantWhitespace) + if (CheckPipeForRedundantWhitespace && hasRedundantWhitespace || CheckPipe && !hasRedundantWhitespace) { yield return new DiagnosticRecord( GetError(ErrorKind.BeforePipe), diff --git a/Tests/Rules/UseConsistentWhitespace.tests.ps1 b/Tests/Rules/UseConsistentWhitespace.tests.ps1 index a12dd8a64..d8a9eadbb 100644 --- a/Tests/Rules/UseConsistentWhitespace.tests.ps1 +++ b/Tests/Rules/UseConsistentWhitespace.tests.ps1 @@ -237,7 +237,7 @@ $x = "abc"; $ruleConfiguration.CheckOpenParen = $false $ruleConfiguration.CheckOperator = $false $ruleConfiguration.CheckPipe = $true - $ruleConfiguration.CheckPipeForRedundantWhiteSpace = $false + $ruleConfiguration.CheckPipeForRedundantWhitespace = $false $ruleConfiguration.CheckSeparator = $false } @@ -293,14 +293,14 @@ foo } } - Context "CheckPipeForRedundantWhiteSpace" { + Context "CheckPipeForRedundantWhitespace " { BeforeAll { $ruleConfiguration.CheckInnerBrace = $false $ruleConfiguration.CheckOpenBrace = $false $ruleConfiguration.CheckOpenParen = $false $ruleConfiguration.CheckOperator = $false $ruleConfiguration.CheckPipe = $false - $ruleConfiguration.CheckPipeForRedundantWhiteSpace = $true + $ruleConfiguration.CheckPipeForRedundantWhitespace = $true $ruleConfiguration.CheckSeparator = $false } From cd31f2a56aa8df8329781d1e0ddb3f637606cdb3 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Tue, 11 Feb 2020 15:30:42 +0000 Subject: [PATCH 4/6] remove redundant whitespace --- Engine/Settings/CodeFormatting.psd1 | 2 +- Engine/Settings/CodeFormattingAllman.psd1 | 2 +- Engine/Settings/CodeFormattingOTBS.psd1 | 2 +- Engine/Settings/CodeFormattingStroustrup.psd1 | 2 +- RuleDocumentation/UseConsistentWhitespace.md | 2 +- Rules/UseConsistentWhitespace.cs | 8 ++++---- Tests/Rules/UseConsistentWhitespace.tests.ps1 | 6 +++--- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Engine/Settings/CodeFormatting.psd1 b/Engine/Settings/CodeFormatting.psd1 index f4c456e2d..0676fccf1 100644 --- a/Engine/Settings/CodeFormatting.psd1 +++ b/Engine/Settings/CodeFormatting.psd1 @@ -37,7 +37,7 @@ CheckOpenParen = $true CheckOperator = $true CheckPipe = $true - CheckPipeForRedundantWhitespace = $false + CheckPipeForRedundantWhitespace = $false CheckSeparator = $true CheckParameter = $false } diff --git a/Engine/Settings/CodeFormattingAllman.psd1 b/Engine/Settings/CodeFormattingAllman.psd1 index b0689e461..a0c649457 100644 --- a/Engine/Settings/CodeFormattingAllman.psd1 +++ b/Engine/Settings/CodeFormattingAllman.psd1 @@ -37,7 +37,7 @@ CheckOpenParen = $true CheckOperator = $true CheckPipe = $true - CheckPipeForRedundantWhitespace = $false + CheckPipeForRedundantWhitespace = $false CheckSeparator = $true CheckParameter = $false } diff --git a/Engine/Settings/CodeFormattingOTBS.psd1 b/Engine/Settings/CodeFormattingOTBS.psd1 index 0109a1afe..21f4c0995 100644 --- a/Engine/Settings/CodeFormattingOTBS.psd1 +++ b/Engine/Settings/CodeFormattingOTBS.psd1 @@ -37,7 +37,7 @@ CheckOpenParen = $true CheckOperator = $true CheckPipe = $true - CheckPipeForRedundantWhitespace = $false + CheckPipeForRedundantWhitespace = $false CheckSeparator = $true CheckParameter = $false } diff --git a/Engine/Settings/CodeFormattingStroustrup.psd1 b/Engine/Settings/CodeFormattingStroustrup.psd1 index 578483081..34ea924a5 100644 --- a/Engine/Settings/CodeFormattingStroustrup.psd1 +++ b/Engine/Settings/CodeFormattingStroustrup.psd1 @@ -38,7 +38,7 @@ CheckOpenParen = $true CheckOperator = $true CheckPipe = $true - CheckPipeForRedundantWhitespace = $false + CheckPipeForRedundantWhitespace = $false CheckSeparator = $true CheckParameter = $false } diff --git a/RuleDocumentation/UseConsistentWhitespace.md b/RuleDocumentation/UseConsistentWhitespace.md index 6b90832b6..4c6bcdf6f 100644 --- a/RuleDocumentation/UseConsistentWhitespace.md +++ b/RuleDocumentation/UseConsistentWhitespace.md @@ -19,7 +19,7 @@ CheckOpenParen = $true CheckOperator = $true CheckPipe = $true - CheckPipeForRedundantWhitespace = $false + CheckPipeForRedundantWhitespace = $false CheckSeparator = $true CheckParameter = $false } diff --git a/Rules/UseConsistentWhitespace.cs b/Rules/UseConsistentWhitespace.cs index 760c4f67e..f589d9e45 100644 --- a/Rules/UseConsistentWhitespace.cs +++ b/Rules/UseConsistentWhitespace.cs @@ -49,7 +49,7 @@ private List>> violationFind public bool CheckPipe { get; protected set; } [ConfigurableRuleProperty(defaultValue: false)] - public bool CheckPipeForRedundantWhitespace { get; protected set; } + public bool CheckPipeForRedundantWhitespace { get; protected set; } [ConfigurableRuleProperty(defaultValue: true)] public bool CheckOpenParen { get; protected set; } @@ -76,7 +76,7 @@ public override void ConfigureRule(IDictionary paramValueMap) violationFinders.Add(FindInnerBraceViolations); } - if (CheckPipe || CheckPipeForRedundantWhitespace ) + if (CheckPipe || CheckPipeForRedundantWhitespace) { violationFinders.Add(FindPipeViolations); } @@ -319,7 +319,7 @@ private IEnumerable FindPipeViolations(TokenOperations tokenOp if (!IsNextTokenApartByWhitespace(pipe, out bool hasRedundantWhitespace)) { - if (CheckPipeForRedundantWhitespace && hasRedundantWhitespace || CheckPipe && !hasRedundantWhitespace) + if (CheckPipeForRedundantWhitespace && hasRedundantWhitespace || CheckPipe && !hasRedundantWhitespace) { yield return new DiagnosticRecord( GetError(ErrorKind.AfterPipe), @@ -347,7 +347,7 @@ private IEnumerable FindPipeViolations(TokenOperations tokenOp if (!IsPreviousTokenApartByWhitespace(pipe, out bool hasRedundantWhitespace)) { - if (CheckPipeForRedundantWhitespace && hasRedundantWhitespace || CheckPipe && !hasRedundantWhitespace) + if (CheckPipeForRedundantWhitespace && hasRedundantWhitespace || CheckPipe && !hasRedundantWhitespace) { yield return new DiagnosticRecord( GetError(ErrorKind.BeforePipe), diff --git a/Tests/Rules/UseConsistentWhitespace.tests.ps1 b/Tests/Rules/UseConsistentWhitespace.tests.ps1 index d8a9eadbb..0d1441384 100644 --- a/Tests/Rules/UseConsistentWhitespace.tests.ps1 +++ b/Tests/Rules/UseConsistentWhitespace.tests.ps1 @@ -237,7 +237,7 @@ $x = "abc"; $ruleConfiguration.CheckOpenParen = $false $ruleConfiguration.CheckOperator = $false $ruleConfiguration.CheckPipe = $true - $ruleConfiguration.CheckPipeForRedundantWhitespace = $false + $ruleConfiguration.CheckPipeForRedundantWhitespace = $false $ruleConfiguration.CheckSeparator = $false } @@ -293,14 +293,14 @@ foo } } - Context "CheckPipeForRedundantWhitespace " { + Context "CheckPipeForRedundantWhitespace" { BeforeAll { $ruleConfiguration.CheckInnerBrace = $false $ruleConfiguration.CheckOpenBrace = $false $ruleConfiguration.CheckOpenParen = $false $ruleConfiguration.CheckOperator = $false $ruleConfiguration.CheckPipe = $false - $ruleConfiguration.CheckPipeForRedundantWhitespace = $true + $ruleConfiguration.CheckPipeForRedundantWhitespace = $true $ruleConfiguration.CheckSeparator = $false } From 842475f33d2307e2b5b838488f8ee0816f6152b7 Mon Sep 17 00:00:00 2001 From: "Christoph Bergmeister [MVP]" Date: Tue, 11 Feb 2020 17:26:18 +0000 Subject: [PATCH 5/6] Update RuleDocumentation/UseConsistentWhitespace.md --- RuleDocumentation/UseConsistentWhitespace.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RuleDocumentation/UseConsistentWhitespace.md b/RuleDocumentation/UseConsistentWhitespace.md index 4c6bcdf6f..f6959515f 100644 --- a/RuleDocumentation/UseConsistentWhitespace.md +++ b/RuleDocumentation/UseConsistentWhitespace.md @@ -58,7 +58,8 @@ Checks if a pipe is surrounded on both sides by a space but ignores redundant wh #### CheckPipeForRedundantWhitespace : bool (Default value is `$false`) -Checks if a pipe is surrounded by redundant whitespace (i.e. more than 1 whitespace). E.g. `foo | bar` instead of `foo|bar`. +Checks if a pipe is surrounded by redundant whitespace (i.e. more than 1 whitespace). E.g. `foo | bar` instead of `foo | + bar`. #### CheckParameter: bool (Default value is `$false` at the moment due to the setting being new) From c2f33576d17718b41ca801b352e8352667a96ae5 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Tue, 11 Feb 2020 17:32:10 +0000 Subject: [PATCH 6/6] remove redundant newline --- RuleDocumentation/UseConsistentWhitespace.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/RuleDocumentation/UseConsistentWhitespace.md b/RuleDocumentation/UseConsistentWhitespace.md index f6959515f..0e7509d1e 100644 --- a/RuleDocumentation/UseConsistentWhitespace.md +++ b/RuleDocumentation/UseConsistentWhitespace.md @@ -58,8 +58,7 @@ Checks if a pipe is surrounded on both sides by a space but ignores redundant wh #### CheckPipeForRedundantWhitespace : bool (Default value is `$false`) -Checks if a pipe is surrounded by redundant whitespace (i.e. more than 1 whitespace). E.g. `foo | bar` instead of `foo | - bar`. +Checks if a pipe is surrounded by redundant whitespace (i.e. more than 1 whitespace). E.g. `foo | bar` instead of `foo | bar`. #### CheckParameter: bool (Default value is `$false` at the moment due to the setting being new)