Skip to content
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

Allow Invoke-ScriptAnalyzer to take in piped paths or FileInfos #1132

Closed
kitforbes opened this issue Jan 21, 2019 · 8 comments
Closed

Allow Invoke-ScriptAnalyzer to take in piped paths or FileInfos #1132

kitforbes opened this issue Jan 21, 2019 · 8 comments
Assignees

Comments

@kitforbes
Copy link

Summary of the new feature

As a user I would like to add the -Exclude parameter to Invoke-ScriptAnalyzer so that I can ignore certain directories from analysis.

In my case, I want to test all of my ps1 files, except those within a vendor directory, as these come from a third party. With Get-ChildItem, I can achieve this with

Get-ChildItem -Path "$PSScriptRoot" -Filter "*.ps1" -Recurse -Exclude "$PSScriptRoot\vendor"

I would expect Invoke-ScriptAnalyzer to have a similar implementation:

Invoke-ScriptAnalyzer -Path "$PSScriptRoot" -Recurse -Exclude "$PSScriptRoot\vendor"

What is the latest version of PSScriptAnalyzer at the point of writing

1.17.1

@bergmeister
Copy link
Collaborator

bergmeister commented Jan 21, 2019

The philosophy of PowerShell or Unix shells is that each command does one job and does it well. Invoke-scriptanalyzer already has a lot of parameters, piping the result of get-childitem does the job as you say and does not make the code more complicated or less readable. Compare this to other cmdlets like invoke-pester and you will find that they do not offer such options for this reason. I would close this as by design if you agree?

@kitforbes
Copy link
Author

Hi @bergmeister, thanks for the quick response. I just tried to pass the results of Get-ChildItem in through the pipeline, but this produces an error.

Get-ChildItem -Recurse | Invoke-ScriptAnalyzer
Invoke-ScriptAnalyzer : Cannot process argument because the value of argument "path" is null. Change the value of argument "path" to a non-null value.
At line:1 char:26
+ Get-ChildItem -Recurse | Invoke-ScriptAnalyzer
+                          ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-ScriptAnalyzer], PSArgumentNullException
    + FullyQualifiedErrorId : ArgumentNull,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeScriptAnalyzerCommand

Looking at the help for the function, the Path parameter does not allow for pipeline input. Is this supposed to be supported?

@bergmeister
Copy link
Collaborator

@kitforbes Yes, you are right, although PSSA declares that it accepts pipeline input and I see tests for it, I can repro your example and it does not work with path strings either. This was maybe a regression that was introduced and somehow not caught by tests.
I will investigate and come back on this because I agree that we definitely need to fix that. For the moment, you could do something like Get-ChildItem | ForEach-Object { Invoke-ScriptAnalyzer -Path $_ } as a workaround

@bergmeister bergmeister self-assigned this Jan 22, 2019
@bergmeister bergmeister changed the title Allow Invoke-ScriptAnalyzer to Exclude directories Allow Invoke-ScriptAnalyzer to take in piped paths or FileInfos (regression) Jan 22, 2019
@kitforbes
Copy link
Author

Thanks @bergmeister.

@bergmeister bergmeister changed the title Allow Invoke-ScriptAnalyzer to take in piped paths or FileInfos (regression) Allow Invoke-ScriptAnalyzer to take in piped paths or FileInfos Jan 23, 2019
@bergmeister
Copy link
Collaborator

@kitforbes I looked into it and yes, this issue exists with the current release 1.17.1 but PR #1040 fixed this already so you can expect this to work in the next release 1.18 (which should hopefully come out soon)

@joerod
Copy link

joerod commented Mar 18, 2019

With the current work around {Invoke-ScriptAnalyzer -Path $_ -Recurse} if -ReportSummary is used you'll get a report for each file instead of the entire directory.

@bergmeister
Copy link
Collaborator

bergmeister commented Mar 19, 2019

This is expected and even with the feature of being able to pipe multiple objects directly to it in the next version this will not change because as far as I am aware the processing of the pipeline is not aware of the whole list being piped to it. If there is a trick to know when the last object is being processed, please let me know.

@felixfbecker
Copy link

@bergmeister can't you add to the report in each process, then output the report in end?

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

4 participants