PowerShell / PowerShell/PSScriptAnalyzer

Ability for script exclusions for PSUseCompatible* rules

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

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

Area - Configuration Consider - 2.0 Issue - Enhancement
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ả

Summary of the new feature

When using PSUseCompatible* rules with target profiles for PSv3, PSSA generates a whole bunch of issues for Pester tests that I have inside of my Script/Module projects. My Dev machine, as well as build machines run latest version of PowerShell, and the tests don't get bundled with my script/modules, hence I don't really care whether they'd run on versions other than latest. It would be really great if I could exclude my Test scripts (by path, by name pattern, or by name) just for these rules, and keep the rest of the rules active.

Proposed technical implementation details (optional)
Introduce an additional configuration setting for PSUseCompatible* rules, i.e. IgnoreScriptPath as follows:

@{
    Rules = @{
        PSUseCompatibleCommands = @{
            Enable = $true
            TargetProfiles = @(...);

            IgnoreScriptPath = @(
                './Tests/', # Ignore any scripts within the Tests sub-folder
                './*.ps1', # Ignore all PowerShell scripts withing the root folder (i.e. build scripts)
                './HelperScripts/SomeHelperScriptForMyBuild.ps1' # Ignore a single helper file
            )
        };

        PSUseCompatibleSyntax = @{
            Enable = $true
            TargetedVersions = @(...)

            IgnoreScriptPath = @(
                './Tests/', # Ignore any scripts within the Tests sub-folder
                './*.ps1', # Ignore all PowerShell scripts withing the root folder (i.e. build scripts)
                './HelperScripts/SomeHelperScriptForMyBuild.ps1' # Ignore a single helper file
            )
        };

        PSUseCompatibleTypes = @{
            Enable = $true
            TargetProfiles = @(...)

            IgnoreScriptPath = @(
                './Tests/', # Ignore any scripts within the Tests sub-folder
                './*.ps1', # Ignore all PowerShell scripts withing the root folder (i.e. build scripts)
                './HelperScripts/SomeHelperScriptForMyBuild.ps1' # Ignore a single helper file
            )
        };

        'PSUseCompatibleCmdlets' = @{
            'compatibility' = @(...)

            'IgnoreScriptPath' = @(
                './Tests/', # Ignore any scripts within the Tests sub-folder
                './*.ps1', # Ignore all PowerShell scripts withing the root folder (i.e. build scripts)
                './HelperScripts/SomeHelperScriptForMyBuild.ps1' # Ignore a single helper file
            )
        }
    }
}

Alternatively, given that the collection of paths to ignore would most likely be identical for all the PSUseCompatible* rules, it might actually be easier to mention it once in a separate place, i.e.:

@{
    Rules = @{
        ...
    }
    'PSUseCompatibleRulesIgnoreScriptPath' = @(
                './Tests/', # Ignore any scripts within the Tests sub-folder
                './*.ps1', # Ignore all PowerShell scripts withing the root folder (i.e. build scripts)
                './HelperScripts/SomeHelperScriptForMyBuild.ps1' # Ignore a single helper file
    )
}

What is the latest version of PSScriptAnalyzer at the point of writing
1.18.3

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ìm cấu hình của các quy tắc PSUseCompatibleCommands, PSUseCompatibleSyntax, PSUseCompatibleTypes và PSUseCompatibleCmdlets cùng các bài kiểm thử hiện có của chúng. So sánh hai thiết lập được đề xuất, sau đó xác minh rằng các script bị loại trừ chỉ vô hiệu hóa các quy tắc tương thích này, trong khi các quy tắc khác vẫn hoạt động.

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
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
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.