zloeber / formatpowershellcode Goto Github PK
View Code? Open in Web Editor NEWFormat PowerShell code with PowerShell code
License: Other
Format PowerShell code with PowerShell code
License: Other
Hi Zachary Loeber,
nice formatting script for Powershell. I just found a bug I guess. It would be great if you can fix that as comments shouldn't be deleted. I just provide you here with a simple example:
Get-Content test.ps1 -raw | Format-ScriptExpandParameterBlocks | clip
test.ps1 consists of:
Param
(
# Information type of log entry
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0,
ParameterSetName = 'Info')]
[ValidateNotNull()]
[ValidateNotNullOrEmpty()]
[Alias("information")]
[System.String]$Info)
After formatting:
param (
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0,
ParameterSetName = 'Info')]
[ValidateNotNull()]
[ValidateNotNullOrEmpty()]
[Alias("information")]
[System.String]$Info
)
The comment is deleted. Can you please fix that?
Thanks
Viki
Heya, I've written a script that looks at a directory and runs the formatter every second on all .ps1 files.
When it came to this code,
Write-Host($subs | Format-Table -Property @{name="Option";expression={$global:indexSub;$global:indexSub+=1}}, SubscriptionId, SubscriptionName | Out-String)
The formatter adds a newline to the front of Out-String, eventually it becomes:
Write-Host($subs |
Format-Table -Property @{name="Option";expression={$global:indexSub;$global:indexSub+=1}}, SubscriptionId, SubscriptionName |
Out-String)
And that blank space increases ad infinitum.
Format-ScriptFormatCodeIndentation stops working after release building. It's related to the following code:
$AST = [System.Management.Automation.Language.Parser]::ParseInput($ScriptText, [ref]$Tokens, [ref]$ParseError)
It will be change after build process is run:
$AST = [System.Management.Automation.Language.Parser]::ParseInput($ScriptText, [System.Management.Automation.PSReference]$Tokens, [System.Management.Automation.PSReference]$ParseError)
It seems types are expanded incorrectly because $Tokens variable will always be empty. If I change it back to [ref] everything works again.
I'm hoping that in the real world, your output is better than in the readme ๐
But in the readme you lost the newlines, and you have one line that's 2 lines long.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.