GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add new code formatting preset "OTPS": OTBS with `else` on new line by o-l-a-v · Pull Request #2158 · PowerShell/PSScriptAnalyzer

Conversation

@o-l-a-v

@o-l-a-v Olav Rønnestad Birkeland (o-l-a-v) commented Mar 1, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Edit: Blocked, see #2045 (comment).

PR Summary

  • Linked PR in PowerShellEditorServices: Add new code formatting preset "OTPS": OTBS with else on new line PowerShellEditorServices#2269
  • PR that can be merged after this in vscode-powershell: Add new code formatting preset "OTPS": OTBS with else on new line vscode-powershell#5413

This PR adds a new code formatting preset, "OTPS" (One True PowerShell Style): OTBS with else on new line.

Thoughts behind the name:

  • To mock the idea of one true formatting style, even though there are none.
  • We do ONE change from OTBS (else on new line), also in the name (change B with P).

Feature request:

  • New formatting preset: OTBS with else on a new line #2045

Context:

  • "There is no One True Brace Style": There is no One True Brace Style PoshCode/PowerShellPracticeAndStyle#177
    • About OTBS with else on a new line:
      • There is no One True Brace Style PoshCode/PowerShellPracticeAndStyle#177 (comment)
      • There is no One True Brace Style PoshCode/PowerShellPracticeAndStyle#177 (comment)

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Change is not breaking
  • Make sure all .cs, .ps1 and .psm1 files have the correct copyright header
  • Make sure you've added a new test if existing tests do not effectively test the code changed and/or updated documentation
  • This PR is ready to merge and is not Work in Progress.
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready.

Tested like so

# Build
.\build.ps1 -PSVersion 7 -Configuration Release

# Import built module
Import-Module -Name './out/PSScriptAnalyzer\1.24.0\PSScriptAnalyzer.psd1'

# Test new preset with OTBS as input
Invoke-Formatter -Settings 'CodeFormattingOTPS' -ScriptDefinition (@'
enum Color {
    Black, 
    White
}

function Test-Code {
    [CmdletBinding()]
    param(
        [int]$ParameterOne
    )
    end {
        if (10 -gt $ParameterOne) {
            "Greater"
        } else {
            "Lesser"
        }
    }
}
'@)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Olav Rønnestad Birkeland (o-l-a-v) added 2 commits March 1, 2026 12:00
@o-l-a-v
feat: added new code formatting preset OTPS
6949890
@o-l-a-v
feat: added new code formatting preset OTPS to some tests where i fou…
5e8ed23
…nd OTBS mentioned
@o-l-a-v
Olav Rønnestad Birkeland (o-l-a-v) requested review from a team and Christoph Bergmeister (bergmeister) as code owners March 1, 2026 11:03
This was referenced Mar 1, 2026
Add new code formatting preset "OTPS": OTBS with else on new line PowerShell/vscode-powershell#5413
Draft
Add new code formatting preset "OTPS": OTBS with else on new line PowerShell/PowerShellEditorServices#2269
Draft
bergmeister
Christoph Bergmeister (bergmeister) reviewed Mar 6, 2026
View reviewed changes

@bergmeister Christoph Bergmeister (bergmeister) left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to add it but can you please add a test that specifically tests the OTPS part of else being on new line?
Liam Peters (@liamjpeters) Are you happy with those properties since you added new ones and potentially other ones in pending PRs? Or would we need to take a note to add certain properties later here?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@o-l-a-v

Olav Rønnestad Birkeland (o-l-a-v) commented Mar 6, 2026

Copy link
Copy Markdown
Contributor Author

I don't see where I should add a test like that.

There seems to be no such test for other presets, only the specific settings seems to be tested.

Also, there are some of the tests that make no sense. Like:

PSScriptAnalyzer/Tests/Rules/PlaceOpenBrace.tests.ps1

Line 43 in aba29c3

Context "Handling of comments when using Invoke-Formatter" {

No comments are involved in those tests.


Idea: Should be create a new test file that has all the samble codes from:

PoshCode/PowerShellPracticeAndStyle#177

And just say that they are the expected output from the various presets?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@o-l-a-v
feat(tests): added dedicated test for code formatting presets
52ba0d0
Copilot AI review requested due to automatic review settings March 6, 2026 18:36
@o-l-a-v
feat(tests): added context for how code formatting presets handles cl…
3db1d6d
…osing bracket and else
@o-l-a-v

Olav Rønnestad Birkeland (o-l-a-v) commented Mar 6, 2026

Copy link
Copy Markdown
Contributor Author

I added some suggestions for tests now Christoph Bergmeister (@bergmeister). 😊

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Copilot AI reviewed Mar 6, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new code formatting preset called "OTPS" (One True PowerShell Style), which is identical to OTBS but places else on a new line (similar to Stroustrup style). The key difference from OTBS is the NewLineAfter = $true setting on PSPlaceCloseBrace.

Changes:

  • New CodeFormattingOTPS.psd1 settings file defining the OTPS preset.
  • New CodeFormattingPresets.tests.ps1 test file covering all preset cross-conversion scenarios.
  • Updates to existing brace placement tests to include the OTPS preset.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
Engine/Settings/CodeFormattingOTPS.psd1 Defines the new OTPS formatting preset rules
Tests/Rules/CodeFormattingPresets.tests.ps1 New test file verifying all formatting preset conversions including OTPS
Tests/Rules/PlaceOpenBrace.tests.ps1 Adds OTPS to existing open brace formatting tests
Tests/Rules/PlaceCloseBrace.tests.ps1 Adds new context block testing if/else formatting across all presets
Comments suppressed due to low confidence (1)

Tests/Rules/CodeFormattingPresets.tests.ps1:1

  • The $OTPSAndStroustrupDefinition test fixture in PlaceCloseBrace.tests.ps1 uses double-quoted strings ("yes", "no"), while the equivalent $OTPS fixture in CodeFormattingPresets.tests.ps1 uses single-quoted strings ('yes', 'no'). If the formatter normalizes string quoting, these fixtures could diverge in meaning or lead to test confusion. Consider aligning the quoting style between the two fixtures for consistency.
# Copyright (c) Microsoft Corporation. All rights reserved.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Tests/Rules/PlaceCloseBrace.tests.ps1
Comment on lines +406 to +413
$OTPSAndStroustrupDefinition = @"
if (`$true) {
"yes"
}
else {
"no"
}
"@

Copilot AI Mar 6, 2026

Copy link

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable $OTPSAndStroustrupDefinition implies that this definition is identical for both OTPS and Stroustrup. However, based on the full preset definitions and tests in CodeFormattingPresets.tests.ps1, OTPS and Stroustrup differ in other formatting aspects (e.g., function brace placement, param block spacing). This naming may be misleading in a broader context. Consider naming it more specifically, such as $ElseOnNewLineDefinition, to avoid implying full equivalence between the two presets.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Copilot uses AI. Check for mistakes.

@o-l-a-v Olav Rønnestad Birkeland (o-l-a-v) Mar 6, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree. For this particular test, OTPS and Stroustrup will create the same result.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@o-l-a-v
fix(tests): fix preset test presets
75a4be0
@o-l-a-v

Olav Rønnestad Birkeland (o-l-a-v) commented Mar 6, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Hmm, may these tests have found a bug in the Stroustrup preset? No, two bugs?

  1. The opening curly bracket after function definition is not on a new line.
  2. Opening paranthese after param should be on the same line.
PS > $Allman = @'
enum Color
{
    Black,
    White
}

function Test-Code
{
    [CmdletBinding()]
    param
    (
        [int] $ParameterOne
    )
    end
    {
        if (10 -gt $ParameterOne)
        {
            "Greater"
        }
        else
        {
            "Lesser"
        }
    }
}
'@

PS > Invoke-Formatter -ScriptDefinition $Allman -Settings 'CodeFormattingStroustrup'
enum Color {
    Black,
    White
}

function Test-Code {
    [CmdletBinding()]
    param
    (
        [int] $ParameterOne
    )
    end {
        if (10 -gt $ParameterOne) {
            "Greater"
        }
        else {
            "Lesser"
        }
    }
}

Edit: These are probably shortcomings with PSSA?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@liamjpeters

Liam Peters (liamjpeters) commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

Happy to add it but can you please add a test that specifically tests the OTPS part of else being on new line? Liam Peters (@liamjpeters) Are you happy with those properties since you added new ones and potentially other ones in pending PRs? Or would we need to take a note to add certain properties later here?

All good with me 😊. I should look over the settings presets once #2132 is merged, to add in the enum alignment, but that can wait. Good reminder, thanks!

Olav Rønnestad Birkeland (@o-l-a-v) - Thanks for the new tests 👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@o-l-a-v

Olav Rønnestad Birkeland (o-l-a-v) commented Mar 6, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

If I understand it correctly, PSSA code formatting only handles curly brackets, thus there will be no difference between Stroustrup and this new proposed preset. As the new test file shows, PSSA does not touch param(), or differentiates on function {} vs. if {} else {}.

If I'm not missing anything here I don't think this proposal makes sense anymore.

What do you guys think we should do? Remove the new preset, keep the closing brackets tests, remove or move to disabled the new test file I made for preset tests?

bergmeister reacted with confused emoji
All reactions
  • 😕 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@o-l-a-v
Olav Rønnestad Birkeland (o-l-a-v) marked this pull request as draft March 7, 2026 12:10
@o-l-a-v
fix(tests): fixed string quotes for new test
29da161
@o-l-a-v Olav Rønnestad Birkeland (o-l-a-v) mentioned this pull request Mar 7, 2026
feat(tests): added closing bracket test for formatting presets #2161
Merged
6 tasks done
@bergmeister
Christoph Bergmeister (bergmeister) requested a balanced review from Copilot September 14, 2026 19:58
Copilot started reviewing on behalf of Christoph Bergmeister (bergmeister) September 14, 2026 19:59
View session
Copilot AI reviewed Sep 14, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

OTPS currently duplicates Stroustrup behavior, and several new assertions require unsupported formatting transformations.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 3
  • Review effort level: Balanced

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Engine/Settings/CodeFormattingOTPS.psd1
Rules = @{
PSPlaceOpenBrace = @{
Enable = $true
OnSameLine = $true
Comment thread Tests/Rules/CodeFormattingPresets.tests.ps1
Comment on lines +18 to +19
param
(
Comment thread Tests/Rules/PlaceCloseBrace.tests.ps1
}
}

Context "When formatting presets handles if else" {
@bergmeister

Christoph Bergmeister (bergmeister) commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Olav Rønnestad Birkeland (@o-l-a-v) can you please resolve merge conflict and review latest copilot review? what is the reason this PR is back in draft and not ready?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@o-l-a-v

Olav Rønnestad Birkeland (o-l-a-v) commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Olav Rønnestad Birkeland (@o-l-a-v) can you please resolve merge conflict and review latest copilot review? what is the reason this PR is back in draft and not ready?

#2158 (comment)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bergmeister

Christoph Bergmeister (bergmeister) commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Olav Rønnestad Birkeland (Olav Rønnestad Birkeland (@o-l-a-v)) can you please resolve merge conflict and review latest copilot review? what is the reason this PR is back in draft and not ready?

#2158 (comment)

so formatting rules deal with tokens so it doesn't just look at braces but as it's derived from the AST, some things like param() don't show in the AST. the AST will always be the limitation as PSSA relies on PowerShell's parser

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@bergmeister Christoph Bergmeister (bergmeister) bergmeister left review comments
Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

At least 1 approving review is required to merge this pull request.

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@o-l-a-v @liamjpeters @bergmeister
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.