Skip to content

Add rule to check cmdlet compatibility #617

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

Merged
merged 38 commits into from
Sep 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4f08fe7
Add a module to create/delete builtin rules
Sep 13, 2016
dad270c
Add add/remove rule functions to RuleMaker
Sep 13, 2016
3ca28fb
Export only add/remove from RuleMaker
Sep 13, 2016
c6fe396
Add rule documentation to RuleMaker
Sep 13, 2016
6a15f0b
Add UseCompatibleCmdlets rule skeleton
Sep 13, 2016
0af4165
Add test files for UseCompatibleCmdlets rule
Sep 14, 2016
faf0c51
Add Newtonsoft.Json to rules project
Sep 14, 2016
326e453
Modify buildCoreClr script to copy json dll
Sep 15, 2016
c1f1c82
Update test for UseCompatibleCmdlets rule
Sep 15, 2016
06712e1
Make helper ContextExtent method public static
Sep 15, 2016
6009a23
Update UseCompatibleCmdlets rule to use offline data
Sep 14, 2016
ab58624
Add script to create command file
Sep 20, 2016
8e679e8
Update and rename command data generator file
Sep 21, 2016
1a4122f
Copy settings folder through buildcoreclr script
Sep 21, 2016
f13e509
Change macOS to OSX in usecompatiblecmdlet rule
Sep 21, 2016
abd558d
Parse object[] for compatibility arg in UseCompatibleCmdlet rule
Sep 21, 2016
de8338d
Read command data files from module settings folder
Sep 21, 2016
7e4a2f8
Read updated json from usecompatiblecmdlets rule
Sep 21, 2016
3d9e91a
Update usecompatiblecmdlets rule tests
Sep 21, 2016
ef18cc0
Copy newtonsoft.json.dll if framework is net451
Sep 22, 2016
51df2f9
Delay initializing data structures in UseCompatibleCmdlets rule
Sep 22, 2016
3ed42e2
Increment total number of rules in tests
Sep 22, 2016
c5df641
Remove unused compatibility arguments
Sep 22, 2016
1b3e7cf
Set default compatibility value to true
Sep 22, 2016
bf20113
Add inline documentation to UseCompatibleCmdlets rule source
Sep 22, 2016
7e13d76
Add UseCompatibleCmdlets rule documentation
Sep 22, 2016
b732c74
Move RuleMaker module to Utils directory
Sep 22, 2016
67eb2ac
Add comment based help to exported function in RuleMaker
Sep 22, 2016
2418639
Add documentation to New-CommandDataFile.ps1
Sep 22, 2016
ad32c63
Use dotnet cli for compilation in AppVeyor
Sep 23, 2016
c35d720
Add nuget config file
Sep 23, 2016
e6ecd27
Change S.M.A version in project json
Sep 23, 2016
ef5bdf5
Remove version number modification in buildCoreClr.ps1
Sep 23, 2016
5122d56
Add command data files to settings
Sep 23, 2016
74c44c1
Add nuget packages to appveyor cache
Sep 23, 2016
36fe25a
Save command data json file as UTF-8
Sep 23, 2016
8adbda8
Fix bugs in RuleMaker.ps1 and New-CommandDataFile.psm1
Sep 26, 2016
f1aa7ac
Add builtin cmdlet metadata file for OSX
Sep 26, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Engine/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ public IScriptExtent GetScriptExtentForFunctionName(FunctionDefinitionAst functi
/// <param name="set"></param>
/// <param name="subset"></param>
/// <returns>True or False</returns>
private bool ContainsExtent(IScriptExtent set, IScriptExtent subset)
public static bool ContainsExtent(IScriptExtent set, IScriptExtent subset)
{
if (set == null || subset == null)
{
Expand Down
1,465 changes: 1,465 additions & 0 deletions Engine/Settings/core-6.0.0-alpha-linux.json

Large diffs are not rendered by default.

1,465 changes: 1,465 additions & 0 deletions Engine/Settings/core-6.0.0-alpha-osx.json

Large diffs are not rendered by default.

1,840 changes: 1,840 additions & 0 deletions Engine/Settings/core-6.0.0-alpha-windows.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Engine/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Microsoft.Windows.PowerShell.ScriptAnalyzer",
"version": "1.7.0",
"dependencies": {
"System.Management.Automation": "1.0.0-alpha.9.4808"
"System.Management.Automation": "1.0.0-alpha10"
},
"frameworks": {
"net451": {
Expand Down
17 changes: 17 additions & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="False" />
<add key="automatic" value="False" />
</packageRestore>
<activePackageSource>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</activePackageSource>
<packageSources>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="powershell-core" value="https://powershell.myget.org/F/powershell-core/api/v3/index.json" />
</packageSources>
<bindingRedirects>
<add key="skip" value="False" />
</bindingRedirects>
</configuration>
3 changes: 2 additions & 1 deletion RuleDocumentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@
|[UseShouldProcessForStateChangingFunctions](./UseShouldProcessForStateChangingFunctions.md) | Warning|
|[UseSingularNouns](./UseSingularNouns.md) | Warning|
|[UseStandardDSCFunctionsInResource](./UseStandardDSCFunctionsInResource.md) | Error |
|[UseToExportFieldsInManifest](./UseToExportFieldsInManifest.md) | Warning|
|[UseToExportFieldsInManifest](./UseToExportFieldsInManifest.md) | Warning|
|[UseCompatibleCmdlets](./UseCompatibleCmdlets.md) | Warning|
16 changes: 16 additions & 0 deletions RuleDocumentation/UseCompatibleCmdlets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# UseCompatibleCmdlets
**Severity Level: Warning**

## Description
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:
```PowerShell
@{
'Rules' = @{
'PSUseCompatibleCmdlets' = @{
'compatibility' = @("core-6.0.0-alpha-windows")
}
}
}
```

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}`.
1 change: 1 addition & 0 deletions Rules/ScriptAnalyzerBuiltinRules.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<Compile Include="UseStandardDSCFunctionsInResource.cs" />
<Compile Include="UseUTF8EncodingForHelpFile.cs" />
<Compile Include="ReturnCorrectTypesForDSCFunctions.cs" />
<Compile Include="UseCompatibleCmdlets.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Engine\ScriptAnalyzerEngine.csproj">
Expand Down
38 changes: 37 additions & 1 deletion Rules/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Rules/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -834,4 +834,16 @@
<data name="UseLiteralInitilializerForHashtableName" xml:space="preserve">
<value>UseLiteralInitializerForHashtable</value>
</data>
<data name="UseCompatibleCmdletsName" xml:space="preserve">
<value>UseCompatibleCmdlets</value>
</data>
<data name="UseCompatibleCmdletsCommonName" xml:space="preserve">
<value>Use compatible cmdlets</value>
</data>
<data name="UseCompatibleCmdletsDescription" xml:space="preserve">
<value>Use cmdlets compatible with the given PowerShell version and edition and operating system</value>
</data>
<data name="UseCompatibleCmdletsError" xml:space="preserve">
<value>'{0}' is not compatible with PowerShell edition '{1}', version '{2}' and OS '{3}'</value>
</data>
</root>
Loading