Skip to content

Possible formatting issue related to unary operators #948

Description

Issue Description

So I opened this bug at the VSCode repo:
PowerShell/vscode-powershell#1237

It's about unary operators that (from what I can tell), aren't handled correctly when formatting the code.

This:

$numberOfDaysToSubtract = 10
(Get-Date).AddDays(-$numberOfDaysToSubtract)

Becomes this:

$numberOfDaysToSubtract = 10
(Get-Date).AddDays( - $numberOfDaysToSubtract)

When formatting the code in VSCode with powershell.codeFormatting.whitespaceAroundOperator set to true.

I got a response from @tylerl0706 who clarified that this formatting actually comes from PSSA, which is why I created a bug here instead.

What do you think?

Thanks!

Activity

  1. bergmeister commented on Mar 26, 2018

    @bergmeister
    Collaborator

    Thanks for taking the time to report this issue. This is a duplicate of #847 and I believe it is by design because the setting whitespaceAroundOperator does exactly what it is supposed to do.
    I can understand however that the resulting formatting is not desired in this case,
    PSSA has 3 built in rule sets (Allman, etc.) that VSCode uses as well and I think the best solution would be to tweak them and to come up with a more refined ruleset that allows certain exceptions like this case.

  2. AWahlqvist commented on Mar 26, 2018

    @AWahlqvist
    Author

    Yes, it does seem to be a duplicate, sorry, missed the other one. Will focus any discussions to that bug instead.

    Thanks!

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