Visitar URL original
[Formatter] Indent Right(hand side) `CommandExpressionAst` · Issue #2175 · PowerShell/PSScriptAnalyzer · GitHub
Skip to content

[Formatter] Indent Right(hand side) CommandExpressionAst #2175

Description

@iRon7

Indent (a multiline) righthand side (list) expression assignment.
Meaning, for a (multiline) Statements.Right CommandExpressionAst (as apposed to Ast's that have already their own embedded indention, as e.g. a PipelineAst), I would like the righthand side to (optionally?) increase the indent:

Wrong way (?)

$List =
'One',
'Two',
'Three'

Correct way

$List =
    'One',
    'Two',
    'Three'

Wrong way (?)

$4 = # or any lengthy variable name aka dot notation
2 + 2

Correct way

$4 = # or any lengthy variable name aka dot notation
    2 + 2

Activity

  1. changed the title [-][Formatter] Right(hand side) list indention[/-] [+][Formatter] Indent Right(hand side) `CommandExpressionAst`[/+] on Apr 21, 2026
  2. bergmeister commented on Apr 21, 2026

    @bergmeister
    Collaborator

    iRon7 are you using latest 1.25.0 release? Cc Liam Peters (@liamjpeters)

  3. iRon7 commented on Apr 21, 2026

    @iRon7
    ContributorAuthor

    @iRon7 are you using latest 1.25.0 release? Cc @liamjpeters

    I think I do:

    Get-Command Invoke-Formatter     
    
    CommandType     Name                                               Version    Source
    -----------     ----                                               -------    ------
    Cmdlet          Invoke-Formatter                                   1.25.0     PSScriptAnalyzer

    But under VSCode, it is a little confusing as the PowerShell extension appears to still come with 1.24.0.
    Besides, I noticed another issue, see: PowerShell/vscode-powershell#5474

    Why do you ask?

  4. liamjpeters commented on Apr 22, 2026

    @liamjpeters
    Contributor

    There's nothing that does this currently that I'm aware of.

    It would be hard to do, as most of the formatters (including for indentation) act on the stream of tokens and not the AST.

    They know that there's an equals sign, but not that it's part of a wider expression with a beginning and an end line and column. So it might be trivial to say that indentation can optionally start at an equals token, but where does it then end?

    I guess you could read the AST up front and keep a list of the starts and ends of expressions you want to affect indentation and check that when during token enumeration. It would be messy though and difficult to get right.

  5. iRon7 commented on Apr 22, 2026

    @iRon7
    ContributorAuthor

    formatters (including for indentation) act on the stream of tokens and not the AST.

    Thank you for your comment, I wasn't aware of that.

  6. bergmeister commented on May 7, 2026

    @bergmeister
    Collaborator

    @iRon7 are you using latest 1.25.0 release? Cc @liamjpeters

    I think I do:

    Get-Command Invoke-Formatter

    CommandType Name Version Source


    Cmdlet Invoke-Formatter 1.25.0 PSScriptAnalyzer
    But under VSCode, it is a little confusing as the PowerShell extension appears to still come with 1.24.0. Besides, I noticed another issue, see: PowerShell/vscode-powershell#5474

    Why do you ask?

    VS Code PowerShell extension ships with PSSA version and binds to that one.

    Therefore until it gets updated, please try repro using Invoke-Formatter (Get-Content -Raw) in a different terminal other than the integrated one of VS-Code extension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions