PowerShell / PowerShell/PSScriptAnalyzer
False Positive: Variable Reference Error for Colon After Variable in Double-Quoted Strings (Format Operator and Concatenation)
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
Before submitting a bug report:
- I have reproduced this on the latest released version of PSScriptAnalyzer and VS Code PowerShell extension.
- I have searched for existing issues and did not find this bug reported.
Steps to reproduce
$errorMsg = 'Some error details'
$feature = 'EnablePlacesWebApp'
# Using format operator
Write-Log -Message ('Failed to enable {0}: {1}' -f $feature, $errorMsg) -Level 'ERROR'
Write-Host ("`n❌ Failed to enable {0}: {1}" -f $feature, $errorMsg) -ForegroundColor Red
# Using string concatenation
Write-Log -Message ('Failed to enable ' + $feature + ': ' + $errorMsg) -Level 'ERROR'
Write-Host ("`n❌ Failed to enable " + $feature + ": " + $errorMsg) -ForegroundColor Red
Expected behavior
No error or warning should be reported by PSScriptAnalyzer for valid PowerShell syntax using the format operator or string concatenation, regardless of the character following the variable.
Actual behavior
PSScriptAnalyzer reports:
Variable reference is not valid. ':' was not followed by a valid variable name character. Consider using ${} to delimit the name.
This occurs even when using the format operator (-f) or string concatenation, which are valid and idiomatic PowerShell.
If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *
No unexpected error thrown; this is a linter false positive.
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 7.3.6
PSEdition Core
GitCommitId 7.3.6
OS Microsoft Windows 10.0.19045
Platform Win32NT
...
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
2.10.0
Additional context:
This issue also appears in the VS Code PowerShell extension, which integrates PSScriptAnalyzer for diagnostics. Please coordinate with the extension maintainers if needed.
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 reproduciendo el diagnóstico con los ejemplos del operador de formato y la concatenación de cadenas del issue, usando PSScriptAnalyzer 2.10.0 y el entorno de PowerShell indicado. Rastrea el punto de entrada del analizador que informa del error de referencia de variable; se considera terminado cuando ambas formas válidas no producen ningún diagnóstico, incluidos los casos con dos puntos mostrados.
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