PSUseConsistentIndentation not respected for pipeline chain operators.

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

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
csharp, powershell
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện ví dụ với Invoke-Formatter và các cài đặt PSUseConsistentIndentation được hiển thị trong issue, đồng thời so sánh các toán tử pipeline thông thường với các toán tử chuỗi pipeline. Theo dõi đường dẫn của formatter xử lý việc tiếp tục dòng tự nhiên và xác nhận rằng đầu ra khớp với mức thụt lề bốn dấu cách như mong đợi cho các lệnh được nối chuỗi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

When using natural line continuation with IncreaseIndentationForFirstPipeline (or IncreaseIndentationAfterEveryPipeline) enabled and pipeline chain operators, it does not format as expected like with regular pipeline operators.

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

$scriptDefinition = @'
Get-Item "C:\someItem" &&
Get-Item "C:\someItem" &&
Get-Item "C:\someItem"
'@

$settings = @{
    IncludeRules = @("PSUseConsistentIndentation")
    Rules = @{
        PSUseConsistentIndentation = @{
            Enable              = $true
            IndentationSize     = 4
            PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
            Kind                = 'space'
        }
    }
}

Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings
Get-Item "C:\someItem" &&
Get-Item "C:\someItem" &&
Get-Item "C:\someItem"

Expected behavior

$scriptDefinition = @'
Get-Item "C:\someItem" &&
Get-Item "C:\someItem" &&
Get-Item "C:\someItem"
'@

$settings = @{
    IncludeRules = @("PSUseConsistentIndentation")
    Rules = @{
        PSUseConsistentIndentation = @{
            Enable              = $true
            IndentationSize     = 4
            PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
            Kind                = 'space'
        }
    }
}

Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings
Get-Item "C:\someItem" &&
    Get-Item "C:\someItem" &&
    Get-Item "C:\someItem"

Actual behavior

$scriptDefinition = @'
Get-Item "C:\someItem" &&
Get-Item "C:\someItem" &&
Get-Item "C:\someItem"
'@

$settings = @{
    IncludeRules = @("PSUseConsistentIndentation")
    Rules = @{
        PSUseConsistentIndentation = @{
            Enable              = $true
            IndentationSize     = 4
            PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
            Kind                = 'space'
        }
    }
}

Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings
Get-Item "C:\someItem" &&
Get-Item "C:\someItem" &&
Get-Item "C:\someItem"

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                      7.4.11
PSEdition                      Core
GitCommitId                    7.4.11
OS                             Microsoft Windows 10.0.19045
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
1.22.0
Ngôn ngữ chính
C#
Star
2.2k
Fork
415
Merge trung bình
13 giờ 1 phút
Pull request đã merge (30 ngày)
2

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.

Issue khác của PowerShell/PSScriptAnalyzer

Tất cả issue của PowerShell/PSScriptAnalyzer

Issue tương tự

Thêm issue về C#

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.