Pretty Printer v1 - Clean and reformat your PowerShell scripts
Now on GitHub: Pretty printer v1 - Edit-DTWCleanScript
Edit-DTWCleanScript is a PowerShell pretty printer / code cleaner; it:
IMPORTANT NOTE: before running this on any script make sure you back it up, commit any changes you have or run this on a copy of your script. In the event this script screws up or the get encoding is incorrect (say you have non-ANSI characters at the end of a long file with no BOM), I don't want your script to be damaged! Let me know if you encounter any issues.
This pretty printer module doesn't do everything - it's version 1. Version 2 (using PowerShell 3's new tokenizing/AST functionality) should allow me to fix most of the deficiencies. But just so you know, here's what it doesn't do:
For more information see: http://danspowershellstuff.blogspot.com/2012/03/powershell-pretty-printer-code-cleaner.html
Now on GitHub: Pretty printer v1 - Edit-DTWCleanScript
Edit-DTWCleanScript is a PowerShell pretty printer / code cleaner; it:
- properly indents code inside {}, [], () and $() groups
- replaces aliases with the command names: dir → Get-ChildItem
- fixes command name casing: get-childitem → Get-ChildItem
- fixes parameter name casing: Test-Path -path → Test-Path -Path
- fixes [type] casing
- changes all PowerShell shortcuts to lower: [STRING] → [string]
- changes other types: [system.exception] → [System.Exception]
- cleans/rearranges all whitespace within a line
IMPORTANT NOTE: before running this on any script make sure you back it up, commit any changes you have or run this on a copy of your script. In the event this script screws up or the get encoding is incorrect (say you have non-ANSI characters at the end of a long file with no BOM), I don't want your script to be damaged! Let me know if you encounter any issues.
This pretty printer module doesn't do everything - it's version 1. Version 2 (using PowerShell 3's new tokenizing/AST functionality) should allow me to fix most of the deficiencies. But just so you know, here's what it doesn't do:
- change location of group openings, say ( or {, from same line to new line and vice-versa;
- expand param names (Test-Path -Inc → Test-Path -Include);
- offer user options to control how space is reformatted.
For more information see: http://danspowershellstuff.blogspot.com/2012/03/powershell-pretty-printer-code-cleaner.html