PSUseConsistentIndentation flattens the indentation of commented-out code
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
- 72/100
Hướng nghiên cứu
Bắt đầu bằng cách tìm rule PSUseConsistentIndentation và các bài kiểm thử formatter của nó, sau đó tái hiện vấn đề bằng Invoke-Formatter với các thiết lập và đầu vào được hiển thị ở đây. Bổ sung coverage cho mã đã bị comment lồng nhau với cả indentation bằng tab và space, đồng thời xác nhận rằng indentation tương đối trước # được giữ nguyên mà không làm hỏng các đoạn chứa mã thực.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
PSUseConsistentIndentation rewrites the whitespace before each comment's #, aligning every comment line in a block to the block indentation. When a run of comments is commented-out code (where the nested structure is expressed by the indentation before #), the rule flattens it, so the structure is lost. Whitespace after the # is preserved, so the two styles behave differently:
# preserved - the extra indentation is after the '#'
# if ($b) {
# doThing
# }
# flattened - the extra indentation is before the '#'
# if ($b) {
# doThing
# }
Steps to reproduce
Only the one rule is enabled:
$settings = @{
IncludeRules = @('PSUseConsistentIndentation')
Rules = @{
PSUseConsistentIndentation = @{ Enable = $true; IndentationSize = 4; PipelineIndentation = 'NoIndentation'; Kind = 'tab' }
}
}
Input:
if ($a) {
# if ($b) {
# doThing
# }
}
Actual (Invoke-Formatter -ScriptDefinition $code -Settings $settings):
if ($a) {
# if ($b) {
# doThing
# }
}
Expected: the commented-out block keeps its relative indentation (at most the whole comment run may be shifted to the code indentation).
The same happens with Kind = 'space' and when there is real code after the comment run.
Environment
- PSScriptAnalyzer 1.25.0
- PowerShell 7.6.6 on Windows
Why it matters
Commenting out a block is a common way to keep code around; flattening the indentation makes the commented-out block unreadable. Tooling that encodes directives as comments (e.g. sources that are uncommented by an external preprocessor) also relies on the indentation before # being preserved.
Related: #2151 asks for an ignore-range directive, but this is about the default behaviour of the indentation rule on ordinary comment runs.
- 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
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.
Issue khác của PowerShell/PSScriptAnalyzer
-
Up-for-Grabs
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 78/100
PowerShell/PSScriptAnalyzer#2213 · 2 bình luận ·
-
PSUseConsistentIndentation double-indents attribute bodies that open a scriptblock (`[Attr({ … })]`) Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 70/100
PowerShell/PSScriptAnalyzer#2216 · 2 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
PowerShell/PSScriptAnalyzer#2211 ·
-
`PSPlaceOpenBrace` and `PSPlaceCloseBrace` leave trailing whitespace when expanding one-line blocks Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 70/100
PowerShell/PSScriptAnalyzer#2210 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
PowerShell/PSScriptAnalyzer#2209 ·
Tất cả issue của PowerShell/PSScriptAnalyzer
Issue tương tự
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
sillsdev/languageforge-lexbox#2665 ·
-
bug documentation frontend
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
azurenoops/spin_agent#975 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
SubtitleEdit/subtitleedit#15108 · 1 bình luận ·