PowerShell / PowerShell/PSScriptAnalyzer
Invoke-Formatter - Custom rules?
まだ誰も着手していません。
- 主要言語
- C#
- スター
- 2.2k
- フォーク
- 414
- 平均マージ
- 13時間 1分
- マージ済み PR(30日)
- 2
説明
When I run through Invoke-ScriptAnalyzer[1], I find all of my expected violations and I see all of my custom rules running. However, when using the same settings file for Invoke-Formatter[2], it only seems to show one rule running (and not a custom one (PSAvoidUsingCmdletAliases ))
Any ideas what could be causing this? I thought Invoke-Formatter supproted custom rules too, but maybe this is not the case?
Output:
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSAvoidUsingCmdletAliases rule.
VERBOSE: Found 0 violations.
VERBOSE: Fixed 0 violations.
Notes:
PSScriptAnalyzer 1.21.0
Tested on both PowerShell 5.1 and PowerShell 7.2
Settings file content:
@{
# Use Severity when you want to limit the generated diagnostic records to a
# subset of: Error, Warning and Information.
# Uncomment the following line if you only want Errors and Warnings but
# not Information diagnostic records.
#Severity = @('Error','Warning')
CustomRulePath = 'C:\Users\redacted\Rules\*'
RecurseCustomRulePath = $true
IncludeDefaultRules = $true
# Use IncludeRules when you want to run only a subset of the default rule set.
#IncludeRules = @('PSAvoidDefaultValueSwitchParameter',
# 'PSMissingModuleManifestField',
# 'PSReservedCmdletChar',
# 'PSReservedParams',
# 'PSShouldProcess',
# 'PSUseApprovedVerbs',
# 'PSUseDeclaredVarsMoreThanAssigments')
# Use ExcludeRules when you want to run most of the default set of rules except
# for a few rules you wish to "exclude". Note: if a rule is in both IncludeRules
# and ExcludeRules, the rule will be excluded.
ExcludeRules = @(
'UseJSModuleImports',
'PSAvoidUsingWriteHost',
'PSUseShouldProcessForStateChangingFunctions',
'PSUseOutputTypeCorrectly'
#, 'PSAvoidGlobalVars'
)
# You can use the following entry to supply parameters to rules that take parameters.
# For instance, the PSAvoidUsingCmdletAliases rule takes a whitelist for aliases you
# want to allow.
Rules = @{
# Do not flag 'cd' alias.
PSAvoidUsingCmdletAliases = @{
Whitelist = @(
'cd',
'compare',
'foreach',
'group',
'measure',
'select',
'sort',
'tee',
'where'
)
}
# Alert for line length
PSAvoidLongLines = @{
Enable = $true
MaximumLineLength = 115
}
# Check if your script uses cmdlets that are compatible on PowerShell Core, version 6.0.0-alpha, on Linux.
# PSUseCompatibleCmdlets = @{Compatibility = @("core-6.0.0-alpha-linux")}
}
}
[1]
Invoke-ScriptAnalyzer -ScriptDefinition (Get-Content -Raw -Path C:\Temp\test.ps1) -Verbose -Settings "$rootPath\PSScriptAnalyzerSettings.psd1"
[2]
Invoke-Formatter -ScriptDefinition (Get-Content -Raw -Path C:\Temp\test.ps1) -Verbose -Settings "$rootPath\PSScriptAnalyzerSettings.psd1"
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、PSScriptAnalyzerSettings.psd1 を使用して C:\Temp\test.ps1 に対して 2 つのコマンドを再現し、詳細なルール検出とフォーマット出力を比較します。レポートで言及されている Invoke-ScriptAnalyzer と Invoke-Formatter のエントリポイントを追跡します。Invoke-Formatter がカスタム ルールをサポートしているかどうかを確定し、観測された動作を文書化または修正できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- powershell
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 35/100