PowerShell / PowerShell/PSScriptAnalyzer

preferences file does not support $env: variables

Đang mở
#2,126 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.

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ả

Expected behavior

# # PSScriptAnalyzerSettings.psd1
# @{
#    CustomRulePath = "rules.psm1"
# }
Invoke-ScriptAnalyzer -Path .\test.ps1 -Settings ./PSScriptAnalyzerSettings.psd1

outputs: (correct)

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSAvoidInvokeSomething              Warning      test.ps1   1     The command 'Invoke-Something' should not be used. Please
                                                                  use 'Invoke-SomethingElse' instead

Actual behavior

# # PSScriptAnalyzerSettings.psd1
# @{
#    CustomRulePath = "$PSScriptRoot/rules.psm1"
# }
Invoke-ScriptAnalyzer -Path .\test.ps1 -Settings ./PSScriptAnalyzerSettings.psd1

Outputs:

Invoke-ScriptAnalyzer: Value in the settings hashtable should be a string or an array of strings: line 2 column 22 in file [...]\Powershell\PSScriptAnalyzerSettings.psd1

Reasoning

according to this article,

Module manifests are loaded in RestrictedLanguage mode and may use these additional variables:
$PSScriptRoot
$PSEdition
$EnabledExperimentalFeatures
Any environment variable, like $env:TEMP

relative file paths CustomRulePath for my environment
were resolving relative to the cwd instead of relative to the settings.file in neovim. the
./rules.psm1 and rules.psm1 were not resolving correctly.

~/.../Powershell/PSScriptAnalyzerSettings.psd1
where '~' expands to HOMEDIR does work

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      7.5.2
PSEdition                      Core
GitCommitId                    7.5.2
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.24.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

Tái hiện sự cố với PSScriptAnalyzerSettings.psd1 và Invoke-ScriptAnalyzer bằng cả CustomRulePath đơn giản lẫn biểu thức $env: hoặc $PSScriptRoot. Theo dõi cách tệp cài đặt được phân tích cú pháp và cách CustomRulePath được phân giải; hoàn tất khi các giá trị biến môi trường được hỗ trợ được chấp nhận mà không gặp lỗi xác thực hashtable và lệnh được ghi trong tài liệu 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
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.