From 8690db2154caf008b63d281602e449ac35255273 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Fri, 7 Feb 2020 22:18:04 +0000 Subject: [PATCH] Fix recently introduced bug (PR #1391) for UseCorrectCasing --- Rules/UseCorrectCasing.cs | 3 +-- Tests/Rules/UseCorrectCasing.tests.ps1 | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Rules/UseCorrectCasing.cs b/Rules/UseCorrectCasing.cs index 3e1b4b2fd..d1f579731 100644 --- a/Rules/UseCorrectCasing.cs +++ b/Rules/UseCorrectCasing.cs @@ -73,8 +73,7 @@ public override IEnumerable AnalyzeScript(Ast ast, string file foreach (var commandParameterAst in commandParameterAsts) { var parameterName = commandParameterAst.ParameterName; - var parameterMetaData = availableParameters[parameterName]; - if (parameterMetaData != null) + if (availableParameters.TryGetValue(parameterName, out ParameterMetadata parameterMetaData)) { var correctlyCasedParameterName = parameterMetaData.Name; if (!parameterName.Equals(correctlyCasedParameterName, StringComparison.Ordinal)) diff --git a/Tests/Rules/UseCorrectCasing.tests.ps1 b/Tests/Rules/UseCorrectCasing.tests.ps1 index 968a93ae7..61d75b408 100644 --- a/Tests/Rules/UseCorrectCasing.tests.ps1 +++ b/Tests/Rules/UseCorrectCasing.tests.ps1 @@ -65,4 +65,9 @@ Describe "UseCorrectCasing" { Invoke-Formatter 'Invoke-DummyFunction -parametername: $parameterValue' | Should -Be 'Invoke-DummyFunction -ParameterName: $parameterValue' } + + It "Should not throw when using parameter name that does not exist" { + Invoke-Formatter 'Get-Process -NonExistingParameterName' -ErrorAction Stop + } + }