PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items/ms-vscode.PowerShell
MIT License
1.7k stars 490 forks source link

Using module incorrectly marked as wrong? #1599

Closed PrzemyslawKlys closed 2 years ago

PrzemyslawKlys commented 5 years ago

System Details

System Details Output

### VSCode version: 1.28.2 7f3ce96ff4729c91352ae6def877e59c561f4850 x64

### VSCode extensions:
aaron-bond.better-comments@2.0.2
abusaidm.html-snippets@0.2.1
AlanWalk.markdown-toc@1.5.6
alefragnani.Bookmarks@9.1.0
azemoh.one-monokai@0.3.7
ban.spellright@3.0.6
batisteo.vscode-django@0.17.0
bierner.markdown-preview-github-styles@0.1.4
DavidAnson.vscode-markdownlint@0.21.0
DavidWang.ini-for-vscode@0.0.4
donjayamanne.githistory@0.4.3
donjayamanne.jupyter@1.1.4
donjayamanne.python-extension-pack@1.4.0
DotJoshJohnson.xml@2.3.2
eamodio.gitlens@8.5.6
emilast.LogFileHighlighter@2.4.2
emmanuelbeziat.vscode-great-icons@2.1.44
Equinusocio.vsc-material-theme@2.5.1
felixfbecker.php-debug@1.12.6
formulahendry.code-runner@0.9.5
gerane.Theme-dimmed-monokai@0.0.2
gharveymn.nightswitch@1.1.0
GitHub.vscode-pull-request-github@0.2.3
GlenBuktenica.unicode-substitutions@2.0.0
GrapeCity.gc-excelviewer@2.1.26
hdg.live-html-previewer@0.3.0
hnw.vscode-auto-open-markdown-preview@0.0.4
HookyQR.beautify@1.4.7
IBM.output-colorizer@0.1.2
ikappas.phpcs@1.0.5
ionutvmi.reg@0.0.2
JerryHong.autofilename@0.1.3
joaompinto.asciidoctor-vscode@0.15.1
johnpapa.winteriscoming@0.8.0
Kelvin.vscode-sshfs@1.11.1
kisstkondoros.vscode-codemetrics@1.17.3
KnisterPeter.vscode-github@0.30.0
magicstack.MagicPython@1.1.0
mariorodeghiero.vue-theme@1.1.1
mechatroner.rainbow-csv@0.7.1
mkloubert.vs-deploy@14.0.0
mkloubert.vscode-remote-workspace@0.37.0
ms-mssql.mssql@1.4.0
ms-python.python@2018.9.2
ms-vscode.csharp@1.17.0
ms-vscode.PowerShell@1.9.0
ms-vsliveshare.vsliveshare@0.3.897
ms-vsts.team@1.142.0
pnp.polacode@0.2.2
quicktype.quicktype@12.0.46
redhat.java@0.33.0
robertohuertasm.vscode-icons@7.28.0
Shan.code-settings-sync@3.2.0
stkb.rewrap@1.9.1
streetsidesoftware.code-spell-checker@1.6.10
streetsidesoftware.code-spell-checker-polish@1.0.0
swyphcosmo.spellchecker@1.2.13
TomasHubelbauer.zip-file-system@1.0.0
vangware.dark-plus-material@1.4.3
VisualStudioExptTeam.vscodeintellicode@1.0.5
vscjava.vscode-java-debug@0.15.0
vscjava.vscode-java-pack@0.4.0
vscjava.vscode-java-test@0.10.0
vscjava.vscode-maven@0.11.1
WakaTime.vscode-wakatime@1.2.3
wayou.vscode-todo-highlight@1.0.4
whizkydee.material-palenight-theme@1.9.4
wholroyd.jinja@0.0.8
xaver.clang-format@1.6.2
zhuangtongfa.Material-theme@2.17.7
Zignd.html-css-class-completion@1.11.0

### PSES version: 1.9.0.0

### PowerShell version:

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

