PowerShell / PowerShell/PSScriptAnalyzer

Private parameters are reported as unused

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

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

Issue - Enhancement 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ả

Before submitting a bug report:

  • Make sure you are able to repro it on the latest released version
  • Perform a quick search for existing issues to check if this bug has already been reported

Steps to reproduce

Run the analyzer against this script.

Param (
    [String] $private:var1
)

function Test-Second
{
    # $var1 is not accessible because it was private to the script.
    Write-Information -InformationAction "continue" "From script: $var1"

    # $var2 is not private to the calling function so we can access it.
    Write-Information -InformationAction "continue" "From caller: $var2"
}

function Test-NotGlobal
{
    Param (
        [String] $var2
    )
    $a = $var1 + " " + $var2
    Write-Information -InformationAction "continue" "Concatenation: $a"
    Test-Second
}

Test-NotGlobal $var1

Expected behavior

Expect no errors because $private:var1 and the use in the last line of $var1 are the same variable and $var1 is private to the script, as required.


Actual behavior

PS C:\Users\pauldsmith> Invoke-ScriptAnalyzer c:\temp\gvar.ps1

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSReviewUnusedParameter             Warning      gvar.ps1   2     The parameter 'private:var1' has been declared but not
                                                                  used.


PS C:\Users\pauldsmith>

If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.22621.963
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22621.963
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }

1.21.0

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 chạy Invoke-ScriptAnalyzer trên bản tái hiện bằng PowerShell và kiểm tra phần triển khai cũng như độ bao phủ của quy tắc PSReviewUnusedParameter. Xác nhận rằng tham số private và lần sử dụng cuối cùng của nó được nhận diện là cùng một biến; hoàn tất khi bản tái hiện không tạo ra cảnh báo tham số không được sử dụ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
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 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
45/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.