PowerShell / PowerShell/PSScriptAnalyzer

`Invoke-Formatter -Range` silently drops corrections after earlier fixes shift text

Abierto
#2,211 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
C#
Estrellas
2.2k
Forks
414
Merge medio
13 h 1 min
PR fusionados (30 d)
2

Descripción

Steps to reproduce

Format only the second line, with the range covering the complete statement:

Invoke-Formatter -ScriptDefinition "if(`$a){'x'}`nif(`$b){'y'}" -Range @(2, 1, 2, 12)

Expected behavior

Every formatting correction within the selected statement should be applied:

if($a){'x'}
if ($b) { 'y' }

Actual behavior

The space before the final } is missing:

if($a){'x'}
if ($b) { 'y'}

The formatter applies fixes iteratively. Earlier corrections make the selected line longer, but later violations are still filtered against the original fixed range coordinates. Once a correction shifts beyond the original range end, it is silently dropped even though it belongs to the statement selected by the caller.

Expected resolution

Track the range through applied edits, or filter corrections once against their original extents, so that a range covering a complete statement formats that statement completely.

Environment data

Reproduced with:

  • PSScriptAnalyzer 1.25.0 on PowerShell 7.5.2
  • PSScriptAnalyzer built from main at PowerShell/PSScriptAnalyzer@4b0117ca7d2887711c9699f467ba7171f8859156 on PowerShell 7.6.4

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con el punto de entrada Invoke-Formatter -Range y reproduce el comando proporcionado en las versiones indicadas de PSScriptAnalyzer. Sigue cómo se filtran las correcciones iterativas de formato según el rango seleccionado y, después, verifica que se aplique cada corrección dentro de la instrucción completa, incluido el espacio final antes de }.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
powershell
Área
tooling
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Activo
Claridad
Bastante claro
Aptitud para principiantes
68/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.