GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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
|
|
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:
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? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…osing bracket and else
|
I added some suggestions for tests now Christoph Bergmeister (@bergmeister). 😊 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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:
CodeFormattingOTPS.psd1 settings file defining the OTPS preset.CodeFormattingPresets.tests.ps1 test file covering all preset cross-conversion scenarios.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 |
Tests/Rules/CodeFormattingPresets.tests.ps1:1
$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.
There was an error while loading. Please reload this page.
| $OTPSAndStroustrupDefinition = @" | ||
| if (`$true) { | ||
| "yes" | ||
| } | ||
| else { | ||
| "no" | ||
| } | ||
| "@ |
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Hmm, may these tests have found a bug in the Stroustrup preset? No, two bugs?
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? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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 👍 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
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 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? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
OTPS currently duplicates Stroustrup behavior, and several new assertions require unsupported formatting transformations.
Get a fresh assessment by requesting another Copilot review.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Rules = @{ | ||
| PSPlaceOpenBrace = @{ | ||
| Enable = $true | ||
| OnSameLine = $true |
| param | ||
| ( |
| } | ||
| } | ||
|
|
||
| Context "When formatting presets handles if else" { |
|
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? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
At least 1 approving review is required to merge this pull request.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.