diff --git a/README.md b/README.md index a45d0f7e4..97fc1146e 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ PSScriptAnalyzer is shipped with a collection of built-in rules that checks vari PSScriptAnalyzer cmdlets ====================== ``` -Get-ScriptAnalyzerRule [-CustomizedRulePath ] [-Name ] [] +Get-ScriptAnalyzerRule [-CustomizedRulePath ] [-Name ] [] [-Severity ] Invoke-ScriptAnalyzer [-Path] [-CustomizedRulePath ] [-ExcludeRule ] [-IncludeRule ] [-Severity ] [-Recurse] [] ``` @@ -46,6 +46,7 @@ Pester-based ScriptAnalyzer Tests are located in ```/PSScriptAnalyzer/Te .\InvokeScriptAnalyzer.tests.ps1 * Run Tests for Built-in rules: .\*.ps1 (Example - .\ AvoidConvertToSecureStringWithPlainText.ps1) +*You can also run all tests under \Engine or \Rules by calling Invoke-Pester in the Engine/Rules directory. Contributing to ScriptAnalyzer diff --git a/Rules/AvoidUsingInternalURLs.cs b/Rules/AvoidUsingInternalURLs.cs index 90d8243cb..095cd5412 100644 --- a/Rules/AvoidUsingInternalURLs.cs +++ b/Rules/AvoidUsingInternalURLs.cs @@ -113,11 +113,12 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName) } if (!firstPartURL.Contains(".")) { + isInternalURL = true; //Add a check to exclude potential SDDL format. Check if a string have four components separated by ":" var count = firstPartURL.Count(x => x == ':'); if (count == 3 || count == 4 ) { - isInternalURL = true; + isInternalURL = false; } } } diff --git a/Tests/Rules/UseShouldProcessForStateChangingFunctions.ps1 b/Tests/Rules/UseShouldProcessForStateChangingFunctions.ps1 index 925a1b809..9898f7f87 100644 --- a/Tests/Rules/UseShouldProcessForStateChangingFunctions.ps1 +++ b/Tests/Rules/UseShouldProcessForStateChangingFunctions.ps1 @@ -1,11 +1,11 @@ -function Get-Service -{ - param ([string]$c) -} - -function Get-MyObject{ +function Set-MyObject{ [CmdletBinding(SupportsShouldProcess = $false)] param([string]$c, [int]$d) } +function Set-MyObject{ + [CmdletBinding()] + param([string]$c, [int]$d) + +} \ No newline at end of file diff --git a/Tests/Rules/UseShouldProcessForStateChangingFunctions.tests.ps1 b/Tests/Rules/UseShouldProcessForStateChangingFunctions.tests.ps1 index e5998e00e..0cbdecc5e 100644 --- a/Tests/Rules/UseShouldProcessForStateChangingFunctions.tests.ps1 +++ b/Tests/Rules/UseShouldProcessForStateChangingFunctions.tests.ps1 @@ -1,15 +1,14 @@ Import-Module PSScriptAnalyzer -$violationMessage = "Function ’Get-Service’ has verb that could change system state. Therefore, the function has to support 'ShouldProcess'" +$violationMessage = "Function ’Set-MyObject’ has verb that could change system state. Therefore, the function has to support 'ShouldProcess'" $violationName = "PSUseShouldProcessForStateChangingFunctions" -$violationName = "PS.UseShouldProcessForStateChangingFunctions" $directory = Split-Path -Parent $MyInvocation.MyCommand.Path $violations = Invoke-ScriptAnalyzer $directory\UseShouldProcessForStateChangingFunctions.ps1 | Where-Object {$_.RuleName -eq $violationName} $noViolations = Invoke-ScriptAnalyzer $directory\UseShouldProcessForStateChangingFunctionsNoViolations.ps1 | Where-Object {$_.RuleName -eq $violationName} -Describe "" { +Describe "It checks UseShouldProcess is enabled when there are state changing verbs in the function names" { Context "When there are violations" { It "has 2 violations where ShouldProcess is not supported" { - $violations.Count | Should Be 3 + $violations.Count | Should Be 2 } It "has the correct description message" { diff --git a/Tests/Rules/UseShouldProcessForStateChangingFunctionsNoViolations.ps1 b/Tests/Rules/UseShouldProcessForStateChangingFunctionsNoViolations.ps1 index cb4b2cfc9..a9f3d8aee 100644 --- a/Tests/Rules/UseShouldProcessForStateChangingFunctionsNoViolations.ps1 +++ b/Tests/Rules/UseShouldProcessForStateChangingFunctionsNoViolations.ps1 @@ -1,6 +1,6 @@ -function Get-Service +function Set-Service { - [CmdletBinding(SupportShouldSuppress= $false)] + [CmdletBinding(SupportsShouldProcess = $true)] param ([string]$c) }