-
Notifications
You must be signed in to change notification settings - Fork 394
Indentation don't follow the same indentation as the row with the open brace #1032
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I am not sure why the current implementation behaves like that (if it was by design from the author or just a case that got forgotten) but I think your expected behaviour makes sense to, therefore I think we should try to correct it. |
I was about to submit a new issue and saw the title of this issue and thought just maybe it might be related. Good thing I checked, because I think this is exactly my issue. Here's what I was going to submit in a new issue: Steps to reproduceJust a quick note, other than enabling the rule, the default settings for indentation are used: 4 spaces. function Get-SomeDataById {
[CmdletBinding()]
param (
[Parameter(Mandatory = $True, Position = 1, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
[string[]]$Id
Process {
foreach ($i in $Id) {
try {
$Results = [hashtable]@{}
# Pretend I'm processing the results of some other action...
$Results.Add($i, @(foreach ($Action in 1..10)) {
[PSCustomObject]@{
PSTypeName = 'MyCustomType'
Id = "$Action"
}
}))
} catch {
throw [Exception]::new("Something went wrong.", $_.Exception)
}
}
}
} Expected behaviorI expected no warnings to be produced (when Severity is set to Warning), as the code is all nicely indented. Actual behavior
I didn't expect these warnings since the code is consistently indented! There's no ragged left edge anywhere. I have a feeling that the logic used to detect when indentation should occur is not as smart as it should be, taking a brief look at the code. It appears (at a terse glance) that when certain characters are seen (i.e. Environment data> $PSVersionTable
PS C:\WINDOWS\system32> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.17763.134
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.134
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.17.1 |
Hmm, my "analysis" is off, as it appears given the OP's description, the analyzer appears to "mis-count" the amount of indentation required--which of course, is what I meant (and have experienced in other places of my code), but not at all what I said. Anyway, just wanted to post my example, too. |
@fourpastmidnight |
I'm seeing a case where the indentation of closing braces is still falling down when the pipelineIndentationStyle option is set to anything but NoIndentation. If the pipeline is on a single line, but includes a multi-line script block (e.g. ForEach-Object) the indentation goes sideways. I'm using PSScriptAnalyzer 1.18.1. For example:
|
I think I may have the same issue. This occurs in VS Code. The following code results in a PSUseConsistentIndentation problem. It refers to the second from last closing brace: Describe -Name 'Test' -Fixture {
It -Name 'Test' -Test {
{1 / 0 -or `
2 / 0} | Should throw
}
} If I format the document using Describe -Name 'Test' -Fixture {
It -Name 'Test' -Test {
{1 / 0 -or `
2 / 0} | Should throw
}
} Notice that the second from last closing brace has been unindented. Strangely, if I move the Describe -Name 'Test' -Fixture {
It -Name 'Test' -Test {
{1 / 0 -or `
2 / 0} |
Should throw
}
} VS Code
Installed Extensions for VS Code
> $PSVersionTable Name Value
---- -----
PSVersion 6.2.2
PSEdition Core
GitCommitId 6.2.2
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0 > (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
Various Settings Files settings.json |
@ThubLives I can repro your issue for PSSA 1.18.1 but PR #1261 already fixed this case, therefore your case will be fixed in the next version. In the meantime, the @mrboring Thanks for your examples and info, unfortunately, I can repro your issue even with the latest version of |
Closing this now as the issue of @ThubLives is already fixed in master and will be in the next release. |
Steps to reproduce
Expected behavior
Actual behavior
Environment data
The text was updated successfully, but these errors were encountered: