mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
Enable Static Analysis on programs plugin (#5847)
* Removing unused ProgramSettings constructor paramaters. * Fix for: Severity Code Description Project File Line Suppression State Error CA1829 Use the "Count" property instead of Enumerable.Count(). Microsoft.Plugin.Program C:\Repos\PowerToys\src\modules\launcher\Plugins\Microsoft.Plugin.Program\Views\ProgramSetting.xaml.cs 182 Active Severity Code Description Project File Line Suppression State Error CA1827 Count() is used where Any() could be used instead to improve performance. Microsoft.Plugin.Program C:\Repos\PowerToys\src\modules\launcher\Plugins\Microsoft.Plugin.Program\Views\ProgramSetting.xaml.cs 287 Active * Fixes for CA1031: https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1031?view=vs-2019 * More fixes(Suppression) for CA1031 (Catching base exception) https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1031?view=vs-2019 * Fix for nested types being externally visible. CA1034 https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1034?view=vs-2019 * Fix for CA1028 If possible, make the underlying type of Hresult System.Int32 instead of uint. Microsoft.Plugin.Program C:\Repos\PowerToys\src\modules\launcher\Plugins\Microsoft.Plugin.Program\Programs\UWP.cs 236 Active * Fix for CA2227 Collection properties should be readonly. https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2227?view=vs-2019 Fix rror CA2211 Non-constant fields should not be visible https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2211?view=vs-2019 * CA2208: Instantiate argument exceptions correctly https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2208?view=vs-2019 * Win32.cs Static analysis fixes: CA2200: Rethrow to preserve stack details https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200?view=vs-2019 CA1825: Avoid zero-length array allocations https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1825?view=vs-2019 CA2211: Non-constant fields should not be visible https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2211?view=vs-2019 * More Win32.cs static analysis fixes: CA1307: Specify StringComparison https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1307?view=vs-2019 Verifying query is not null before using it. CA1062: Validate arguments of public methods https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1062?view=vs-2019 CA1305: Specify IFormatProvider https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1305?view=vs-2019 * UWPApplication. CA2007: Do not directly await a Task https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2007?view=vs-2019 * Error CA2010 Consume the hresult returned by method 'Microsoft.Plugin.Program.Programs.AppxPackageHelper.IAppxManifestApplication.GetStringValue(string, out string)' and call Marshal.ThrowExceptionForHR. Note: CA2010 has been removed from future FXCop versions as it can provide incorrect advice for methods that don't return hresult (possibly when [PreserveSig] has been incorrectly labeled.) I've verified the methods in question do still return hresults. * More fixes for Error CA2010 Consume the hresult returned by method and call Marshal.ThrowExceptionForHR. * Fixes for: Error CA2000 Call System.IDisposable.Dispose on object created before all references to it are out of scope. * Suppress CA1031:Do not catch general exception types * Fixes for Error CA1034 Do not nest type ... * Fixing Unit tests that were broken as per a previous fix. * Fix for: CA1034: Nested types should not be visible: https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1034?view=vs-2019 * Suppressing CA1707 for native/com types. CA1707:Identifiers should not contain underscores * Fix for Error CA1307 The behavior of 'string.Replace(string, string?)' could vary based on the current user's locale settings. * Fixes for Error CA1825 Avoid unnecessary zero-length array allocations. Use Array.Empty<string>() instead. * Fix for: Error CA1823 Unused field 'IndexLock'. * Fixes for CA1822: Mark members as static: https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1822?view=vs-2019 * Fix for Error CA1819 Properties should not return arrays * Fix for Error CA1806 ContextMenus calls Trim but does not use the new string instance that the method returns. Pass the instance as an argument to another method, assign the instance to a variable, or remove the call if it is unnecessary. * Fix for Error CA1801 Parameter settings of method UpdateSettings is never used. Remove the parameter or use it in the method body. * Fix for Error CA1724 The type name Settings conflicts in whole or in part with the namespace name 'Microsoft.PowerToys.Settings'. * Includes FxCop for static analysis * Fix for Error CA1717 Only FlagsAttribute enums should have plural names * Suppress Stgm flags: Error CA1714 Flags enums should have plural names Microsoft.Plugin.Program * Rename Win32 to Win32Program Fix for: Error CA1724 The type name Win32 conflicts in whole or in part with the namespace name 'Microsoft.Win32' defined in the .NET Framework. Rename the type to eliminate the conflict. * Fixes for Error CA1507 Use nameof in place of string literal * Using ordinal instead of invariant culture when not symbolic comparison * CA1308: Normalize strings to uppercase https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1308?view=vs-2019 * CA1304: Specify CultureInfo CA1305: Specify IFormatProvider https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1305?view=vs-2019 https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1304?view=vs-2019 * CA1062: Validate arguments of public methods https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1062?view=vs-2019 * CA1056: URI properties should not be strings https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1056?view=vs-2019 Fix: Making LogoURi private, as it is only used internally and operated on as a string * Warning CA1052 Type 'AppxPackageHelper' is a static holder type but is neither static nor NotInheritable * CA1060: Move P/Invokes to NativeMethods class https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1060?view=vs-2019 * Programs Plugin - Treat warnings as errors true * CA1031:Do not catch general exception types Missed release only compile issue. Making debug and release behave the same. * Renaming 'Create' to 'CreateWin32Program' based on PR feedback.
This commit is contained in:
committed by
GitHub
parent
83de1686c0
commit
ac10c988b9
@@ -10,12 +10,12 @@ using System.IO.Packaging;
|
||||
using Windows.ApplicationModel;
|
||||
namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
{
|
||||
using Win32 = Microsoft.Plugin.Program.Programs.Win32;
|
||||
using Win32Program = Microsoft.Plugin.Program.Programs.Win32Program;
|
||||
|
||||
[TestFixture]
|
||||
public class Win32Tests
|
||||
{
|
||||
static Win32 notepad_appdata = new Win32
|
||||
static Win32Program notepad_appdata = new Win32Program
|
||||
{
|
||||
Name = "Notepad",
|
||||
ExecutableName = "notepad.exe",
|
||||
@@ -24,7 +24,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 2
|
||||
};
|
||||
|
||||
static Win32 notepad_users = new Win32
|
||||
static Win32Program notepad_users = new Win32Program
|
||||
{
|
||||
Name = "Notepad",
|
||||
ExecutableName = "notepad.exe",
|
||||
@@ -33,7 +33,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 2
|
||||
};
|
||||
|
||||
static Win32 azure_command_prompt = new Win32
|
||||
static Win32Program azure_command_prompt = new Win32Program
|
||||
{
|
||||
Name = "Microsoft Azure Command Prompt - v2.9",
|
||||
ExecutableName = "cmd.exe",
|
||||
@@ -42,7 +42,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 2
|
||||
};
|
||||
|
||||
static Win32 visual_studio_command_prompt = new Win32
|
||||
static Win32Program visual_studio_command_prompt = new Win32Program
|
||||
{
|
||||
Name = "x64 Native Tools Command Prompt for VS 2019",
|
||||
ExecutableName = "cmd.exe",
|
||||
@@ -51,7 +51,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 2
|
||||
};
|
||||
|
||||
static Win32 command_prompt = new Win32
|
||||
static Win32Program command_prompt = new Win32Program
|
||||
{
|
||||
Name = "Command Prompt",
|
||||
ExecutableName = "cmd.exe",
|
||||
@@ -60,7 +60,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 2
|
||||
};
|
||||
|
||||
static Win32 file_explorer = new Win32
|
||||
static Win32Program file_explorer = new Win32Program
|
||||
{
|
||||
Name = "File Explorer",
|
||||
ExecutableName = "File Explorer.lnk",
|
||||
@@ -69,7 +69,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 2
|
||||
};
|
||||
|
||||
static Win32 wordpad = new Win32
|
||||
static Win32Program wordpad = new Win32Program
|
||||
{
|
||||
Name = "Wordpad",
|
||||
ExecutableName = "wordpad.exe",
|
||||
@@ -78,7 +78,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 2
|
||||
};
|
||||
|
||||
static Win32 wordpad_duplicate = new Win32
|
||||
static Win32Program wordpad_duplicate = new Win32Program
|
||||
{
|
||||
Name = "WORDPAD",
|
||||
ExecutableName = "WORDPAD.EXE",
|
||||
@@ -87,7 +87,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 2
|
||||
};
|
||||
|
||||
static Win32 twitter_pwa = new Win32
|
||||
static Win32Program twitter_pwa = new Win32Program
|
||||
{
|
||||
Name = "Twitter",
|
||||
FullPath = "c:\\program files (x86)\\google\\chrome\\application\\chrome_proxy.exe",
|
||||
@@ -96,7 +96,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 0
|
||||
};
|
||||
|
||||
static Win32 pinned_webpage = new Win32
|
||||
static Win32Program pinned_webpage = new Win32Program
|
||||
{
|
||||
Name = "Web page",
|
||||
FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\msedge_proxy.exe",
|
||||
@@ -105,7 +105,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 0
|
||||
};
|
||||
|
||||
static Win32 edge_named_pinned_webpage = new Win32
|
||||
static Win32Program edge_named_pinned_webpage = new Win32Program
|
||||
{
|
||||
Name = "edge - Bing",
|
||||
FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\msedge_proxy.exe",
|
||||
@@ -114,7 +114,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 0
|
||||
};
|
||||
|
||||
static Win32 msedge = new Win32
|
||||
static Win32Program msedge = new Win32Program
|
||||
{
|
||||
Name = "Microsoft Edge",
|
||||
ExecutableName = "msedge.exe",
|
||||
@@ -123,7 +123,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 2
|
||||
};
|
||||
|
||||
static Win32 chrome = new Win32
|
||||
static Win32Program chrome = new Win32Program
|
||||
{
|
||||
Name = "Google Chrome",
|
||||
ExecutableName = "chrome.exe",
|
||||
@@ -132,7 +132,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 2
|
||||
};
|
||||
|
||||
static Win32 dummy_proxy_app = new Win32
|
||||
static Win32Program dummy_proxy_app = new Win32Program
|
||||
{
|
||||
Name = "Proxy App",
|
||||
ExecutableName = "test_proxy.exe",
|
||||
@@ -141,7 +141,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 2
|
||||
};
|
||||
|
||||
static Win32 cmd_run_command = new Win32
|
||||
static Win32Program cmd_run_command = new Win32Program
|
||||
{
|
||||
Name = "cmd",
|
||||
ExecutableName = "cmd.exe",
|
||||
@@ -150,7 +150,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 3 // Run command
|
||||
};
|
||||
|
||||
static Win32 cmder_run_command = new Win32
|
||||
static Win32Program cmder_run_command = new Win32Program
|
||||
{
|
||||
Name = "Cmder",
|
||||
Description = "Cmder: Lovely Console Emulator",
|
||||
@@ -160,7 +160,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 3 // Run command
|
||||
};
|
||||
|
||||
static Win32 dummy_internetShortcut_app = new Win32
|
||||
static Win32Program dummy_internetShortcut_app = new Win32Program
|
||||
{
|
||||
Name = "Shop Titans",
|
||||
ExecutableName = "Shop Titans.url",
|
||||
@@ -170,7 +170,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
AppType = 1
|
||||
};
|
||||
|
||||
static Win32 dummy_internetShortcut_app_duplicate = new Win32
|
||||
static Win32Program dummy_internetShortcut_app_duplicate = new Win32Program
|
||||
{
|
||||
Name = "Shop Titans",
|
||||
ExecutableName = "Shop Titans.url",
|
||||
@@ -184,12 +184,12 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
public void DedupFunction_whenCalled_mustRemoveDuplicateNotepads()
|
||||
{
|
||||
// Arrange
|
||||
List<Win32> prgms = new List<Win32>();
|
||||
List<Win32Program> prgms = new List<Win32Program>();
|
||||
prgms.Add(notepad_appdata);
|
||||
prgms.Add(notepad_users);
|
||||
|
||||
// Act
|
||||
Win32[] apps = Win32.DeduplicatePrograms(prgms.AsParallel());
|
||||
Win32Program[] apps = Win32Program.DeduplicatePrograms(prgms.AsParallel());
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(apps.Length, 1);
|
||||
@@ -199,12 +199,12 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
public void DedupFunction_whenCalled_MustRemoveInternetShortcuts()
|
||||
{
|
||||
// Arrange
|
||||
List<Win32> prgms = new List<Win32>();
|
||||
List<Win32Program> prgms = new List<Win32Program>();
|
||||
prgms.Add(dummy_internetShortcut_app);
|
||||
prgms.Add(dummy_internetShortcut_app_duplicate);
|
||||
|
||||
// Act
|
||||
Win32[] apps = Win32.DeduplicatePrograms(prgms.AsParallel());
|
||||
Win32Program[] apps = Win32Program.DeduplicatePrograms(prgms.AsParallel());
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(apps.Length, 1);
|
||||
@@ -214,11 +214,11 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
public void DedupFunction_whenCalled_mustNotRemovelnkWhichdoesNotHaveExe()
|
||||
{
|
||||
// Arrange
|
||||
List<Win32> prgms = new List<Win32>();
|
||||
List<Win32Program> prgms = new List<Win32Program>();
|
||||
prgms.Add(file_explorer);
|
||||
|
||||
// Act
|
||||
Win32[] apps = Win32.DeduplicatePrograms(prgms.AsParallel());
|
||||
Win32Program[] apps = Win32Program.DeduplicatePrograms(prgms.AsParallel());
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(apps.Length, 1);
|
||||
@@ -228,12 +228,12 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
public void DedupFunction_mustRemoveDuplicates_forExeExtensionsWithoutLnkResolvedPath()
|
||||
{
|
||||
// Arrange
|
||||
List<Win32> prgms = new List<Win32>();
|
||||
List<Win32Program> prgms = new List<Win32Program>();
|
||||
prgms.Add(wordpad);
|
||||
prgms.Add(wordpad_duplicate);
|
||||
|
||||
// Act
|
||||
Win32[] apps = Win32.DeduplicatePrograms(prgms.AsParallel());
|
||||
Win32Program[] apps = Win32Program.DeduplicatePrograms(prgms.AsParallel());
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(apps.Length, 1);
|
||||
@@ -244,13 +244,13 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
|
||||
public void DedupFunction_mustNotRemovePrograms_withSameExeNameAndFullPath()
|
||||
{
|
||||
// Arrange
|
||||
List<Win32> prgms = new List<Win32>();
|
||||
List<Win32Program> prgms = new List<Win32Program>();
|
||||
prgms.Add(azure_command_prompt);
|
||||
prgms.Add(visual_studio_command_prompt);
|
||||
prgms.Add(command_prompt);
|
||||
|
||||
// Act
|
||||
Win32[] apps = Win32.DeduplicatePrograms(prgms.AsParallel());
|
||||
Win32Program[] apps = Win32Program.DeduplicatePrograms(prgms.AsParallel());
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(apps.Length, 3);
|
||||
|
||||
Reference in New Issue
Block a user