Skip to content

Settings param cannot be set to $_ inside of a foreach-object loop #807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
thomasrayner opened this issue Aug 1, 2017 · 2 comments
Open

Comments

@thomasrayner
Copy link
Contributor

When the value of the -Settings parameter is set to $_ inside of a foreach-object loop, PSScriptAnalyzer is unable to find the settings file.

Steps to reproduce:
Create a file that violates a rule that is only checked if a particular setting is triggered.
IE:

if ($true)
{
    Write-Output 'Something'
}

This code will throw errors if -Settings is set to CodeFormattingStroustrup but not if -Settings it is omitted.

The following command returns warnings.
invoke-scriptanalyzer -path C:\files\ax.ps1 -Settings 'CodeFormattingStroustrup'
But this one does not.
'CodeFormattingStroustrup' | % { invoke-scriptanalyzer -path C:\files\ax.ps1 -Settings $_ }

Using -Verbose on the non-working example shows that PSScriptAnalyzer cannot find a settings file.

This occurs on version 1.15.0 of PSScriptAnalyzer.

Screenshot
image

@kapilmb
Copy link

kapilmb commented Aug 1, 2017

Probably something is wrong with the settings parameter processing. The following, however, seems to work as expected:

'CodeFormattingStroustrup' | % { invoke-scriptanalyzer -path C:\files\ax.ps1 -Settings "$_" }

@bergmeister
Copy link
Collaborator

bergmeister commented Mar 11, 2018

@ThmsRynr This still reproes in 1.16.1 and in the latest version of development branch. There have been recent improvements to the -Setting parameter object parsing to allow it parsing expressions that resolve to a string at the end (in BeginProcessing, the object is not a string yet but a PSObject), therefore the improvement also needs to take those built in settings into account as well. I opened a PR with a fix for it, I just need to add a test and then we are ready to go (and hopefully this makes it into the next upcoming version)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants