PowerShell / PowerShell/PSScriptAnalyzer

Invoke-Formatter - Custom rules?

Đang mở
#1,957 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Needs-Investigation Up-for-Grabs
Ngôn ngữ chính
C#
Star
2.2k
Fork
414
Merge trung bình
13 giờ 1 phút
Pull request đã merge (30 ngày)
2

Mô tả

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"

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện hai lệnh trên C:\Temp\test.ps1 với PSScriptAnalyzerSettings.psd1, đồng thời so sánh việc phát hiện quy tắc chi tiết và đầu ra định dạng. Truy vết các entry point Invoke-ScriptAnalyzer và Invoke-Formatter được đề cập trong báo cáo. Công việc được xem là hoàn tất khi xác định được liệu Invoke-Formatter có hỗ trợ các quy tắc tùy chỉnh hay không, đồng thời ghi lại hoặc sửa hành vi quan sát được.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
powershell
Lĩnh vực
tooling
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.