Skip to content

Commit 48a6cd2

Browse files
author
Kapil Borle
authored
Merge pull request #617 from PowerShell/kapilmb/UseCompatibleCmdlets
Add rule to check cmdlet compatibility
2 parents c38e3e0 + f1aa7ac commit 48a6cd2

22 files changed

+5978
-21
lines changed

Engine/Helper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ public IScriptExtent GetScriptExtentForFunctionName(FunctionDefinitionAst functi
806806
/// <param name="set"></param>
807807
/// <param name="subset"></param>
808808
/// <returns>True or False</returns>
809-
private bool ContainsExtent(IScriptExtent set, IScriptExtent subset)
809+
public static bool ContainsExtent(IScriptExtent set, IScriptExtent subset)
810810
{
811811
if (set == null || subset == null)
812812
{

Engine/Settings/core-6.0.0-alpha-linux.json

Lines changed: 1465 additions & 0 deletions
Large diffs are not rendered by default.

Engine/Settings/core-6.0.0-alpha-osx.json

Lines changed: 1465 additions & 0 deletions
Large diffs are not rendered by default.

Engine/Settings/core-6.0.0-alpha-windows.json

Lines changed: 1840 additions & 0 deletions
Large diffs are not rendered by default.

Engine/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Microsoft.Windows.PowerShell.ScriptAnalyzer",
33
"version": "1.7.0",
44
"dependencies": {
5-
"System.Management.Automation": "1.0.0-alpha.9.4808"
5+
"System.Management.Automation": "1.0.0-alpha10"
66
},
77
"frameworks": {
88
"net451": {

NuGet.Config

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageRestore>
4+
<add key="enabled" value="False" />
5+
<add key="automatic" value="False" />
6+
</packageRestore>
7+
<activePackageSource>
8+
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
9+
</activePackageSource>
10+
<packageSources>
11+
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
12+
<add key="powershell-core" value="https://powershell.myget.org/F/powershell-core/api/v3/index.json" />
13+
</packageSources>
14+
<bindingRedirects>
15+
<add key="skip" value="False" />
16+
</bindingRedirects>
17+
</configuration>

RuleDocumentation/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@
4545
|[UseShouldProcessForStateChangingFunctions](./UseShouldProcessForStateChangingFunctions.md) | Warning|
4646
|[UseSingularNouns](./UseSingularNouns.md) | Warning|
4747
|[UseStandardDSCFunctionsInResource](./UseStandardDSCFunctionsInResource.md) | Error |
48-
|[UseToExportFieldsInManifest](./UseToExportFieldsInManifest.md) | Warning|
48+
|[UseToExportFieldsInManifest](./UseToExportFieldsInManifest.md) | Warning|
49+
|[UseCompatibleCmdlets](./UseCompatibleCmdlets.md) | Warning|
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# UseCompatibleCmdlets
2+
**Severity Level: Warning**
3+
4+
## Description
5+
This rule flags cmdlets that are not available in a given Edition/Version of PowerShell on a given Operating System. It works by comparing a cmdlet against a set of whitelists which ship with PSScriptAnalyzer. They can be found at `/path/to/PSScriptAnalyzerModule/Settings`. These files are of the form, `PSEDITION-PSVERSION-OS.json` where `PSEDITION` can be either `core` or `desktop`, `OS` can be either `windows`, `linux` or `osx`, and `version` is the PowerShell version. To enable the rule to check if your script is compatible on PowerShell Core on windows, put the following your settings file:
6+
```PowerShell
7+
@{
8+
'Rules' = @{
9+
'PSUseCompatibleCmdlets' = @{
10+
'compatibility' = @("core-6.0.0-alpha-windows")
11+
}
12+
}
13+
}
14+
```
15+
16+
The parameter `compatibility` is a list that contain any of the following `{core-6.0.0-alpha-windows, core-6.0.0-alpha-linux, core-6.0.0-alpha-osx}`.

Rules/ScriptAnalyzerBuiltinRules.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
<Compile Include="UseStandardDSCFunctionsInResource.cs" />
115115
<Compile Include="UseUTF8EncodingForHelpFile.cs" />
116116
<Compile Include="ReturnCorrectTypesForDSCFunctions.cs" />
117+
<Compile Include="UseCompatibleCmdlets.cs" />
117118
</ItemGroup>
118119
<ItemGroup>
119120
<ProjectReference Include="..\Engine\ScriptAnalyzerEngine.csproj">

Rules/Strings.Designer.cs

Lines changed: 37 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rules/Strings.resx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,4 +834,16 @@
834834
<data name="UseLiteralInitilializerForHashtableName" xml:space="preserve">
835835
<value>UseLiteralInitializerForHashtable</value>
836836
</data>
837+
<data name="UseCompatibleCmdletsName" xml:space="preserve">
838+
<value>UseCompatibleCmdlets</value>
839+
</data>
840+
<data name="UseCompatibleCmdletsCommonName" xml:space="preserve">
841+
<value>Use compatible cmdlets</value>
842+
</data>
843+
<data name="UseCompatibleCmdletsDescription" xml:space="preserve">
844+
<value>Use cmdlets compatible with the given PowerShell version and edition and operating system</value>
845+
</data>
846+
<data name="UseCompatibleCmdletsError" xml:space="preserve">
847+
<value>'{0}' is not compatible with PowerShell edition '{1}', version '{2}' and OS '{3}'</value>
848+
</data>
837849
</root>

0 commit comments

Comments
 (0)