Repository navigation
PSUseSingularNouns Rule doesn't work in PowerShell Core but does in PowerShell #1626
Copy link
Copy link
Closed
Description
Steps to reproduce
Run the following in both PowerShell and PowerShell core
dpaul :: ~ » Invoke-ScriptAnalyzer -ScriptDefinition 'function Get-AllNics () { }'
dpaul :: ~ » Get-Module -Name PSScriptAnalyzer
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 1.19.1 PSScriptAnalyzer {Get-ScriptAnalyzerRule, Invoke-Formatter, Invoke-ScriptAnalyzer}
dpaul :: ~ » $PSversionTable.PSVersion
Major Minor Patch PreReleaseLabel BuildLabel
----- ----- ----- --------------- ----------
7 1 1
dpaul :: ~ »
PS C:\Windows\system32> Invoke-ScriptAnalyzer -ScriptDefinition 'function Get-AllNics () { }'
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
PSUseSingularNouns Warning 1 The cmdlet 'Get-AllNics' uses a plural noun. A singular
noun should be used instead.
PS C:\Windows\system32> Get-Module -Name PSScriptAnalyzer
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 1.19.1 PSScriptAnalyzer {Get-ScriptAnalyzerRule, Invoke-Formatter, Invoke-ScriptAnalyzer}
PS C:\Windows\system32> $PSversionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
5 1 19041 610
PS C:\Windows\system32>
Expected behavior
Both types of PowerShell should invoke the same rules.
Actual behavior
PowerShell Core doesn't invoke the same rules like PowerShell. PSUseSingularNouns is the only one that I have found thus far.
Environment data
dpaul :: ~ » $PSversionTable
Name Value
---- -----
PSVersion 7.1.1
PSEdition Core
GitCommitId 7.1.1
OS Microsoft Windows 10.0.19042
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.19.1
1.19.1
dpaul :: ~ » Get-Module -ListAvailable PSScriptAnalyzer
Directory: C:\Users\dpaul\Documents\PowerShell\Modules
ModuleType Version PreRelease Name PSEdition ExportedCommands
---------- ------- ---------- ---- --------- ----------------
Script 1.19.1 PSScriptAnalyzer Desk {Get-ScriptAnalyzerRule, Invoke-ScriptAnalyzer, Invoke-Formatter}
Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version PreRelease Name PSEdition ExportedCommands
---------- ------- ---------- ---- --------- ----------------
Script 1.19.1 PSScriptAnalyzer Desk {Get-ScriptAnalyzerRule, Invoke-ScriptAnalyzer, Invoke-Formatter}
PS C:\Windows\system32> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.19.1
PS C:\Windows\system32> $PSversionTable
Name Value
---- -----
PSVersion 5.1.19041.610
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.610
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Note sure if the PowerShell Core is supported, but it should be as that is what we appear to be moving to. Also not sure if the issue is partly because of the two modules somehow being loaded. Tried to remove them but wasn't working.
Reactions are currently unavailable
Activity
bergmeister commentedon Jan 22, 2021
This is known, because the Pluralisation API in .Net was not ported to .Net Core but the rule needs that API in order to work, hence why that rule is not available in PowerShell Core versions. This is documented here: https://github.com/PowerShell/PSScriptAnalyzer/tree/master/RuleDocumentation
dpaulson45 commentedon Jan 22, 2021
Christoph Bergmeister (@bergmeister) didn't see that. Thanks!
bergmeister commentedon Jan 23, 2021
Actually, I had a look and someone recently ported the old .NET API to .Net Core and published it. I opened PR #1627 that might be able to bring it back to PowerShell Core if the PowerShell Team is happy to accept using such an unofficial package.
rjmholt commentedon Feb 9, 2021
Given the fact that we don't think we can accept the unlicensed package that might resolve this issue in #1627, it might be worth briefly discussing other possibilities.
In .NET Framework, the ability to run this rule came from Entity Framework, which was just reliably present on the machine thanks to .NET Fx's GAC.
EF Core I believe has some kind of similar functionality, but doesn't expose it in such a general way (I believe deliberately to prevent people from relying on it like we used to). Even if they did, I think us shipping EF Core assemblies is probably something we don't want to do with PSSA.
As much as I'd like to re-enable this particular rule, the complexity of doing so I think means that it's probably not something we're going to be able to do any time soon.
bergmeister commentedon Feb 10, 2021
Rob Holt (@rjmholt) Please check the PR again. I updated it to a different package, which is MIT licensed
rjmholt commentedon Feb 10, 2021
I'll mark it for discussion in our next issue triage