Skip to content

Consistent Script formatting #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dpaulson45 opened this issue Dec 23, 2020 · 2 comments
Closed

Consistent Script formatting #9

dpaulson45 opened this issue Dec 23, 2020 · 2 comments

Comments

@dpaulson45
Copy link
Member

We also need to decide on a consistent set of styling rules and shift-alt-F these files in VSCode. For example, in some places we have Javascript-style braces (my own preference), and in some places we have C# style braces. In some places we have <# #> multiline comments, and in other places we have # multiline comments. But we can address styling consistency in a separate PR.

Originally posted by @bill-long in #8 (comment)

+++++++++++++++++++++++++++++++++

Not sure if we can get the comments in there, but we can align to something within a build pipeline for this. This makes it easier for other people to contribute to the project as well without having them need to setup VSCode and pressing shift-alt-F.

One option that I have played around with is this one:

https://github.com/PowerShell/PSScriptAnalyzer/blob/master/docs/markdown/Invoke-Formatter.md

We should be able to easily add this to a build pipeline.

Import-Module PSScriptAnalyzer
$content = Get-Content .\Setup\SetupAssist.ps1
$stringContent = [string]::Empty
foreach($line in $content)
{
    $stringContent += "{0}`r`n" -f $line
}

$test = Invoke-Formatter $stringContent -Setting .\settings\codeformatting.psd1
if ($test -ne $content)
{
    throw "failed to meet code formatting requirements"
}

another option appears to be this one:

https://sumtips.com/software/powershell-beautifier-free-tool-to-pretty-print-ps1-script-files/#:~:text=%20How%20to%20Use%20PowerShell%20Beautifier%20%201,Save%20Formatted%20Code%20as%20New%20File.%20More%20

I haven't looked much into it.

@dpaulson45
Copy link
Member Author

I personally like Allman style, but it looks like more people like OTBS.

PoshCode/PowerShellPracticeAndStyle#81

@dpaulson45
Copy link
Member Author

Completed in PR #12

erinIs1337 added a commit that referenced this issue Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant