Azure / azure-sdk-tools

Tools repository leveraged by the Azure SDK team.
MIT License
114 stars 180 forks source link

Style Checking for PowerShell Scripts. #829

Open chidozieononiwu opened 4 years ago

chidozieononiwu commented 4 years ago

To help drive consistency for many of the tools/scripts written in PowerShell I think that we should reach some team wide consensus on Style Guidelines for PowerShell code that can be enforced as part of CI.

A good option for this will be to make use of PSScriptAnalyzer which is already bundled with the Microsoft PowerShell extension for VSCode but can also be run in PowerShell and therefore as part of CI.

One way we can go about this is to first decide on the coding style to follow using either preset settings or manually configuring rules .

VSCode users will be able to adopt some of these setting as part of their workspace code formatting setting which will allow formatting on the fly/ on save. But we should add a script which runs Invoke-ScriptAnalyzer using the agreed on set of rules. This will allow for testing of new scripts locally as well as style enforcement on CI. Invoke-ScriptAnalyzer also helps automatically fix some of the rules but it does not seem to be implemented perfectly right now so we'll still need to manually fix a few things before checking in script.

Here is some community discussions about PowerShell coding styles https://github.com/PoshCode/PowerShellPracticeAndStyle/issues/81

weshaggard commented 4 years ago

As part of setting up a PS standard we should also consider setting strict mode https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/set-strictmode?view=powershell-7.

benbp commented 2 years ago

Related #3473