PSScriptAnalyzer icon indicating copy to clipboard operation
PSScriptAnalyzer copied to clipboard

feature request for formatting rule to have an empty line after brace

Open t3mi opened this issue 4 years ago • 2 comments

Summary of the new feature This is a proposal to add additional formatting rule to have an empty line after brace to keep code more readable with OTBS scheme. It's a separate rule comparing to inserting a new line.

Current behaviour:

...
foreach ($account in $Permissions.Keys) {
    foreach ($permission in $Permissions[$account].Keys) {
        foreach ($folder in $Permissions[$account][$permission]) {
            cNtfsPermissionEntry $folder {
                Ensure                   = 'Present'
                Path                     = $folder
                Principal                = $account
                AccessControlInformation = @(
                    cNtfsAccessControlInformation {
                        FileSystemRights  = $permission
                    }
                )
            }
        }
    }
}
...

Proposed behaviour:

...
foreach ($account in $Permissions.Keys) {

    foreach ($permission in $Permissions[$account].Keys) {

        foreach ($folder in $Permissions[$account][$permission]) {

            cNtfsPermissionEntry $folder {
                Ensure                   = 'Present'
                Path                     = $folder
                Principal                = $account
                AccessControlInformation = @(
                    cNtfsAccessControlInformation {
                        FileSystemRights  = $permission
                    }
                )
            }
        }
    }
}
...

t3mi avatar May 15 '21 07:05 t3mi

The formatting functionality is actually provided by a different repo - https://github.com/PowerShell/PSScriptAnalyzer. You should post this suggestion there. BTW your proposed behavior is not quite right. Shouldn't it be:

foreach ($account in $Permissions.Keys) {

    foreach ($permission in $Permissions[$account].Keys) {

        foreach ($folder in $Permissions[$account][$permission]) {

            cNtfsPermissionEntry $folder {

                Ensure                   = 'Present'
                Path                     = $folder
                Principal                = $account
                AccessControlInformation = @(

                    cNtfsAccessControlInformation {

                        FileSystemRights  = $permission
                    }
                )
            }
        }
    }
}

rkeithhill avatar May 15 '21 17:05 rkeithhill

This could be an option on the PSCloseBrace rule/setting but I cannot imagine it being on by default or one of the 3 code style schemes. Would it still be valuable to you then?

bergmeister avatar May 17 '21 21:05 bergmeister