Issue Description

I am using PSDsHook module. It's installed from PSGallery. It works fine. I use it as Import-Module and it doesn't bug out. I change it to using module PSDsHook and it works fine. However for VSCode it's a problem. It says module can't be found.

image

Since PSDsHook uses Classes it requires using module instead of standard Import-Module.

Expected Behaviour

Not marking everything red.

Actual Behaviour

Marking file on left as red, claiming it's an error.

Attached Logs

Follow the instructions in the troubleshooting docs about capturing and sending logs.

rjmholt commented 5 years ago

Hi @PrzemyslawKlys, if you run PSScriptAnalyzer on this directly, do you get an error?

There should be an explanation of how to do that in our script analysis bug template.

PrzemyslawKlys commented 5 years ago
PS C:\Support\GitHub\PSBlackListChecker\Ignore> Invoke-ScriptAnalyzer -Path '.\Evotec-RunMeReporting.ps1' -verbose -Settings PSGallery -Recurse
VERBOSE: Using settings file at C:\Users\pklys\.vscode\extensions\ms-vscode.powershell-1.9.0\modules\PSScriptAnalyzer\1.17.1\Settings\PSGallery.psd1.
VERBOSE: Performing the operation "Analyzing path with Recurse=True" on target "C:\Support\GitHub\PSBlackListChecker\Ignore\Evotec-RunMeReporting.ps1".
VERBOSE: Performing the operation "Analyzing file C:\Support\GitHub\PSBlackListChecker\Ignore\Evotec-RunMeReporting.ps1" on target "C:\Support\GitHub\PSBlackListChecker\Ignore\Evotec-RunMeReporting.ps1".
VERBOSE: Analyzing file: C:\Support\GitHub\PSBlackListChecker\Ignore\Evotec-RunMeReporting.ps1
VERBOSE: Running PSAvoidUsingCmdletAliases rule.
VERBOSE: Running PSAvoidDefaultValueSwitchParameter rule.
VERBOSE: Running PSAvoidUsingEmptyCatchBlock rule.
VERBOSE: Running PSAvoidGlobalVars rule.
VERBOSE: Running PSAvoidUsingPositionalParameters rule.
VERBOSE: Running PSReservedCmdletChar rule.
VERBOSE: Running PSReservedParams rule.
VERBOSE: Running PSAvoidUsingComputerNameHardcoded rule.
VERBOSE: Running PSAvoidUsingConvertToSecureStringWithPlainText rule.
VERBOSE: Running PSAvoidUsingUserNameAndPassWordParams rule.
VERBOSE: Running PSAvoidUsingInvokeExpression rule.
VERBOSE: Running PSAvoidUsingPlainTextForPassword rule.
VERBOSE: Running PSMissingModuleManifestField rule.
VERBOSE: Running PSAvoidUsingWMICmdlet rule.
VERBOSE: Running PSUseApprovedVerbs rule.
VERBOSE: Running PSUseCmdletCorrectly rule.
VERBOSE: Running PSUseDeclaredVarsMoreThanAssignments rule.
VERBOSE: Running PSUsePSCredentialType rule.
VERBOSE: Running PSUseShouldProcessForStateChangingFunctions rule.
VERBOSE: Running PSShouldProcess rule.
VERBOSE: Running PSUseSingularNouns rule.

or

