PowerShell / PowerShell/PSScriptAnalyzer

Remove-Module PSScriptAnalyzer leaves behavior of removed module version

Đang mở
#722 7 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 - Discussion
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ả

Removing a version of PSScriptAnalyzer does not remove its behavior from the session. I don't know much about this, but it looks like we're missing code to clean up after a remove.

Version 1.10.0 and 1.11.0 are somewhat different. For example, in 1.11.0, the Settings parameter tab-completes the .psd1 file names in the Settings subdirectory. Also, the PSPlaceOpenBrace and PSPlaceCloseBrace rules do not trigger on a one-line function, such as:

function Test-Brace1 () {"Hello, World"}

However, if you import one version (Import-Module), remove that version (Remove-Module), and then import the other version, the result is the same as if you imported only the first version.

This is important, because the results of the different module versions are perceptibly different.

REPRO:

0. Start a new session, e.g. new console. 
1. ipmo PSScriptAnalyzer -RequiredVersion 1.10.0 -Passthru
2. gmo | rmo
3. ipmo PSScriptAnalyzer -RequiredVersion 1.11.0 -Passthru 

Now, test one of the differing features.

4. Invoke-ScriptAnalyzer -Settings <TAB>    #Fails to tab complete, as in 1.10.0.
5. Invoke-ScriptAnalyzer -ScriptDefinition 'function Test-Brace1 () {"Hello, World"}' -Settings $home\Documents\WindowsPowerShell\Modules\PSScriptAnalyzer\1.11.0\Settings\CodeFormatting.psd1

This returns output that you shouldn't see any more in 1.11.0.

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSPlaceOpenBrace                    Warning                 1     There is no new line after open brace.
PSPlaceCloseBrace                   Warning                 1     Close brace is not on a new line.

The same is true if you reverse the order of the versions.

0. Start a new session, e.g. new console. 
1. ipmo PSScriptAnalyzer -RequiredVersion 1.11.0 -Passthru
2. gmo | rmo
3. ipmo PSScriptAnalyzer -RequiredVersion 1.10.0 -Passthru 

Now, we have 1.10.0 with 1.11.0 behavior:

4. Invoke-ScriptAnalyzer -Settings <TAB>    #Tab completes!
5. Invoke-ScriptAnalyzer -ScriptDefinition 'function Test-Brace1 () {"Hello, World"}' -Settings CodeFormatting

Version 1.10.0 should error on the one-liner, but it doesn't.

PS C:\> Invoke-ScriptAnalyzer -Settings CodeFormatting -ScriptDefinition 'function Test-Brace1 () {"Hello, World"}'
PS C:\>

Strange, I know. If you need more info, let me know. Thanks!

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 với chuỗi Import-Module và Remove-Module trong bản tái hiện, sau đó kiểm tra hành vi của Invoke-ScriptAnalyzer sau khi chuyển đổi giữa PSScriptAnalyzer 1.10.0 và 1.11.0. So sánh tính năng hoàn tất bằng phím Tab cho các thiết đặt và kết quả của PSPlaceOpenBrace và PSPlaceCloseBrace; hoàn tất khi việc gỡ bỏ một phiên bản không còn để lại hành vi của phiên bản đó trong phiên làm việ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ệ
csharp, 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
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.