PowerShell / PowerShell/PSScriptAnalyzer
formatting partial / dot sourced ps1 dsc scripts
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ả
Steps to reproduce
I originally opened this on the vscode-powershell#1583 project, but I've been directed to open an issue here directly.
I'm currently creating DSC Resource modules to apply settings in our environment, I'm breaking down the actual settings to individual files to make managing the settings easier and to have an easy structure of those settings.
The issue is that the formatter is not performing the align dsc resource / hash table function on the files to import.
It's not really relevant but i'm using the following code in my policy.schema.psm1 file
Configuration Win10CustomComputerPolicy
{
Param(
[Parameter(Mandatory = $false)]
[array]
$excludeImports = @()
)
Import-DscResource -ModuleName PSDesiredStateConfiguration
$importParams = @{
Path = $PSScriptRoot
Exclude = $excludeImports
Filter = '*.ps1'
ErrorAction = 'SilentlyContinue'
Recurse = $true
}
$imports = @(Get-ChildItem @importParams)
#Dot source the files
Foreach ($import in $imports) {
Try {
. $import.fullname
}
Catch {
Write-Error -Message "Failed to import function $($import.fullname): $_"
}
}
}
each individual file then looks like this:
DisableLocalMachineRunOnce.ps1
#\System\Logon\Do not process the run once list
Registry DisableLocalMachineRunOnce {
Ensure = "Present"
Key = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"
Force = $true
ValueName = "DisableLocalMachineRunOnce"
ValueType = "DWord"
ValueData = "1"
}
most of the formatting works, but not the alignment, if I add a configuration section around the code it works, but that would break my import.
#\System\Logon\Do not process the run once list
configuration test {
Registry DisableLocalMachineRunOnce {
Ensure = "Present"
Key = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"
Force = $true
ValueName = "DisableLocalMachineRunOnce"
ValueType = "DWord"
ValueData = "1"
}
}
I can provide a bit more information when I'm back in the office tomorrow if any is needed, but I wanted to make sure I'd opened the issue since I was aware.
Expected behavior
Registry DisableLocalMachineRunOnce {
Ensure = "Present"
Key = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"
Force = $true
ValueName = "DisableLocalMachineRunOnce"
ValueType = "DWord"
ValueData = "1"
}
Actual behavior
Registry DisableLocalMachineRunOnce {
Ensure = "Present"
Key = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"
Force = $true
ValueName = "DisableLocalMachineRunOnce"
ValueType = "DWord"
ValueData = "1"
}
Environment data
| Name | Value |
|---|---|
| PSVersion | 5.1.17134.228 |
| PSEdition | Desktop |
| PSCompatibleVersions | 1.0 2.0 3.0 4.0 5.0 5.1.17134.228 |
| BuildVersion | 10.0.17134.228 |
| CLRVersion | 4.0.30319.42000 |
| WSManStackVersion | 3.0 |
| PSRemotingProtocolVersion | 2.3 |
| SerializationVersion | 1.1.0.1 |
(Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
I'm using PSScriptAnalyzer as part of vscode-powershell using the current version.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Tái hiện hành vi của formatter trong PSScriptAnalyzer với resource độc lập DisableLocalMachineRunOnce.ps1 và so sánh với cùng resource bên trong ví dụ cấu hình được cung cấp. Bắt đầu bằng cách theo dõi cách formatter nhận diện các resource DSC trong các tệp dot-sourced; hoàn tất khi resource độc lập căn chỉnh Ensure và các phép gán khác như trong hành vi mong đợi.
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
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100