PowerShell / PowerShell/PSScriptAnalyzer
Formatting fails to pretty print a bad formatted document
オープン
まだ誰も着手していません。
Area - Formatter
Issue - Bug
- 主要言語
- C#
- スター
- 2.2k
- フォーク
- 414
- 平均マージ
- 13時間 1分
- マージ済み PR(30日)
- 2
説明
Prerequisites
- I have written a descriptive issue title.
- I have searched all issues to ensure it has not already been reported.
Summary
I have some code copied from a pdf. Here it is when I paste it in VSCode :
function Stop-ProcessUsingWMI{ [CmdletBinding(SupportsShouldProcess=$True)] param( [parameter(mandatory=$true)] [regex] $pattern ) foreach ($process in Get-WmiObject Win32_Process | where { $_.Name -match $pattern }) { if ($PSCmdlet.ShouldProcess( "process $($process.Name) " + " (id: $($process.ProcessId))" , "Stop Process")) { $process.Terminate() } }}
A long one-line code.
After formatting it, I get this :
function Stop-ProcessUsingWMI {
[CmdletBinding(SupportsShouldProcess = $True)] param( [parameter(mandatory = $true)] [regex] $pattern ) foreach ($process in Get-WmiObject Win32_Process | Where-Object { $_.Name -match $pattern }) {
if ($PSCmdlet.ShouldProcess( "process $($process.Name) " + " (id: $($process.ProcessId))" , 'Stop Process')) {
$process.Terminate()
}
}
}
It is better but far from what one could expect from a well formatted code. There are multiple spaces everywhere and function body is not standard. Here is what I would expect :
function Stop-ProcessUsingWMI {
[CmdletBinding(SupportsShouldProcess = $True)]
param(
[parameter(mandatory = $true)] [regex] $pattern
)
foreach ($process in Get-WmiObject Win32_Process | Where-Object { $_.Name -match $pattern }) {
if ($PSCmdlet.ShouldProcess( "process $($process.Name) " + " (id: $($process.ProcessId))" , 'Stop Process')) {
$process.Terminate()
}
}
}
| System | Version |
|---|---|
| OS | Win 10 x64 pro (french) 19043.1165 |
| VS Code version | 1.59.1 |
| Extension version | v2021.8.0 |
| Powershell | 7.1.4 |
PS extension custom settings :
"powershell.buttons.showPanelMovementButtons": true,
"powershell.codeFormatting.autoCorrectAliases": true,
"powershell.codeFormatting.preset": "OTBS",
"powershell.codeFormatting.trimWhitespaceAroundPipe": true,
"powershell.codeFormatting.useCorrectCasing": true,
"powershell.integratedConsole.focusConsoleOnExecute": false,
"powershell.codeFormatting.useConstantStrings": true,
"security.workspace.trust.untrustedFiles": "open",
"editor.suggest.preview": true,
"powershell.codeFormatting.ignoreOneLineBlock": false,
"powershell.codeFormatting.whitespaceBetweenParameters": true
Proposed Design
- remove multiple spaces when not needed
- format function body, list of parameters and attributes on their respected line.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された PowerShell 関数と一覧にある PSScriptAnalyzer 設定を使用して、issue のフォーマット結果を再現します。出力を期待される例と比較し、その後、空白、関数本体、パラメーター、属性を処理するフォーマッターの動作を追跡します。不要なスペースの繰り返しなしに、形式の崩れた 1 行のドキュメントが期待される例のようにフォーマットされれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- csharp, powershell
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100