Is there a PowerShell code formatter / pretty printer? [closed]

点点圈 提交于 2019-11-27 10:44:32

问题


I'm looking for a source code beautifyer for PowerShell programs. Ideally, it would be CLI based, but any solution is acceptable. I would like to avoid configuring a generic pretty printer tool; I'd like a solution that works for PowerShell out of the box. Is there such a thing?


回答1:


UPDATE: it's now on GitHub: https://github.com/DTW-DanWard/PowerShell-Beautifier

I wrote a PowerShell pretty printer / code cleaner in PowerShell. It cleans white space, indents code groups, replaces aliases with commands, fixes casing on commands, parameters, types, etc. You can use it to reformat a file in place or read a source file and output the result in a different file.

More info: http://danspowershellstuff.blogspot.com/2012/03/powershell-pretty-printer-code-cleaner.html

Download page: http://www.dtwconsulting.com/PS/Module_PrettyPrinterV1.htm

Let me know what you'd like to see changed/configurable/etc.




回答2:


I don't know of any. However, PowerShell V2 exposes a PowerShell tokenizer you could build on: System.Management.Automation.PsParser

It might be interesting to do some "lint"-like checks, too.

For example, I think scripts should avoid using aliases that aren't marked ReadOnly, as users may have changed them. See Where are the default aliases defined in powershell? for some discussion.




回答3:


Take a look at ScriptCop.
Props to Mike Shepard - I found this from his answer here.



来源:https://stackoverflow.com/questions/2987176/is-there-a-powershell-code-formatter-pretty-printer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!