From dfa924e92cc4074b950c79cd341ca3ab3f508c00 Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Wed, 9 Dec 2020 11:19:15 +0000 Subject: [PATCH 1/2] Fix RCS1215: Expression is always equal to true/false https://github.com/JosefPihrt/Roslynator/blob/master/docs/analyzers/RCS1215.md --- .../commands/management/Navigation.cs | 2 +- .../host/msh/ConsoleHostUserInterfacePromptForChoice.cs | 2 +- .../security/CertificateProvider.cs | 4 ++-- .../engine/hostifaces/InternalHostUserInterface.cs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs index 6528e8394c2..648b0ecb832 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs @@ -107,7 +107,7 @@ protected bool DoesProviderSupportShouldProcess(string[] paths) // may be getting piped in. bool result = true; - if (paths != null && paths.Length >= 0) + if (paths != null && true) { foreach (string path in paths) { diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePromptForChoice.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePromptForChoice.cs index da9d5689105..448eaa944a2 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePromptForChoice.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePromptForChoice.cs @@ -252,7 +252,7 @@ public Collection PromptForChoice(string caption, // choices to be picked. // user did not pick up any choices..choose the default - if ((result.Count == 0) && (defaultChoiceKeys.Keys.Count >= 0)) + if ((result.Count == 0) && (true)) { // if there's a default, pick that one. foreach (int defaultChoice in defaultChoiceKeys.Keys) diff --git a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs index 26b1668c6fb..661884eddba 100644 --- a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs +++ b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs @@ -2017,7 +2017,7 @@ private object GetItemAtPath(string path, bool test, out bool isContainer) // // Thus lengths 1 & 2 are container items. // - isContainer = (pathElements.Length >= 0) && + isContainer = (true) && (pathElements.Length <= 2); X509NativeStore store = null; @@ -2026,7 +2026,7 @@ private object GetItemAtPath(string path, bool test, out bool isContainer) // handle invalid path depth // if ((pathElements.Length > 3) || - (pathElements.Length < 0)) + (false)) { if (test) { diff --git a/src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs b/src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs index b30d64d04db..2e969b351d5 100644 --- a/src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs +++ b/src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs @@ -993,7 +993,7 @@ private Collection EmulatePromptForMultipleChoice(string caption, // choices to be picked. // user did not pick up any choices..choose the default - if ((result.Count == 0) && (defaultChoiceKeys.Keys.Count >= 0)) + if ((result.Count == 0) && (true)) { // if there's a default, pick that one. foreach (int defaultChoice in defaultChoiceKeys.Keys) From c691d9ded26c7fb61ba935e687953b0f06d12e42 Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Wed, 9 Dec 2020 11:24:15 +0000 Subject: [PATCH 2/2] cleanup --- .../commands/management/Navigation.cs | 2 +- .../host/msh/ConsoleHostUserInterfacePromptForChoice.cs | 2 +- .../security/CertificateProvider.cs | 6 ++---- .../engine/hostifaces/InternalHostUserInterface.cs | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs index 648b0ecb832..66e449dc341 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs @@ -107,7 +107,7 @@ protected bool DoesProviderSupportShouldProcess(string[] paths) // may be getting piped in. bool result = true; - if (paths != null && true) + if (paths != null) { foreach (string path in paths) { diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePromptForChoice.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePromptForChoice.cs index 448eaa944a2..872aaa19a9c 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePromptForChoice.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfacePromptForChoice.cs @@ -252,7 +252,7 @@ public Collection PromptForChoice(string caption, // choices to be picked. // user did not pick up any choices..choose the default - if ((result.Count == 0) && (true)) + if (result.Count == 0) { // if there's a default, pick that one. foreach (int defaultChoice in defaultChoiceKeys.Keys) diff --git a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs index 661884eddba..00ba1f57898 100644 --- a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs +++ b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs @@ -2017,16 +2017,14 @@ private object GetItemAtPath(string path, bool test, out bool isContainer) // // Thus lengths 1 & 2 are container items. // - isContainer = (true) && - (pathElements.Length <= 2); + isContainer = pathElements.Length <= 2; X509NativeStore store = null; // // handle invalid path depth // - if ((pathElements.Length > 3) || - (false)) + if (pathElements.Length > 3) { if (test) { diff --git a/src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs b/src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs index 2e969b351d5..57f3f675ffc 100644 --- a/src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs +++ b/src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs @@ -993,7 +993,7 @@ private Collection EmulatePromptForMultipleChoice(string caption, // choices to be picked. // user did not pick up any choices..choose the default - if ((result.Count == 0) && (true)) + if (result.Count == 0) { // if there's a default, pick that one. foreach (int defaultChoice in defaultChoiceKeys.Keys)