Skip to content

PSScriptAnalyzerSettings.psd1 not Used Implicitly when used together with *. for -Path parameter #978

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

Closed
alx9r opened this issue Apr 25, 2018 · 2 comments · Fixed by #979

Comments

@alx9r
Copy link

alx9r commented Apr 25, 2018

In #975(comment) @bergmeister wrote the following:

...and if you name it PSScriptAnalyzerSettings.psd1 then those settings get applied implicitly if you run Invoke-ScriptAnalyzer from the root without having to specify the -Settings parameter...

Steps to reproduce

  1. Extract the zip PssaVscode.zip with full paths.
  2. Set PowerShell's location to the folder containing PSScriptAnalyzerSettings.psd1.
  3. Invoke Invoke-ScriptAnalyzer *.

Expected behavior

No output as an indication of no errors.

Actual behavior

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSAvoidUsingCmdletAliases           Warning      PssaVscode 2     '%' is an alias of
                                                 .psm1            'ForEach-Object'. Alias can
                                                                  introduce possible problems and
                                                                  make scripts hard to maintain.
                                                                  Please consider changing alias
                                                                  to its full content.

Environment data

> $PSVersionTable

Name                           Value                                                              
----                           -----                                                              
PSVersion                      5.1.14409.1012                                                     
PSEdition                      Desktop                                                            
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                            
BuildVersion                   10.0.14409.1012                                                    
CLRVersion                     4.0.30319.42000                                                    
WSManStackVersion              3.0                                                                
PSRemotingProtocolVersion      2.3                                                                
SerializationVersion           1.1.0.1                                                            

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.16.1
1.16.1
@bergmeister
Copy link
Collaborator

bergmeister commented Apr 25, 2018

@alx9r This seems to be a problem with the wildcard *.that you provided because it does not match any file and the way how the algorithm works here is that the fallback to PSScriptAnalyzerSettings.psd1 happens only if there is at least one path/file to analyze.
Therefore just use . or *.* to actually analyse files:

Invoke-ScriptAnalyzer . -Verbose
VERBOSE: Settings not provided. Will look for settings file in the given path .
VERBOSE: Found C:\Users\cberg\Downloads\PssaVscode\PssaVscode\PSScriptAnalyzerSettings.psd1. Will use it to provide
settings for this invocation.
....

I will keep this issue open though as you found a special case where the error message is slightly misleading.

@bergmeister bergmeister changed the title PSScriptAnalyzerSettings.psd1 not Used Implicitly PSScriptAnalyzerSettings.psd1 not Used Implicitly when used together with *. for -Path parameter Apr 25, 2018
@alx9r
Copy link
Author

alx9r commented Apr 25, 2018

Thanks for looking into this @bergmeister. The reason I expected * to work is because the help for the -Path parameter includes the following statement:

To analyze files that are not in the root directory of the specified path, use a wildcard character (C:\Modules\MyModule*) or the Recurse parameter.

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