Skip to content

Settings file cannot be found in a special case when specifying -Setting parameter object in a certain way #914

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
bergmeister opened this issue Feb 28, 2018 · 1 comment · Fixed by #915
Assignees

Comments

@bergmeister
Copy link
Collaborator

bergmeister commented Feb 28, 2018

Steps to reproduce

This was reported in the UK PowerShell Slack user group get-psuguk by @pauby
This bug was initially reported for version 1.16.1 but even with the recent PR 909 that was merged today, this strange behaviour happens.

cd $PSScriptAnalyzerCheckout
Invoke-ScriptAnalyzer -ScriptDefinition gci -Settings (join-path ((get-location).path) 'Engine\Settings\ScriptingStyle.psd1') -Verbose

Expected behavior

No warning and only the 2 rules in the settings file are being used.

VERBOSE: Using settings file at C:\Users\cberg\git\PSScriptAnalyzer\Engine\Settings\ScriptingStyle.psd1.
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSAvoidUsingWriteHost rule.
VERBOSE: Running PSProvideCommentHelp rule.

Actual behavior

The settings file is ignored and all rules are being applied

VERBOSE: Cannot find a settings file.
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSAvoidAssignmentToAutomaticVariable rule.
VERBOSE: Running PSAvoidUsingCmdletAliases rule.
VERBOSE: Running PSAvoidDefaultValueSwitchParameter rule.
VERBOSE: Running PSAvoidUsingEmptyCatchBlock rule.
VERBOSE: Running PSAvoidGlobalAliases rule.
VERBOSE: Running PSAvoidGlobalFunctions rule.
VERBOSE: Running PSAvoidGlobalVars rule.
VERBOSE: Running PSAvoidInvokingEmptyMembers rule.
VERBOSE: Running PSAvoidNullOrEmptyHelpMessageAttribute rule.
VERBOSE: Running PSAvoidDefaultValueForMandatoryParameter rule.
VERBOSE: Running PSReservedCmdletChar rule.
VERBOSE: Running PSAvoidUsingPositionalParameters rule.
VERBOSE: Running PSAvoidShouldContinueWithoutForce rule.
VERBOSE: Running PSAvoidTrailingWhitespace rule.
VERBOSE: Running PSAvoidUsingUserNameAndPassWordParams rule.
VERBOSE: Running PSAvoidUsingComputerNameHardcoded rule.
VERBOSE: Running PSAvoidUsingConvertToSecureStringWithPlainText rule.
VERBOSE: Running PSAvoidUsingDeprecatedManifestFields rule.
VERBOSE: Running PSAvoidUsingInvokeExpression rule.
VERBOSE: Running PSAvoidUsingPlainTextForPassword rule.
VERBOSE: Running PSAvoidUsingWMICmdlet rule.
VERBOSE: Running PSAvoidUsingWriteHost rule.
VERBOSE: Running PSMisleadingBacktick rule.
VERBOSE: Running PSMissingModuleManifestField rule.
VERBOSE: Running PSPossibleIncorrectComparisonWithNull rule.
VERBOSE: Running PSPossibleIncorrectUsageOfAssignmentOperator rule.
VERBOSE: Running PSReservedParams rule.
VERBOSE: Running PSProvideCommentHelp rule.
VERBOSE: Running PSUseBOMForUnicodeEncodedFile rule.
VERBOSE: Running PSUseCmdletCorrectly rule.
VERBOSE: Running PSUseCompatibleCmdlets rule.
VERBOSE: Running PSUseDeclaredVarsMoreThanAssignments rule.
VERBOSE: Running PSUseLiteralInitializerForHashtable rule.
VERBOSE: Running PSUseOutputTypeCorrectly rule.
VERBOSE: Running PSUseApprovedVerbs rule.
VERBOSE: Running PSUsePSCredentialType rule.
VERBOSE: Running PSUseShouldProcessForStateChangingFunctions rule.
VERBOSE: Running PSUseSingularNouns rule.
VERBOSE: Running PSUseSupportsShouldProcess rule.
VERBOSE: Running PSUseToExportFieldsInManifest rule.
VERBOSE: Running PSUseUTF8EncodingForHelpFile rule.
VERBOSE: Running PSShouldProcess rule.

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSAvoidUsingCmdletAliases           Warning                 1     'gci' is an alias of 'Get-ChildItem'. 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.16299.248
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.248
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Name                           Value
----                           -----
PSVersion                      6.0.1
PSEdition                      Core
GitCommitId                    v6.0.1
OS                             Microsoft Windows 10.0.16299
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.16.1 # Happens also using  latest code at hash d4ba9470fa5677ea95266b8334ebaf8681650b6c

Remarks

What is weird is the fact that this does not happen if the object being passed to the cmdlet is specified as a string "$((join-path ((get-location).path) 'Engine\Settings\ScriptingStyle.psd1'))". This is weird because the object is already a string and when assigning the object to a variable and doing an equal comparison to its literal string, then it reports true...

@bergmeister bergmeister self-assigned this Feb 28, 2018
@bergmeister bergmeister changed the title SettingsFile cannot be found in a special case when specifying -Setting parameter object in a certain way Settings file cannot be found in a special case when specifying -Setting parameter object in a certain way Feb 28, 2018
@bergmeister
Copy link
Collaborator Author

A quick investigation shows that this might be a quirk/artifact of PowerShell's parser because in the BeginProcessing() part, the object does not seem to get fully resolved and is therefore not a string yet. Maybe we need to try to convert the expression to a string as a last resort...

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