PS C:\Support\GitHub\PSBlackListChecker\Ignore> Invoke-ScriptAnalyzer -Path '.\Evotec-RunMeReporting.ps1' -verbose
VERBOSE: Settings object could not be resolved.
VERBOSE: Performing the operation "Analyzing path with Recurse=False" on target "C:\Support\GitHub\PSBlackListChecker\Ignore\Evotec-RunMeReporting.ps1".
VERBOSE: Performing the operation "Analyzing file C:\Support\GitHub\PSBlackListChecker\Ignore\Evotec-RunMeReporting.ps1" on target "C:\Support\GitHub\PSBlackListChecker\Ignore\Evotec-RunMeReporting.ps1".
VERBOSE: Analyzing file: C:\Support\GitHub\PSBlackListChecker\Ignore\Evotec-RunMeReporting.ps1
VERBOSE: Running PSAvoidDefaultValueForMandatoryParameter rule.
VERBOSE: Running PSAvoidDefaultValueSwitchParameter rule.
VERBOSE: Running PSAvoidUsingCmdletAliases rule.
VERBOSE: Running PSAvoidAssignmentToAutomaticVariable rule.
VERBOSE: Running PSAvoidGlobalAliases rule.
VERBOSE: Running PSAvoidGlobalFunctions rule.
VERBOSE: Running PSAvoidUsingEmptyCatchBlock rule.
VERBOSE: Running PSAvoidInvokingEmptyMembers rule.
VERBOSE: Running PSAvoidNullOrEmptyHelpMessageAttribute rule.
VERBOSE: Running PSReservedParams rule.
VERBOSE: Running PSAvoidGlobalVars rule.
VERBOSE: Running PSAvoidShouldContinueWithoutForce rule.
VERBOSE: Running PSAvoidUsingPositionalParameters rule.
VERBOSE: Running PSAvoidUsingUserNameAndPassWordParams rule.
VERBOSE: Running PSAvoidUsingConvertToSecureStringWithPlainText rule.
VERBOSE: Running PSAvoidUsingDeprecatedManifestFields rule.
VERBOSE: Running PSAvoidUsingInvokeExpression rule.
VERBOSE: Running PSAvoidUsingWriteHost rule.
VERBOSE: Running PSAvoidUsingWMICmdlet rule.
VERBOSE: Running PSPossibleIncorrectComparisonWithNull rule.
VERBOSE: Running PSPossibleIncorrectUsageOfAssignmentOperator rule.
VERBOSE: Running PSAvoidUsingPlainTextForPassword rule.
VERBOSE: Running PSAvoidUsingComputerNameHardcoded rule.
VERBOSE: Running PSMissingModuleManifestField rule.
VERBOSE: Running PSPossibleIncorrectUsageOfRedirectionOperator rule.
VERBOSE: Running PSReservedCmdletChar rule.
VERBOSE: Running PSProvideCommentHelp rule.
VERBOSE: Running PSUseCmdletCorrectly rule.
VERBOSE: Running PSUseCompatibleCmdlets rule.
VERBOSE: Running PSUseLiteralInitializerForHashtable rule.
VERBOSE: Running PSUseOutputTypeCorrectly rule.
VERBOSE: Running PSUsePSCredentialType rule.
VERBOSE: Running PSUseDeclaredVarsMoreThanAssignments rule.
VERBOSE: Running PSUseShouldProcessForStateChangingFunctions rule.
VERBOSE: Running PSUseSupportsShouldProcess rule.
VERBOSE: Running PSUseSingularNouns rule.
VERBOSE: Running PSUseBOMForUnicodeEncodedFile rule.
VERBOSE: Running PSUseUTF8EncodingForHelpFile rule.
VERBOSE: Running PSUseToExportFieldsInManifest rule.
VERBOSE: Running PSShouldProcess rule.
VERBOSE: Running PSUseApprovedVerbs rule.
VERBOSE: Running PSMisleadingBacktick rule.
VERBOSE: Running PSAvoidTrailingWhitespace rule.

Although I've never run this manually so not sure what to expect as an output.

image

PS C:\Support\GitHub\PSBlackListChecker> get-module psdshook -ListAvailable

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     0.1.5      PSDsHook                            Invoke-PSDsHook
rjmholt commented 5 years ago

Hmmm looks like this might be on us. A using module problem is a parse-time error, so it will be reported by the parser and PSES deals with that.

I imagine what's happening is that parsing the script in memory in PSES doesn't find the module the way that executing the file does. We should look into it.

PrzemyslawKlys commented 2 years ago

I think it works correctly now.