AddViolation(), which subsequently checks the lines indentation against the expected indentation, is not called if the conditional evaluates to true.
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 to false.
Fixes #1994
I've run this rule recursively over some large code-bases, including the PSScriptAnalyzer repo.
In the current 1.22.0 we find 2,927 violations.
With this PR applied, we find 2,931 violations.
I believe the settings I used (below) means the rule defaults to spaces and many of the files were using tabs - hence the large number of violations.
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:
https://github.com/PowerShell/PSScriptAnalyzer/blob/a754b950467aa9e78a1eba1a3423bbd055ed8772/Rules/UseConsistentIndentation.cs#L165-L177
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
PSScriptAnalyzer
repo.1.22.0
we find2,927
violations.2,931
violations.spaces
and many of the files were usingtabs
- hence the large number of violations.There were 4 newly found violations:
\Tests\Engine\ModuleHelp.Tests.ps1\ModuleHelp.Tests.ps1
line 48 https://github.com/PowerShell/PSScriptAnalyzer/blob/a754b950467aa9e78a1eba1a3423bbd055ed8772/Tests/Engine/ModuleHelp.Tests.ps1#L47-L54This becomes:
Which is a little dubious 🤔
\Tests\Engine\ModuleHelp.Tests.ps1\ModuleHelp.Tests.ps1
line 116 https://github.com/PowerShell/PSScriptAnalyzer/blob/a754b950467aa9e78a1eba1a3423bbd055ed8772/Tests/Engine/ModuleHelp.Tests.ps1#L115-L117This 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.psm1
line 518 https://github.com/PowerShell/PSScriptAnalyzer/blob/a754b950467aa9e78a1eba1a3423bbd055ed8772/Tests/Engine/CommunityAnalyzerRules/CommunityAnalyzerRules.psm1#L515-L521This is changed to:
\Tests\Rules\UseToExportFieldsInManifest.tests.ps1\UseToExportFieldsInManifest.tests.ps1
line 73This is a line that randomly uses tabs
PR Checklist
.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
to the beginning of the title and remove the prefix when the PR is ready.