PSUseConsistentIndentation flattens the indentation of commented-out code
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 72/100
Direção de pesquisa
Comece localizando a regra PSUseConsistentIndentation e seus testes do formatador; em seguida, reproduza o problema com Invoke-Formatter usando as configurações e a entrada mostradas aqui. Adicione cobertura para código aninhado comentado com indentação de tabulações e espaços e confirme que a indentação relativa antes de # é preservada sem quebrar sequências que contêm código real.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- C#
- Estrelas
- 2.2k
- Forks
- 415
- Merge médio
- 13h 1min
- PRs com merge (30d)
- 2
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de PowerShell/PSScriptAnalyzer
-
Up-for-Grabs
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 78/100
PowerShell/PSScriptAnalyzer#2213 · 2 comentários ·
-
PSUseConsistentIndentation double-indents attribute bodies that open a scriptblock (`[Attr({ … })]`) Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 70/100
PowerShell/PSScriptAnalyzer#2216 · 2 comentários ·
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 68/100
PowerShell/PSScriptAnalyzer#2211 ·
-
`PSPlaceOpenBrace` and `PSPlaceCloseBrace` leave trailing whitespace when expanding one-line blocks Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 70/100
PowerShell/PSScriptAnalyzer#2210 ·
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 55/100
PowerShell/PSScriptAnalyzer#2209 ·
Todas as issues de PowerShell/PSScriptAnalyzer
Issues semelhantes
-
type/automation type/tech-debt
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
-
t/bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
-
ci-failure-cause test-failure
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
-
area:auth FE mvp P3
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
klasolsson81/jobbliggaren#1788 ·