Skip to content

Invoke-Formatter - Allman-to-OTBS with a comment after keyword fails #800

Closed
@JPRuskin

Description

@JPRuskin

Using Invoke-Formatter, the suggested correction for correcting an Allman style brace with the pre-existing OTBS rules fails if there is a comment after the keyword.
if ($bar) # this is the test {

Expected behavior would be that the brace is moved to a non-comment section.
if ($bar) { # this is the test

Full Example:

$RulesDirectory = Join-Path -Path (Get-Module PSScriptAnalyzer -ListAvailable).ModuleBase -ChildPath 'Settings'
$Settings = Import-PowerShellDataFile (Join-Path $RulesDirectory 'CodeFormattingOTBS.psd1')

$Script = @'
function foo {
    if ($bar) # this is the test
    {
        Write-Host "bar"
    }
}
'@

$Formatted = Invoke-Formatter -Settings $Settings -ScriptDefinition $Script

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions