From 6d7221299e8679531a8e7d1eb758fe8675103dba Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Wed, 14 Nov 2018 08:06:29 +0000 Subject: [PATCH 1/8] Fix PSUseConsistentIndentationRule to handle pipes correctly when there is a multi-line statement after it: Do not just add temporary indentation for the next line but keep the indentation level --- Rules/UseConsistentIndentation.cs | 13 ++++++++----- Tests/Rules/UseConsistentIndentation.tests.ps1 | 4 +++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Rules/UseConsistentIndentation.cs b/Rules/UseConsistentIndentation.cs index f3395cca5..2710345f0 100644 --- a/Rules/UseConsistentIndentation.cs +++ b/Rules/UseConsistentIndentation.cs @@ -123,6 +123,14 @@ public override IEnumerable AnalyzeScript(Ast ast, string file AddViolation(token, indentationLevel++, diagnosticRecords, ref onNewLine); break; + case TokenKind.Pipe: + if (k < tokens.Length - 1 && + (tokens[k + 1].Kind == TokenKind.NewLine || tokens[k + 1].Kind == TokenKind.LineContinuation)) + { + AddViolation(token, indentationLevel++, diagnosticRecords, ref onNewLine); + } + break; + case TokenKind.RParen: case TokenKind.RCurly: indentationLevel = ClipNegative(indentationLevel - 1); @@ -156,11 +164,6 @@ public override IEnumerable AnalyzeScript(Ast ast, string file { --j; } - - if (j >= 0 && tokens[j].Kind == TokenKind.Pipe) - { - ++tempIndentationLevel; - } } AddViolation(token, tempIndentationLevel, diagnosticRecords, ref onNewLine); diff --git a/Tests/Rules/UseConsistentIndentation.tests.ps1 b/Tests/Rules/UseConsistentIndentation.tests.ps1 index 0f91b7e3f..7ba979359 100644 --- a/Tests/Rules/UseConsistentIndentation.tests.ps1 +++ b/Tests/Rules/UseConsistentIndentation.tests.ps1 @@ -135,7 +135,9 @@ where-object {$_.Name -match 'powershell'} It "Should not find a violation if a pipleline element is indented correctly" { $def = @' get-process | - where-object {$_.Name -match 'powershell'} + where-object { + $_.Name -match 'powershell' + } '@ $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings $violations.Count | Should -Be 0 From eddbbcc3c16b6798e345be43451c7ec9494c4fc0 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Wed, 14 Nov 2018 23:16:24 +0000 Subject: [PATCH 2/8] correctly decrement indentation count for multiple pipes --- Rules/UseConsistentIndentation.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Rules/UseConsistentIndentation.cs b/Rules/UseConsistentIndentation.cs index 2710345f0..98f2ecec6 100644 --- a/Rules/UseConsistentIndentation.cs +++ b/Rules/UseConsistentIndentation.cs @@ -170,11 +170,26 @@ public override IEnumerable AnalyzeScript(Ast ast, string file } break; } + + var pipelines = ast.FindAll(testAst => testAst is PipelineAst && (testAst as PipelineAst).PipelineElements.Count > 1, true); + var matchingPipeline = pipelines.FirstOrDefault(pipelineAst => + PositionIsEqual(pipelineAst.Extent.EndScriptPosition, token.Extent.EndScriptPosition)) as PipelineAst; + if (pipelines != null && matchingPipeline != null) + { + indentationLevel = ClipNegative(indentationLevel - (matchingPipeline.PipelineElements.Count - 1)); + } } return diagnosticRecords; } + private static bool PositionIsEqual(IScriptPosition position1, IScriptPosition position2) + { + return position1.ColumnNumber == position2.ColumnNumber && + position1.LineNumber == position2.LineNumber && + position1.File == position2.File; + } + /// /// Retrieves the common name of this rule. /// From 0991326767b778808bc099e935fb4292eb466280 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Mon, 19 Nov 2018 18:30:09 +0000 Subject: [PATCH 3/8] add customisation --- Rules/UseConsistentIndentation.cs | 59 +++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/Rules/UseConsistentIndentation.cs b/Rules/UseConsistentIndentation.cs index 98f2ecec6..274b4d68b 100644 --- a/Rules/UseConsistentIndentation.cs +++ b/Rules/UseConsistentIndentation.cs @@ -57,6 +57,24 @@ public string Kind } } + + [ConfigurableRuleProperty(defaultValue: "IncreaseIndentationForFirstPipeline")] + public string PipelineIndentation + { + get + { + return pipelineIndentationStyle.ToString(); + } + set + { + if (String.IsNullOrWhiteSpace(value) || + !Enum.TryParse(value, true, out pipelineIndentationStyle)) + { + pipelineIndentationStyle = PipelineIndentationStyle.IncreaseIndentationAfterEveryPipeline; + } + } + } + private bool insertSpaces; private char indentationChar; private int indentationLevelMultiplier; @@ -68,9 +86,17 @@ private enum IndentationKind { // Auto }; + private enum PipelineIndentationStyle + { + IncreaseIndentationForFirstPipeline, + IncreaseIndentationAfterEveryPipeline, + NoIndentation + } + // TODO make this configurable private IndentationKind indentationKind = IndentationKind.Space; + private PipelineIndentationStyle pipelineIndentationStyle = PipelineIndentationStyle.IncreaseIndentationAfterEveryPipeline; /// /// Analyzes the given ast to find violations. @@ -104,6 +130,7 @@ public override IEnumerable AnalyzeScript(Ast ast, string file var diagnosticRecords = new List(); var indentationLevel = 0; var onNewLine = true; + var pipelineAsts = ast.FindAll(testAst => testAst is PipelineAst && (testAst as PipelineAst).PipelineElements.Count > 1, true); for (int k = 0; k < tokens.Length; k++) { var token = tokens[k]; @@ -124,11 +151,24 @@ public override IEnumerable AnalyzeScript(Ast ast, string file break; case TokenKind.Pipe: - if (k < tokens.Length - 1 && - (tokens[k + 1].Kind == TokenKind.NewLine || tokens[k + 1].Kind == TokenKind.LineContinuation)) + var pipelineIsFollowedByNewlineOrLineContinuation = k < tokens.Length - 1 && k > 0 && + (tokens[k + 1].Kind == TokenKind.NewLine || tokens[k + 1].Kind == TokenKind.LineContinuation); + if (!pipelineIsFollowedByNewlineOrLineContinuation) + { + break; + } + if (pipelineIndentationStyle == PipelineIndentationStyle.IncreaseIndentationAfterEveryPipeline) { AddViolation(token, indentationLevel++, diagnosticRecords, ref onNewLine); } + else if (pipelineIndentationStyle == PipelineIndentationStyle.IncreaseIndentationForFirstPipeline) + { + var isFirstPipeInPipeline = pipelineAsts.Any(pipelineAst => PositionIsEqual(((PipelineAst)pipelineAst).PipelineElements[0].Extent.EndScriptPosition, tokens[k - 1].Extent.EndScriptPosition)); + if (isFirstPipeInPipeline) + { + AddViolation(token, indentationLevel++, diagnosticRecords, ref onNewLine); + } + } break; case TokenKind.RParen: @@ -171,12 +211,19 @@ public override IEnumerable AnalyzeScript(Ast ast, string file break; } - var pipelines = ast.FindAll(testAst => testAst is PipelineAst && (testAst as PipelineAst).PipelineElements.Count > 1, true); - var matchingPipeline = pipelines.FirstOrDefault(pipelineAst => + // Check if the current token matches the end of a PipelineAst + var matchingPipeLineAstEnd = pipelineAsts.FirstOrDefault(pipelineAst => PositionIsEqual(pipelineAst.Extent.EndScriptPosition, token.Extent.EndScriptPosition)) as PipelineAst; - if (pipelines != null && matchingPipeline != null) + if (matchingPipeLineAstEnd != null) { - indentationLevel = ClipNegative(indentationLevel - (matchingPipeline.PipelineElements.Count - 1)); + if (pipelineIndentationStyle == PipelineIndentationStyle.IncreaseIndentationForFirstPipeline) + { + indentationLevel = ClipNegative(indentationLevel - 1); + } + else if (pipelineIndentationStyle == PipelineIndentationStyle.IncreaseIndentationAfterEveryPipeline) + { + indentationLevel = ClipNegative(indentationLevel - (matchingPipeLineAstEnd.PipelineElements.Count - 1)); + } } } From 99611c7c98fac9440d8ca730b49ce6429fc8da70 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Mon, 26 Nov 2018 10:45:59 +0000 Subject: [PATCH 4/8] take pipeline into account and add docs. TODO: Change shipped setting files --- RuleDocumentation/UseConsistentIndentation.md | 24 +++++++++++++++++++ Rules/UseConsistentIndentation.cs | 18 ++++++++++---- .../Rules/UseConsistentIndentation.tests.ps1 | 20 +++++++++++++++- 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/RuleDocumentation/UseConsistentIndentation.md b/RuleDocumentation/UseConsistentIndentation.md index ade8866f4..deca041ee 100644 --- a/RuleDocumentation/UseConsistentIndentation.md +++ b/RuleDocumentation/UseConsistentIndentation.md @@ -15,6 +15,7 @@ Indentation should be consistent throughout the source file. PSUseConsistentIndentation = @{ Enable = $true IndentationSize = 4 + PipelineIndentation = 'IncreaseIndentationForFirstPipeline' Kind = 'space' } } @@ -30,6 +31,29 @@ Enable or disable the rule during ScriptAnalyzer invocation. Indentation size in the number of space characters. +#### PipelineIndentation: string (Default value is `IncreaseIndentationForFirstPipeline`) + +Whether to increase indentation after a pipeline for multi-line statements. The settings are: + +- IncreaseIndentationForFirstPipeline (default): Indent once after the first pipeline and keep this indentation. Example: +```powershell +foo | + bar | + baz +``` +- IncreaseIndentationAfterEveryPipeline: Indent more after the first pipeline and keep this indentation. Example: +```powershell +foo | + bar | + baz +``` +- NoIndentation: Do not increase indentation. Example: +```powershell +foo | +bar | +baz +``` + #### Kind: string (Default value is `space`) Represents the kind of indentation to be used. Possible values are: `space`, `tab`. If any invalid value is given, the property defaults to `space`. diff --git a/Rules/UseConsistentIndentation.cs b/Rules/UseConsistentIndentation.cs index 274b4d68b..8e0969ace 100644 --- a/Rules/UseConsistentIndentation.cs +++ b/Rules/UseConsistentIndentation.cs @@ -206,7 +206,12 @@ public override IEnumerable AnalyzeScript(Ast ast, string file } } - AddViolation(token, tempIndentationLevel, diagnosticRecords, ref onNewLine); + var lineHasPipelineBeforeToken = tokens.Any(oneToken => + oneToken.Kind == TokenKind.Pipe && + oneToken.Extent.StartLineNumber == token.Extent.StartLineNumber && + oneToken.Extent.StartColumnNumber < token.Extent.StartColumnNumber); + + AddViolation(token, tempIndentationLevel, diagnosticRecords, ref onNewLine, lineHasPipelineBeforeToken); } break; } @@ -302,7 +307,8 @@ private void AddViolation( Token token, int expectedIndentationLevel, List diagnosticRecords, - ref bool onNewLine) + ref bool onNewLine, + bool lineHasPipelineBeforeToken = false) { if (onNewLine) { @@ -330,26 +336,28 @@ private void AddViolation( GetDiagnosticSeverity(), fileName, null, - GetSuggestedCorrections(token, expectedIndentationLevel))); + GetSuggestedCorrections(token, expectedIndentationLevel, lineHasPipelineBeforeToken))); } } } private List GetSuggestedCorrections( Token token, - int indentationLevel) + int indentationLevel, + bool lineHasPipelineBeforeToken = false) { // TODO Add another constructor for correction extent that takes extent // TODO handle param block // TODO handle multiline commands var corrections = new List(); + var optionalPipeline = lineHasPipelineBeforeToken ? "| " : string.Empty; corrections.Add(new CorrectionExtent( token.Extent.StartLineNumber, token.Extent.EndLineNumber, 1, token.Extent.EndColumnNumber, - GetIndentationString(indentationLevel) + token.Extent.Text, + GetIndentationString(indentationLevel) + optionalPipeline + token.Extent.Text, token.Extent.File)); return corrections; } diff --git a/Tests/Rules/UseConsistentIndentation.tests.ps1 b/Tests/Rules/UseConsistentIndentation.tests.ps1 index 7ba979359..370390bc4 100644 --- a/Tests/Rules/UseConsistentIndentation.tests.ps1 +++ b/Tests/Rules/UseConsistentIndentation.tests.ps1 @@ -170,6 +170,24 @@ $x = "this " + ` } Test-CorrectionExtentFromContent @params } + + It "Should indent properly after line continuation (backtick) character with pipeline" { + $def = @' +foo | + bar ` +| baz +'@ + $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings + $violations.Count | Should -Be 1 + $params = @{ + RawContent = $def + DiagnosticRecord = $violations[0] + CorrectionsCount = 1 + ViolationText = "| baz" + CorrectionText = (New-Object -TypeName String -ArgumentList $indentationUnit, $indentationSize) + "| baz" + } + Test-CorrectionExtentFromContent @params + } } Context "When tabs instead of spaces are used for indentation" { @@ -185,7 +203,7 @@ get-childitem $x=1+2 $hashtable = @{ property1 = "value" - anotherProperty = "another value" + anotherProperty = "another value" } } '@ From abff01a2f6017d5022900cb35b4528a533540bf8 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Mon, 26 Nov 2018 11:05:39 +0000 Subject: [PATCH 5/8] update formatting setting files --- Engine/Settings/CodeFormatting.psd1 | 1 + Engine/Settings/CodeFormattingAllman.psd1 | 1 + Engine/Settings/CodeFormattingOTBS.psd1 | 1 + Engine/Settings/CodeFormattingStroustrup.psd1 | 1 + 4 files changed, 4 insertions(+) diff --git a/Engine/Settings/CodeFormatting.psd1 b/Engine/Settings/CodeFormatting.psd1 index 02a07a1da..d2e5437d3 100644 --- a/Engine/Settings/CodeFormatting.psd1 +++ b/Engine/Settings/CodeFormatting.psd1 @@ -25,6 +25,7 @@ PSUseConsistentIndentation = @{ Enable = $true Kind = 'space' + PipelineIndentation = 'IncreaseIndentationAfterEveryPipeline' IndentationSize = 4 } diff --git a/Engine/Settings/CodeFormattingAllman.psd1 b/Engine/Settings/CodeFormattingAllman.psd1 index 15b0ecfbd..e02cda261 100644 --- a/Engine/Settings/CodeFormattingAllman.psd1 +++ b/Engine/Settings/CodeFormattingAllman.psd1 @@ -25,6 +25,7 @@ PSUseConsistentIndentation = @{ Enable = $true Kind = 'space' + PipelineIndentation = 'IncreaseIndentationAfterEveryPipeline' IndentationSize = 4 } diff --git a/Engine/Settings/CodeFormattingOTBS.psd1 b/Engine/Settings/CodeFormattingOTBS.psd1 index 589487235..0fa84db8a 100644 --- a/Engine/Settings/CodeFormattingOTBS.psd1 +++ b/Engine/Settings/CodeFormattingOTBS.psd1 @@ -25,6 +25,7 @@ PSUseConsistentIndentation = @{ Enable = $true Kind = 'space' + PipelineIndentation = 'IncreaseIndentationAfterEveryPipeline' IndentationSize = 4 } diff --git a/Engine/Settings/CodeFormattingStroustrup.psd1 b/Engine/Settings/CodeFormattingStroustrup.psd1 index f40c83988..f63cc9911 100644 --- a/Engine/Settings/CodeFormattingStroustrup.psd1 +++ b/Engine/Settings/CodeFormattingStroustrup.psd1 @@ -26,6 +26,7 @@ PSUseConsistentIndentation = @{ Enable = $true Kind = 'space' + PipelineIndentation = 'IncreaseIndentationAfterEveryPipeline' IndentationSize = 4 } From 524caeaa169aac859375c243196885e31bbbdb7e Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Mon, 26 Nov 2018 15:40:30 +0000 Subject: [PATCH 6/8] add tests and refactor/improve test suite --- .../Rules/UseConsistentIndentation.tests.ps1 | 109 +++++++++++------- 1 file changed, 67 insertions(+), 42 deletions(-) diff --git a/Tests/Rules/UseConsistentIndentation.tests.ps1 b/Tests/Rules/UseConsistentIndentation.tests.ps1 index 370390bc4..408423dc7 100644 --- a/Tests/Rules/UseConsistentIndentation.tests.ps1 +++ b/Tests/Rules/UseConsistentIndentation.tests.ps1 @@ -3,41 +3,40 @@ $testRootDirectory = Split-Path -Parent $directory Import-Module (Join-Path $testRootDirectory "PSScriptAnalyzerTestHelper.psm1") -$indentationUnit = ' ' -$indentationSize = 4 -$ruleConfiguration = @{ - Enable = $true - IndentationSize = 4 - Kind = 'space' -} - -$settings = @{ - IncludeRules = @("PSUseConsistentIndentation") - Rules = @{ - PSUseConsistentIndentation = $ruleConfiguration +Describe "UseConsistentIndentation" { + BeforeEach { + $indentationUnit = ' ' + $indentationSize = 4 + $ruleConfiguration = @{ + Enable = $true + IndentationSize = 4 + PipelineIndentation = 'IncreaseIndentationForFirstPipeline' + Kind = 'space' + } + + $settings = @{ + IncludeRules = @("PSUseConsistentIndentation") + Rules = @{ + PSUseConsistentIndentation = $ruleConfiguration + } + } } -} -Describe "UseConsistentIndentation" { Context "When top level indentation is not consistent" { - BeforeAll { + It "Should detect a violation" { $def = @' function foo ($param1) { } '@ - $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings - } - - It "Should detect a violation" { $violations.Count | Should -Be 1 } } Context "When nested indenation is not consistent" { - BeforeAll { + It "Should find a violation" { $def = @' function foo ($param1) { @@ -45,15 +44,12 @@ function foo ($param1) } '@ $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings - } - - It "Should find a violation" { $violations.Count | Should -Be 1 } } Context "When a multi-line hashtable is provided" { - BeforeAll { + It "Should find violations" { $def = @' $hashtable = @{ a = 1 @@ -62,15 +58,12 @@ b = 2 } '@ $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings - } - - It "Should find violations" { $violations.Count | Should -Be 2 } } Context "When a multi-line array is provided" { - BeforeAll { + It "Should find violations" { $def = @' $array = @( 1, @@ -78,15 +71,12 @@ $array = @( 3) '@ $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings - } - - It "Should find violations" { $violations.Count | Should -Be 2 } } Context "When a param block is provided" { - BeforeAll { + It "Should find violations" { $def = @' param( [string] $param1, @@ -99,15 +89,12 @@ $param3 ) '@ $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings - } - - It "Should find violations" { $violations.Count | Should -Be 4 } } Context "When a sub-expression is provided" { - BeforeAll { + It "Should not find a violations" { $def = @' function foo { $x = $("abc") @@ -115,9 +102,6 @@ function foo { } '@ $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings - } - - It "Should not find a violations" { $violations.Count | Should -Be 0 } } @@ -171,6 +155,45 @@ $x = "this " + ` Test-CorrectionExtentFromContent @params } + It "Should indent pipelines correctly using IncreaseIndentationAfterEveryPipeline option" { + $def = @' +foo | + bar | +baz +'@ + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'IncreaseIndentationAfterEveryPipeline' + $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings + $violations.Count | Should -Be 1 + $params = @{ + RawContent = $def + DiagnosticRecord = $violations[0] + CorrectionsCount = 1 + ViolationText = "baz" + CorrectionText = (New-Object -TypeName String -ArgumentList $indentationUnit, ($indentationSize * 2)) + 'baz' + } + Test-CorrectionExtentFromContent @params + } + + It "Should indent pipelines correctly using NoIndentation option" { + $def = @' +foo | + bar | + baz +'@ + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'NoIndentation' + $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings + $violations.Count | Should -Be 2 + $params = @{ + RawContent = $def + DiagnosticRecord = $violations[1] + CorrectionsCount = 1 + ViolationText = " baz" + CorrectionText = (New-Object -TypeName String -ArgumentList $indentationUnit, ($indentationSize * 0)) + 'baz' + } + Test-CorrectionExtentFromContent @params + } + + It "Should indent properly after line continuation (backtick) character with pipeline" { $def = @' foo | @@ -191,8 +214,8 @@ foo | } Context "When tabs instead of spaces are used for indentation" { - BeforeAll { - $ruleConfiguration.'Kind' = 'tab' + BeforeEach { + $settings.Rules.PSUseConsistentIndentation.Kind = 'tab' } It "Should indent using tabs" { @@ -203,7 +226,9 @@ get-childitem $x=1+2 $hashtable = @{ property1 = "value" - anotherProperty = "another value" + +'@ + "`t" + @' +anotherProperty = "another value" } } '@ From f2a518f96472c775d1334d73838e5231bac6a14f Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Tue, 5 Mar 2019 19:47:15 +0000 Subject: [PATCH 7/8] Apply suggestions from code review Co-Authored-By: bergmeister --- Rules/UseConsistentIndentation.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Rules/UseConsistentIndentation.cs b/Rules/UseConsistentIndentation.cs index 8e0969ace..48a057614 100644 --- a/Rules/UseConsistentIndentation.cs +++ b/Rules/UseConsistentIndentation.cs @@ -151,7 +151,7 @@ public override IEnumerable AnalyzeScript(Ast ast, string file break; case TokenKind.Pipe: - var pipelineIsFollowedByNewlineOrLineContinuation = k < tokens.Length - 1 && k > 0 && + bool pipelineIsFollowedByNewlineOrLineContinuation = k < tokens.Length - 1 && k > 0 && (tokens[k + 1].Kind == TokenKind.NewLine || tokens[k + 1].Kind == TokenKind.LineContinuation); if (!pipelineIsFollowedByNewlineOrLineContinuation) { @@ -163,7 +163,7 @@ public override IEnumerable AnalyzeScript(Ast ast, string file } else if (pipelineIndentationStyle == PipelineIndentationStyle.IncreaseIndentationForFirstPipeline) { - var isFirstPipeInPipeline = pipelineAsts.Any(pipelineAst => PositionIsEqual(((PipelineAst)pipelineAst).PipelineElements[0].Extent.EndScriptPosition, tokens[k - 1].Extent.EndScriptPosition)); + bool isFirstPipeInPipeline = pipelineAsts.Any(pipelineAst => PositionIsEqual(((PipelineAst)pipelineAst).PipelineElements[0].Extent.EndScriptPosition, tokens[k - 1].Extent.EndScriptPosition)); if (isFirstPipeInPipeline) { AddViolation(token, indentationLevel++, diagnosticRecords, ref onNewLine); From bcf7c9ad463d09d0f6f34eb2a8f6954350b9f1cf Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Tue, 5 Mar 2019 20:07:35 +0000 Subject: [PATCH 8/8] Remove else block by using break --- Rules/UseConsistentIndentation.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Rules/UseConsistentIndentation.cs b/Rules/UseConsistentIndentation.cs index 48a057614..06724c3b7 100644 --- a/Rules/UseConsistentIndentation.cs +++ b/Rules/UseConsistentIndentation.cs @@ -160,8 +160,9 @@ public override IEnumerable AnalyzeScript(Ast ast, string file if (pipelineIndentationStyle == PipelineIndentationStyle.IncreaseIndentationAfterEveryPipeline) { AddViolation(token, indentationLevel++, diagnosticRecords, ref onNewLine); + break; } - else if (pipelineIndentationStyle == PipelineIndentationStyle.IncreaseIndentationForFirstPipeline) + if (pipelineIndentationStyle == PipelineIndentationStyle.IncreaseIndentationForFirstPipeline) { bool isFirstPipeInPipeline = pipelineAsts.Any(pipelineAst => PositionIsEqual(((PipelineAst)pipelineAst).PipelineElements[0].Extent.EndScriptPosition, tokens[k - 1].Extent.EndScriptPosition)); if (isFirstPipeInPipeline)