From 9da1bd6f874ebf666879a25d1c0d5024be173c83 Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Sun, 22 Nov 2020 10:10:48 +0000 Subject: [PATCH] Fix SA1122: Use string.Empty for empty strings Follow-up to #6950. https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1122.md --- .globalconfig | 2 +- .../commands/management/ComputerUnix.cs | 2 +- .../commands/management/Process.cs | 2 +- src/Microsoft.WSMan.Management/ConfigProvider.cs | 2 +- .../engine/CommandCompletion/ExtensibleCompletion.cs | 2 +- .../engine/Modules/ModuleCmdletBase.cs | 2 +- .../engine/hostifaces/LocalPipeline.cs | 2 +- .../engine/remoting/common/WireDataFormat/EncodeAndDecode.cs | 2 +- src/powershell/Program.cs | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.globalconfig b/.globalconfig index f6683fcab64..74af40cc68b 100644 --- a/.globalconfig +++ b/.globalconfig @@ -1162,7 +1162,7 @@ dotnet_diagnostic.SA1120.severity = none dotnet_diagnostic.SA1121.severity = none # SA1122: Use string.Empty for empty strings -dotnet_diagnostic.SA1122.severity = none +dotnet_diagnostic.SA1122.severity = warning # SA1123: Do not place regions within elements dotnet_diagnostic.SA1123.severity = none diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/ComputerUnix.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/ComputerUnix.cs index 023fc1d0501..fc32e3edd39 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/ComputerUnix.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/ComputerUnix.cs @@ -137,7 +137,7 @@ protected override void StopProcessing() /// Run a command. /// protected void RunCommand(String command, String args) { - String cmd = ""; + String cmd = string.Empty; _process = new Process() { diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs index 1334567ffb0..e90cedaa43d 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs @@ -233,7 +233,7 @@ private void RetrieveMatchingProcessesById() catch (ArgumentException) { WriteNonTerminatingError( - "", + string.Empty, processId, processId, null, diff --git a/src/Microsoft.WSMan.Management/ConfigProvider.cs b/src/Microsoft.WSMan.Management/ConfigProvider.cs index 3b0251d09f8..a4c6ad1db72 100644 --- a/src/Microsoft.WSMan.Management/ConfigProvider.cs +++ b/src/Microsoft.WSMan.Management/ConfigProvider.cs @@ -1284,7 +1284,7 @@ protected override void SetItem(string path, object value) { if (!Force) { - string query = ""; + string query = string.Empty; string caption = helper.GetResourceMsgFromResourcetext("SetItemGeneralSecurityCaption"); if (ChildName.Equals("TrustedHosts", StringComparison.OrdinalIgnoreCase)) { diff --git a/src/System.Management.Automation/engine/CommandCompletion/ExtensibleCompletion.cs b/src/System.Management.Automation/engine/CommandCompletion/ExtensibleCompletion.cs index 6905e39b165..665dee5c8c8 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/ExtensibleCompletion.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/ExtensibleCompletion.cs @@ -129,7 +129,7 @@ protected override void EndProcessing() if (CommandName == null || CommandName.Length == 0) { - CommandName = new[] { "" }; + CommandName = new[] { string.Empty }; } for (int i = 0; i < CommandName.Length; i++) diff --git a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs index dbd52e080bd..fdd907103cc 100644 --- a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs +++ b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs @@ -2345,7 +2345,7 @@ internal PSModuleInfo LoadModuleManifest( key: "FileList", manifestProcessingFlags, moduleBase, - extension: "", + extension: string.Empty, // Don't check file existence - don't want to change current behavior without feature team discussion. verifyFilesExist: false, out List fileList)) diff --git a/src/System.Management.Automation/engine/hostifaces/LocalPipeline.cs b/src/System.Management.Automation/engine/hostifaces/LocalPipeline.cs index 61f391dd358..b79eb4d6fd5 100644 --- a/src/System.Management.Automation/engine/hostifaces/LocalPipeline.cs +++ b/src/System.Management.Automation/engine/hostifaces/LocalPipeline.cs @@ -249,7 +249,7 @@ protected override void StartPipelineExecution() } default: - Debug.Fail(""); + Debug.Fail(string.Empty); break; } } diff --git a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs index fc011b313e2..69eb7420573 100644 --- a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs +++ b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs @@ -2236,7 +2236,7 @@ internal static PowerShell GetCommandDiscoveryPipeline(object data) } else { - module = new string[] { "" }; + module = new string[] { string.Empty }; } ModuleSpecification[] fullyQualifiedName = null; diff --git a/src/powershell/Program.cs b/src/powershell/Program.cs index 732b4db5888..edac5b24f04 100644 --- a/src/powershell/Program.cs +++ b/src/powershell/Program.cs @@ -320,7 +320,7 @@ private static int ExecPwshLogin(string[] args, string pwshPath, bool isMacOS) // // Since command_name is ignored and we can't use null (it's the terminator) // we use empty string - execArgs[4] = ""; + execArgs[4] = string.Empty; // Add the arguments passed to pwsh on the end. args.CopyTo(execArgs, 5);