PowerShell / PowerShell/PSScriptAnalyzer
False Positive: Variable Reference Error for Colon After Variable in Double-Quoted Strings (Format Operator and Concatenation)
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.2k
- Forks
- 414
- Avg merge
- 13h 1m
- Merged PRs (30d)
- 2
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the diagnostic with the format-operator and string-concatenation examples in the issue, using PSScriptAnalyzer 2.10.0 and the reported PowerShell environment. Trace the analyzer entry point that reports the variable-reference error; done means both valid forms produce no diagnostic, including the colon cases shown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, powershell
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100