Skip to content
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

When a line ends in an equal sign, automatically indent the next line since it is part of the assignment statement #4997

Closed
2 tasks done
deadlydog opened this issue May 23, 2024 · 1 comment
Labels
Issue-Enhancement A feature request (enhancement). Needs: Triage Maintainer attention needed!

Comments

@deadlydog
Copy link

deadlydog commented May 23, 2024

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.

Summary

When a line ends in an equal sign, I would like the formatting of the next line to be automatically indented. This would help make it clear that the next line is part of the assignment and not the start of a new code statement. This would also allow it to match the behaviour used when a line ends with the pipe character, since it too is a continuation of a code statement, and would match the default behaviour of other languages, such as C# in Visual Studio.

For example, when using the VS Code setting powershell.codeFormatting.pipelineIndentationStyle = IncreaseIndentationForFirstPipeline, the code is currently formatted like this:

$result =
Get-Process |
    Select-Object -First 1

I would prefer = to follow the same rules as | and have the code formatted like this:

$result =
    Get-Process |
    Select-Object -First 1

In this small example it may look silly to not just do:

$result = Get-Process |
    Select-Object -First 1

However, sometimes with fully qualified namespaces and descriptive variable names, the left-side of the equal operator may get very lengthy, such as:

[System.Collections.ArrayList] $listOfCustomersWithValidDriversLicenses = Get-CustomersFromCmdletWithAVeryLongName -Country Canada -AreaCode 123

This would look much better and prevent horizontal scrolling as:

[System.Collections.ArrayList] $listOfCustomersWithValidDriversLicenses = 
    Get-CustomersFromCmdletWithAVeryLongName -Country Canada -AreaCode 123

Currently, VS Code formats the code like this:

[System.Collections.ArrayList] $listOfCustomersWithValidDriversLicenses = 
Get-CustomersFromCmdletWithAVeryLongName -Country Canada -AreaCode 123

The current formatting makes it easy to overlook that the results returned from Get-CustomersFromCmdletWithAVeryLongName are being saved in a variable.

Proposed Design

No response

@deadlydog
Copy link
Author

Looking at some other formatting requests, it looks like it is PSScriptAnalyzer that handles all of the code formatting, so I have moved this request to the PSScriptAnalyzer repo here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement A feature request (enhancement). Needs: Triage Maintainer attention needed!
Projects
None yet
Development

No branches or pull requests

1 participant