PSUseConsistentIndentation: Check indentation of lines where first token is a LParen not followed by comment or new line #1995
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


PR Summary
Currently if an LParen
(is the first token on a line and the next token is not a comment or new line, then the line's indentation is not checked.This is due to this if-check:
PSScriptAnalyzer/Rules/UseConsistentIndentation.cs
Lines 165 to 177 in a754b95
AddViolation(), which subsequently checks the lines indentation against the expected indentation, is not called if the conditional evaluates totrue.This PR changes the logic to always call
AddViolation(), so the indentation is checked, but to only increase the indentation level when the conditional evaluates tofalse.Fixes #1994
I've run this rule recursively over some large code-bases, including the
PSScriptAnalyzerrepo.1.22.0we find2,927violations.2,931violations.spacesand many of the files were usingtabs- hence the large number of violations.\Tests\Engine\ModuleHelp.Tests.ps1\ModuleHelp.Tests.ps1line 48PSScriptAnalyzer/Tests/Engine/ModuleHelp.Tests.ps1
Lines 47 to 54 in a754b95
This becomes:
Which is a little dubious 🤔
\Tests\Engine\ModuleHelp.Tests.ps1\ModuleHelp.Tests.ps1line 116PSScriptAnalyzer/Tests/Engine/ModuleHelp.Tests.ps1
Lines 115 to 117 in a754b95
This line wasn't previously being checked. It's using tabs, and as mentioned above the settings is defaulting to spaces.
\Tests\Engine\CommunityAnalyzerRules\CommunityAnalyzerRules.psm1\CommunityAnalyzerRules.psm1line 518PSScriptAnalyzer/Tests/Engine/CommunityAnalyzerRules/CommunityAnalyzerRules.psm1
Lines 515 to 521 in a754b95
This is changed to:
\Tests\Rules\UseToExportFieldsInManifest.tests.ps1\UseToExportFieldsInManifest.tests.ps1line 73This is a line that randomly uses tabs
PR Checklist
.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.