{"id":13599039,"url":"https://github.com/Kriegel/BeautyOfPower","last_synced_at":"2025-04-10T12:31:13.438Z","repository":{"id":87468924,"uuid":"281726862","full_name":"Kriegel/BeautyOfPower","owner":"Kriegel","description":"PowerShell Module to tidy / beautify PowerShell sourcecode and to do refactoring.","archived":false,"fork":false,"pushed_at":"2020-08-15T11:39:56.000Z","size":683,"stargazers_count":7,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-02T17:35:52.515Z","etag":null,"topics":["beautifier","beautify","case-sensitivity","format","formatter","formatting","powershell","pretty-printer","refactor","refactoring","tidy"],"latest_commit_sha":null,"homepage":"","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kriegel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-07-22T16:19:45.000Z","updated_at":"2024-04-22T21:59:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"368e4d36-da20-4d88-99bd-cba3219bcf05","html_url":"https://github.com/Kriegel/BeautyOfPower","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kriegel%2FBeautyOfPower","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kriegel%2FBeautyOfPower/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kriegel%2FBeautyOfPower/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kriegel%2FBeautyOfPower/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kriegel","download_url":"https://codeload.github.com/Kriegel/BeautyOfPower/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223437249,"owners_count":17144877,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["beautifier","beautify","case-sensitivity","format","formatter","formatting","powershell","pretty-printer","refactor","refactoring","tidy"],"created_at":"2024-08-01T17:00:59.146Z","updated_at":"2024-11-07T00:30:32.474Z","avatar_url":"https://github.com/Kriegel.png","language":"PowerShell","funding_links":[],"categories":["PowerShell"],"sub_categories":[],"readme":"# BeautyOfPower (BoP)\n\n**PowerShell Module to format PowerShell script text (sourcecode) to beautify PowerShell sourcecode and to do refactoring on PowerShell sourcecode**\n\n\nThe Functions out of this Module will change (refactor) PowerShell sourcecode.\nThe Authors of this Module have done great care to do no harm or damage to the processed sourcecode and its execution behavior or results.\n\nBest is to run the this Module in a Sandbox or an Sandbox like Virtual Machine to process, refactor or tidy PowerShell sourcecode.\n\nTO REVIEW THE CHANGES MADE TO THE SOURCECODE, BEFORE EXECUTING IT, IS ON YOUR OWN RESPONSIBILITY.\n\nfor Disclaimer of liability see License.\n\n**Alternativly** to this Module use the Module **PSScriptAnalyzer** and his Cmdlet **Invoke-Formatter**\n\u003chttps://github.com/PowerShell/PSScriptAnalyzer\u003e\n\u003csub\u003e(The reason I devlop my own Module here is that PSScriptAnalyzer is written in C# so I can not contribute there and Invoke-Fomatter seems to be an [unloved Kid](https://github.com/PowerShell/PSScriptAnalyzer/issues/775) and shows no development Progress. :-(  )\u003c/sub\u003e\n\n## Usage\n\n```powershell\n\n# import Module (from Path)\nImport-Module 'BeautyOfPower'\n\n# path to file which holds the sourcecode and is to be prettified\n$FileToBeParsed = 'C:\\PsCode\\TestFile.ps1'\n\n# define path for the resulting out file\n$OutFilePath = \"$env:Temp\\Out-Tesfile.ps1\"\n# remove out file (if exist before)\n$Null = Remove-Item $OutFilePath -confirm:$False -ErrorAction 'ignore'\n# create an new empty out file\n$Null = New-Item $OutFilePath -ItemType File -Force\n\n\n# Let the sourcecode parsed by the PowerShell parser and Tokenize it\n# parse File C:\\PsCode\\TestFile.ps1\n# IT IS STRONGLY NOT RECOMENDED TO USE -IncludeNestedToken IN REFACTORING,\n# THIS WILL DAMAGE THE CODE!\nGet-BopTokenAndAst -Path $FileToBeParsed |\n# Convert .NET Tokens to custom, writeable Bop-Tokens\nConvertTo-BopToken |\n#\n# Chain the Formating functions to process the tokens\n#\n# Functions which correct the casing of the Tokens\n#\nFormat-BopCasingTypeName |\nFormat-BopCasingAttributeName |\nFormat-BopCasingKeyword -ToLower |\nFormat-BopCasingCommandName |\nFormat-BopCasingParameter |\nFormat-BopCasingTypeMemberName |\nFormat-BopCasingKnownVariables -MSDefault -IncludeUnknownVars |\nFormat-BopCasingScopeModifier |\nFormat-BopCasingOperator -MixedCase |\n#\n# Function to define the place of the opening brace (LCurly) (here on their own line)\n#\nFormat-BopLCurly -LCurlyOnNewLine |\n#\n# Function to expand Command-Alias\n#\nFormat-BopExpandCommandAlias -CaseSensitiv -IncludeAll |\n#\n# Functions to process Command ParameterNames\n#\n# Command Parameter casing\nFormat-BopCasingParameter | # this calls : Format-BopParameter -Format 'Casing'\n# Shortened Command Parameter expanding\nFormat-BopExpandParameterShort | # this calls : Format-BopParameter -Format 'ExpandShort'\n# Convert Command Parameter-Alias to real Parameter Name\nFormat-BopExpandParameterAlias  | # this calls : Format-BopParameter -Format 'ExpandAlias'\n# For faster processing alternativly to the single functions, you can use :\n# Format-BopParameter -Format 'All'\n#\n# Add ParameterName to Positional Parameter\n# (convert Positional Parameters to Named Parameters)\n# THIS FUNCTION IS EXPERIMENTAL! USE -Force TO USE IT REGARDLESS\nFormat-BopAddParameterName -Force|\n#\nForEach-Object {\n\n    # Writing the processed Tokens one after the other to the output file and add spaces between the Tokens\n    # Write the Surrogate to the file!\n    Add-Content -Path $OutFilePath -Value ((' ' * $Token.PrefixSpaces)  + $Token.Surrogate) -NoNewline\n}\n\n# show the out file\nNotepad.exe $OutFilePath\n\n```\n\n## Description\n\nI am developing this Module to prettify PowerShell sourcecode, downloaded from the Internet.\nI am a german resident, we germans have imbibe word casing from first day of writing.\nMany coders in the world, do not care about correct casing, this has itched me so much,\nthat i have started to develop this Module. (even though I am very bad in grammar)\n\nSo the first bunch of Formating functions of this Module are processing PowerShell sourcecode for casing.\n\n### Roadmap\n\n- Largely Done! :-) replace aliases with the names who points the alias to (command alias and ParameterName alias or shorts)\n\n- a bunch of functions to place braces (and space between them).\n\n- write some functions to ident the code and to correct other whitespace.\n\n## Main Functions of this Module\n\n### Get-BopTokenAndAst\n\nUtilizes the PowerShell \"advanced\" parser to Parse PowerShell sourcecode from File (*.ps1, *.psm1, *.psd1) or Scriptblock or a String Variable.\nReturns the Tokens, the AST, syntax Errors and additionally Informations as a custom Object.\n(Big credits for this function goes to Tobias Weltner)\n\n### ConvertTo-BopToken\n\nThis Function creates an flat clone from 'System.Management.Automation.Language.Token' Token Types.\nWith additional fields useful for refactoring and to prettify.\n\nMicrosoft allows not to Instantiate custom .NET Tokens and\nmost of the Properties (Fields) of the .NET Token Class members are not edit able.\nFor simple access of deep nested members, economize memory consumption and for speed reasons this function creates custom Token Object with writeable (set able) fields.\n\nThe custom Token Object produced by this function are consumed by the formatting functions.\n\n### Formatting Functions\n\n#### Casing\n\n- Format-BopCasingTypeName\n\n- Format-BopCasingAttributeName\n\n- Format-BopCasingKeyword (uses PascalCase by default!)\n\n- Format-BopCasingCommandName\n\n- Format-BopCasingParameter\n\n- Format-BopCasingTypeMemberName\n\n- Format-BopCasingKnownVariables (uses PascalCase by default!)\n\n- Format-BopCasingParameter ; alternativly use : Format-BopParameter -Format 'Casing'\n\n- Format-BopCasingScopeModifier\n\n- Format-BopCasingOperator\n\nWatchout for additional Parameters a Function servers.\nThis can be used to change casing behavior\n\nSee also: Capitalization guidelines\n\u003chttps://github.com/PoshCode/PowerShellPracticeAndStyle/issues/36\u003e\n\n#### Brace placement\n\n- Format-BopLCurly (Kernighan \u0026 Ritchie Style and Allman style)\n\n#### Adding content (that was not there before)\n\n- Format-BopAddParameterName\n\n#### Expanding Alias and shortnames\n\n- Format-BopExpandCommandAlias\n\n- Format-BopExpandParameterShort\n  (alternativly use : Format-BopParameter -Format 'ExpandShort')\n\n- Format-BopExpandParameterAlias\n  (alternativly use : Format-BopParameter -Format 'ExpandAlias')\n\n#### All in one Functions\n\n- Format-BopParameter -Format 'All'\n  (replacement for: Format-BopCasingParameter + Format-BopExpandParameterShort + Format-BopExpandParameterAlias)\n\n## Insights\n\nIn this Module the Tokens parsed from PowerShell sourcecode are the first class citizen.\nThe Tokens are handled as a Stream (of Tokens)\n\nFor more insights, read the sourcecode of the Module and functions and see documents in folder Doc!\n\n## Informations about Formating PowerShell Code\n\nWindows PowerShell Language Specification Version 3.0\n(download as Word document .docx Year 2012)\n\u003chttps://www.microsoft.com/en-us/download/details.aspx?id=36389\u003e\n\nPowershell Practice and Style recomendations\n\u003chttps://poshcode.gitbooks.io/powershell-practice-and-style/\u003e\n\nAlso useful for general PowerShell code:\nDSC Resource Style Guidelines \u0026 Best Practices\n\u003chttps://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md\u003e\n\nKnown Issues for PowerShell 6.0\nCase-sensitivity in PowerShell etc. ...\n\u003chttps://docs.microsoft.com/en-us/powershell/scripting/whats-new/known-issues-ps6\u003e\n\n## Credits\n\nCredits goes to:\n\nTobias Welter\n\n\u003chttps://github.com/TobiasPSP/Modules.PSOneTools\u003e\n\n\u003chttps://powershell.one/powershell-internals/parsing-and-tokenization/advanced-tokenizer\u003e\n\n\u003chttps://powershell.one/powershell-internals/parsing-and-tokenization/abstract-syntax-tree\u003e\n\nDan Ward\n\nhttps://github.com/DTW-DanWard/PowerShell-Beautifier\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKriegel%2FBeautyOfPower","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKriegel%2FBeautyOfPower","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKriegel%2FBeautyOfPower/lists"}