PowerShell / PowerShell/PSScriptAnalyzer
PSUseDeclaredVarsMoreThanAssignments is not aware of the scriptblock context (invocation or dot-sourcing)
Abierto
Nadie ha tomado este issue todavía.
Area - PSUseDeclaredVarsMoreThanAssignments
Area - Rules
- Lenguaje dominante
- C#
- Estrellas
- 2.2k
- Forks
- 414
- Merge medio
- 13 h 1 min
- PR fusionados (30 d)
- 2
Descripción
Steps to reproduce
Extracted from here but similar issues also reported in #711
It’s a PSSA bug. I get the same warning with:
$totalSize = 0
. { $totalSize += 1 }
$totalSize
PSSA is apparently analyzing each script block independently.
It needs to recognize when a script block is dot sourced and analyze it in the context of where it is >invoked. This isn’t always possible, but it’s usually easy to do when using ForEach-Object (which dot >sources like this).
In trying some variants on the idea, it seems like there are multiple bugs:
$totalSize = 0
function foo {
$x = $totalSize + 1
$totalSize = $x # Should warn, doesn't (bug)
}
& {
$x = $totalSize + 1
$totalSize = $x # Should warn, doesn't (bug)
}
. {
$x = $totalSize + 1
$totalSize = $x # Should not warn, doesn't (no bug)
}
. {
$totalSize += 1 # Should not warn, does (bug)
}
$totalSize
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con la implementación de PSUseDeclaredVarsMoreThanAssignments y reproduce los ejemplos de invocación, dot-sourcing, función y scriptblock incluidos en el issue. Compara cada diagnóstico con el comportamiento esperado descrito en los comentarios; se considera terminado cuando el analizador maneja estos contextos sin falsos positivos ni advertencias omitidas.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- csharp, powershell
- Área
- tooling
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100