From 6d138e80fb74545aed05ad6a4537ac2a2d1f1a43 Mon Sep 17 00:00:00 2001 From: Davide Giacometti Date: Sun, 18 Dec 2022 14:27:14 +0100 Subject: [PATCH] [Analyzers] Update StyleCop and enable SA1200 (#22707) * update StyleCop and enable SA1200 * Fix merge issues * fix build and added using rule --- Directory.Build.props | 4 +- src/.editorconfig | 1 - src/codeAnalysis/GlobalSuppressions.cs | 1 - src/codeAnalysis/StyleCop.json | 3 +- src/common/ManagedCommon/ColorFormatHelper.cs | 32 ++-- .../Converters/FileCountConverter.cs | 8 +- .../FileListToDescriptionConverter.cs | 10 +- .../Converters/PidToIconConverter.cs | 16 +- .../UserToSystemWarningVisibilityConverter.cs | 12 +- .../ViewModels/MainViewModel.cs | 29 ++-- .../FileLocksmithUI/Views/MainPage.xaml.cs | 8 +- .../Hosts/Hosts/Helpers/NativeMethods.cs | 6 +- .../MeasureToolUI/MainWindow.xaml.cs | 3 +- src/modules/awake/Awake/Core/TrayHelper.cs | 3 +- .../Behaviors/DragAndDropReorderBehavior.cs | 28 ++-- .../Controls/ColorPickerControl.xaml.cs | 22 +-- .../ColorPickerUI/Helpers/ColorHelper.cs | 3 +- .../ViewModels/ColorEditorViewModel.cs | 2 +- .../Helpers/ColorConverterTest.cs | 57 ++++--- .../Controls/CustomSlider.xaml.cs | 6 +- .../Controls/CustomSliderAutomationPeer.cs | 8 +- .../tests/Models/ResizeBatchTests.cs | 2 +- .../ui/Extensions/BitmapMetadataExtension.cs | 10 +- .../Microsoft.Plugin.Folder/SearchResult.cs | 4 +- .../Sources/QueryInternalDirectory.cs | 2 +- .../SearchHelper/SearchResult.cs | 4 +- .../QueryTests.cs | 20 +-- .../BracketHelper.cs | 2 +- .../CalculateHelper.cs | 3 +- .../Helper/RegistryHelper.cs | 2 +- .../ImageTests.cs | 8 +- .../QueryTests.cs | 32 ++-- .../PowerLauncher/Helper/DragDataObject.cs | 14 +- .../PowerLauncher/ViewModel/MainViewModel.cs | 158 +++++++++--------- .../poweraccent/PowerAccent.Core/Languages.cs | 8 +- .../PowerAccent.Core/PowerAccent.cs | 3 +- .../Services/SettingsService.cs | 8 +- .../Tools/WindowsFunctions.cs | 6 +- .../poweraccent/PowerAccent.UI/Program.cs | 3 +- .../PowerAccent.UI/Selector.xaml.cs | 6 +- .../GcodePreviewHandler/Program.cs | 10 +- .../GcodeThumbnailProvider/Program.cs | 4 +- .../MarkdownPreviewHandler/Program.cs | 10 +- .../Formatters/JsonFormatter.cs | 4 +- .../Formatters/XmlFormatter.cs | 6 +- .../MonacoPreviewHandler/Program.cs | 10 +- .../previewpane/PdfPreviewHandler/Program.cs | 9 +- .../PdfThumbnailProvider/Program.cs | 4 +- .../StlThumbnailProvider/Program.cs | 3 +- .../previewpane/SvgPreviewHandler/Program.cs | 10 +- .../SvgThumbnailProvider/Program.cs | 4 +- .../SettingsBackupAndRestoreUtils.cs | 24 +-- .../Settings.UI.Library/SettingsUtils.cs | 4 +- .../Settings.UI/GlobalSuppressions.cs | 30 ---- .../ViewModels/GeneralViewModel.cs | 20 +-- 55 files changed, 338 insertions(+), 371 deletions(-) delete mode 100644 src/settings-ui/Settings.UI/GlobalSuppressions.cs diff --git a/Directory.Build.props b/Directory.Build.props index 655fae2a96..01872028f9 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -29,14 +29,14 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/.editorconfig b/src/.editorconfig index 6f461f661f..e67af737e1 100644 --- a/src/.editorconfig +++ b/src/.editorconfig @@ -8,7 +8,6 @@ dotnet_diagnostic.CA1303.severity = suggestion # CA1051: Do not declare visible instance fields dotnet_code_quality.ca1051.exclude_structs = true -csharp_using_directive_placement = inside_namespace:warning csharp_prefer_simple_using_statement = true:suggestion csharp_prefer_braces = true:silent csharp_style_namespace_declarations = block_scoped:silent diff --git a/src/codeAnalysis/GlobalSuppressions.cs b/src/codeAnalysis/GlobalSuppressions.cs index 92fa1d258e..59af74b139 100644 --- a/src/codeAnalysis/GlobalSuppressions.cs +++ b/src/codeAnalysis/GlobalSuppressions.cs @@ -12,7 +12,6 @@ using System.Diagnostics.CodeAnalysis; [assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:PrefixLocalCallsWithThis", Justification = "We follow the C# Core Coding Style which avoids using `this` unless absolutely necessary.")] -[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1200:UsingDirectivesMustBePlacedWithinNamespace", Justification = "We follow the C# Core Coding Style which puts using statements outside the namespace.")] [assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1201:ElementsMustAppearInTheCorrectOrder", Justification = "It is not a priority and have hight impact in code changes.")] [assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1202:ElementsMustBeOrderedByAccess", Justification = "It is not a priority and have hight impact in code changes.")] [assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1203:ConstantsMustAppearBeforeFields", Justification = "It is not a priority and have hight impact in code changes.")] diff --git a/src/codeAnalysis/StyleCop.json b/src/codeAnalysis/StyleCop.json index 1207615669..a338998bbc 100644 --- a/src/codeAnalysis/StyleCop.json +++ b/src/codeAnalysis/StyleCop.json @@ -15,7 +15,8 @@ "newlineAtEndOfFile": "require" }, "orderingRules": { - "usingDirectivesPlacement": "outsideNamespace" + "usingDirectivesPlacement": "outsideNamespace", + "systemUsingDirectivesFirst": true } } } \ No newline at end of file diff --git a/src/common/ManagedCommon/ColorFormatHelper.cs b/src/common/ManagedCommon/ColorFormatHelper.cs index e68a78b763..b740f524d8 100644 --- a/src/common/ManagedCommon/ColorFormatHelper.cs +++ b/src/common/ManagedCommon/ColorFormatHelper.cs @@ -2,13 +2,13 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Globalization; + namespace ManagedCommon { - using System; - using System.Collections.Generic; - using System.Drawing; - using System.Globalization; - public static class ColorFormatHelper { /// @@ -16,7 +16,7 @@ namespace ManagedCommon /// /// The to convert /// The cyan[0..1], magenta[0..1], yellow[0..1] and black key[0..1] of the converted color - public static (double cyan, double magenta, double yellow, double blackKey) ConvertToCMYKColor(Color color) + public static (double Cyan, double Magenta, double Yellow, double BlackKey) ConvertToCMYKColor(Color color) { // special case for black (avoid division by zero) if (color.R == 0 && color.G == 0 && color.B == 0) @@ -48,7 +48,7 @@ namespace ManagedCommon /// /// The to convert /// The hue [0°..360°], saturation [0..1] and brightness [0..1] of the converted color - public static (double hue, double saturation, double brightness) ConvertToHSBColor(Color color) + public static (double Hue, double Saturation, double Brightness) ConvertToHSBColor(Color color) { // HSB and HSV represents the same color space return ConvertToHSVColor(color); @@ -59,7 +59,7 @@ namespace ManagedCommon /// /// The to convert /// The hue [0°..360°], saturation [0..1] and value [0..1] of the converted color - public static (double hue, double saturation, double value) ConvertToHSVColor(Color color) + public static (double Hue, double Saturation, double Value) ConvertToHSVColor(Color color) { var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d; var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d; @@ -72,7 +72,7 @@ namespace ManagedCommon /// /// The to convert /// The hue [0°..360°], saturation [0..1] and intensity [0..1] of the converted color - public static (double hue, double saturation, double intensity) ConvertToHSIColor(Color color) + public static (double Hue, double Saturation, double Intensity) ConvertToHSIColor(Color color) { // special case for black if (color.R == 0 && color.G == 0 && color.B == 0) @@ -96,7 +96,7 @@ namespace ManagedCommon /// /// The to convert /// The hue [0°..360°], saturation [0..1] and lightness [0..1] values of the converted color - public static (double hue, double saturation, double lightness) ConvertToHSLColor(Color color) + public static (double Hue, double Saturation, double Lightness) ConvertToHSLColor(Color color) { var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d; var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d; @@ -120,7 +120,7 @@ namespace ManagedCommon /// /// The to convert /// The hue [0°..360°], whiteness [0..1] and blackness [0..1] of the converted color - public static (double hue, double whiteness, double blackness) ConvertToHWBColor(Color color) + public static (double Hue, double Whiteness, double Blackness) ConvertToHWBColor(Color color) { var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d; var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d; @@ -133,10 +133,10 @@ namespace ManagedCommon /// /// The to convert /// The lightness [0..100] and two chromaticities [-128..127] - public static (double lightness, double chromaticityA, double chromaticityB) ConvertToCIELABColor(Color color) + public static (double Lightness, double ChromaticityA, double ChromaticityB) ConvertToCIELABColor(Color color) { var xyz = ConvertToCIEXYZColor(color); - var lab = GetCIELABColorFromCIEXYZ(xyz.x, xyz.y, xyz.z); + var lab = GetCIELABColorFromCIEXYZ(xyz.X, xyz.Y, xyz.Z); return lab; } @@ -150,7 +150,7 @@ namespace ManagedCommon /// /// The to convert /// The X [0..1], Y [0..1] and Z [0..1] - public static (double x, double y, double z) ConvertToCIEXYZColor(Color color) + public static (double X, double Y, double Z) ConvertToCIEXYZColor(Color color) { double r = color.R / 255d; double g = color.G / 255d; @@ -177,7 +177,7 @@ namespace ManagedCommon /// The represents the luminance /// The is quasi-equal to blue (of CIE RGB) /// The lightness [0..100] and two chromaticities [-128..127] - private static (double lightness, double chromaticityA, double chromaticityB) + private static (double Lightness, double ChromaticityA, double ChromaticityB) GetCIELABColorFromCIEXYZ(double x, double y, double z) { // sRGB reference white (x=0.3127, y=0.3290, Y=1.0), actually CIE Standard Illuminant D65 truncated to 4 decimal places, @@ -215,7 +215,7 @@ namespace ManagedCommon /// /// The to convert /// The hue, whiteness [0..1] and blackness [0..1] of the converted color - public static (string hue, double whiteness, double blackness) ConvertToNaturalColor(Color color) + public static (string Hue, double Whiteness, double Blackness) ConvertToNaturalColor(Color color) { var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d; var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d; diff --git a/src/modules/FileLocksmith/FileLocksmithUI/Converters/FileCountConverter.cs b/src/modules/FileLocksmith/FileLocksmithUI/Converters/FileCountConverter.cs index 737a6cf34f..47e4e97ebf 100644 --- a/src/modules/FileLocksmith/FileLocksmithUI/Converters/FileCountConverter.cs +++ b/src/modules/FileLocksmith/FileLocksmithUI/Converters/FileCountConverter.cs @@ -2,12 +2,12 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; +using FileLocksmith.Interop; +using Microsoft.UI.Xaml.Data; + namespace PowerToys.FileLocksmithUI.Converters { - using System; - using FileLocksmith.Interop; - using Microsoft.UI.Xaml.Data; - public sealed class FileCountConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) diff --git a/src/modules/FileLocksmith/FileLocksmithUI/Converters/FileListToDescriptionConverter.cs b/src/modules/FileLocksmith/FileLocksmithUI/Converters/FileListToDescriptionConverter.cs index 4ea7687b13..58abd64fb7 100644 --- a/src/modules/FileLocksmith/FileLocksmithUI/Converters/FileListToDescriptionConverter.cs +++ b/src/modules/FileLocksmith/FileLocksmithUI/Converters/FileListToDescriptionConverter.cs @@ -2,13 +2,13 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; +using System.IO; +using FileLocksmith.Interop; +using Microsoft.UI.Xaml.Data; + namespace PowerToys.FileLocksmithUI.Converters { - using System; - using System.IO; - using FileLocksmith.Interop; - using Microsoft.UI.Xaml.Data; - public sealed class FileListToDescriptionConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) diff --git a/src/modules/FileLocksmith/FileLocksmithUI/Converters/PidToIconConverter.cs b/src/modules/FileLocksmith/FileLocksmithUI/Converters/PidToIconConverter.cs index 875ad4241f..be66f94c23 100644 --- a/src/modules/FileLocksmith/FileLocksmithUI/Converters/PidToIconConverter.cs +++ b/src/modules/FileLocksmith/FileLocksmithUI/Converters/PidToIconConverter.cs @@ -2,16 +2,16 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; +using System.Drawing; +using System.IO; +using CommunityToolkit.WinUI.UI; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Media.Imaging; +using Windows.Storage; + namespace PowerToys.FileLocksmithUI.Converters { - using System; - using System.Drawing; - using System.IO; - using CommunityToolkit.WinUI.UI; - using Microsoft.UI.Xaml.Data; - using Microsoft.UI.Xaml.Media.Imaging; - using Windows.Storage; - public sealed class PidToIconConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) diff --git a/src/modules/FileLocksmith/FileLocksmithUI/Converters/UserToSystemWarningVisibilityConverter.cs b/src/modules/FileLocksmith/FileLocksmithUI/Converters/UserToSystemWarningVisibilityConverter.cs index a4ea8199ef..d14f444117 100644 --- a/src/modules/FileLocksmith/FileLocksmithUI/Converters/UserToSystemWarningVisibilityConverter.cs +++ b/src/modules/FileLocksmith/FileLocksmithUI/Converters/UserToSystemWarningVisibilityConverter.cs @@ -2,14 +2,14 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; +using System.Globalization; +using FileLocksmith.Interop; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Data; + namespace PowerToys.FileLocksmithUI.Converters { - using System; - using System.Globalization; - using FileLocksmith.Interop; - using Microsoft.UI.Xaml; - using Microsoft.UI.Xaml.Data; - public sealed class UserToSystemWarningVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) diff --git a/src/modules/FileLocksmith/FileLocksmithUI/ViewModels/MainViewModel.cs b/src/modules/FileLocksmith/FileLocksmithUI/ViewModels/MainViewModel.cs index 38246cae11..6e0adf2dcf 100644 --- a/src/modules/FileLocksmith/FileLocksmithUI/ViewModels/MainViewModel.cs +++ b/src/modules/FileLocksmith/FileLocksmithUI/ViewModels/MainViewModel.cs @@ -2,23 +2,20 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using FileLocksmith.Interop; +using global::FileLocksmithUI.Helpers; + namespace PowerToys.FileLocksmithUI.ViewModels { - using System; - using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.Diagnostics; - using System.Linq; - using System.Threading; - using System.Threading.Tasks; - using CommunityToolkit.Mvvm.ComponentModel; - using CommunityToolkit.Mvvm.Input; - using FileLocksmith.Interop; - using global::FileLocksmithUI; - using global::FileLocksmithUI.Helpers; - using Microsoft.UI.Dispatching; - using Microsoft.UI.Xaml.Controls; - #pragma warning disable CA1708 // Identifiers should differ by more than case public partial class MainViewModel : ObservableObject, IDisposable #pragma warning restore CA1708 // Identifiers should differ by more than case @@ -31,7 +28,7 @@ namespace PowerToys.FileLocksmithUI.ViewModels private bool _disposed; private CancellationTokenSource _cancelProcessWatching; - public ObservableCollection Processes { get; } = new (); + public ObservableCollection Processes { get; } = new(); public bool IsLoading { diff --git a/src/modules/FileLocksmith/FileLocksmithUI/Views/MainPage.xaml.cs b/src/modules/FileLocksmith/FileLocksmithUI/Views/MainPage.xaml.cs index 61ae051548..6a98692941 100644 --- a/src/modules/FileLocksmith/FileLocksmithUI/Views/MainPage.xaml.cs +++ b/src/modules/FileLocksmith/FileLocksmithUI/Views/MainPage.xaml.cs @@ -2,12 +2,12 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; +using Microsoft.UI.Xaml.Controls; +using PowerToys.FileLocksmithUI.ViewModels; + namespace PowerToys.FileLocksmithUI.Views { - using System; - using Microsoft.UI.Xaml.Controls; - using PowerToys.FileLocksmithUI.ViewModels; - public sealed partial class MainPage : Page { public MainViewModel ViewModel { get; private set; } diff --git a/src/modules/Hosts/Hosts/Helpers/NativeMethods.cs b/src/modules/Hosts/Hosts/Helpers/NativeMethods.cs index e35884560c..bff5f3db4f 100644 --- a/src/modules/Hosts/Hosts/Helpers/NativeMethods.cs +++ b/src/modules/Hosts/Hosts/Helpers/NativeMethods.cs @@ -2,11 +2,11 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; +using System.Runtime.InteropServices; + namespace Hosts.Helpers { - using System; - using System.Runtime.InteropServices; - internal class NativeMethods { [DllImport("user32.dll", SetLastError = true)] diff --git a/src/modules/MeasureTool/MeasureToolUI/MainWindow.xaml.cs b/src/modules/MeasureTool/MeasureToolUI/MainWindow.xaml.cs index f90f7a55d2..c15d157fcf 100644 --- a/src/modules/MeasureTool/MeasureToolUI/MainWindow.xaml.cs +++ b/src/modules/MeasureTool/MeasureToolUI/MainWindow.xaml.cs @@ -13,11 +13,10 @@ using Microsoft.UI.Xaml.Controls.Primitives; using Microsoft.UI.Xaml.Input; using Windows.Graphics; using WinUIEx; +using static NativeMethods; namespace MeasureToolUI { - using static NativeMethods; - /// /// An empty window that can be used on its own or navigated to within a Frame. /// diff --git a/src/modules/awake/Awake/Core/TrayHelper.cs b/src/modules/awake/Awake/Core/TrayHelper.cs index f76a5ecd04..171da89ff2 100644 --- a/src/modules/awake/Awake/Core/TrayHelper.cs +++ b/src/modules/awake/Awake/Core/TrayHelper.cs @@ -57,7 +57,8 @@ namespace Awake.Core _log.Error($"An error occurred initializing the tray. {ex.Message}"); _log.Error($"{ex.StackTrace}"); } - }, TrayIcon); + }, + TrayIcon); } /// diff --git a/src/modules/colorPicker/ColorPickerUI/Behaviors/DragAndDropReorderBehavior.cs b/src/modules/colorPicker/ColorPickerUI/Behaviors/DragAndDropReorderBehavior.cs index d43208e71e..03a84eac1f 100644 --- a/src/modules/colorPicker/ColorPickerUI/Behaviors/DragAndDropReorderBehavior.cs +++ b/src/modules/colorPicker/ColorPickerUI/Behaviors/DragAndDropReorderBehavior.cs @@ -38,19 +38,21 @@ namespace ColorPicker.Behaviors { Task.Run( new Action(() => - { - Dispatcher.BeginInvoke( - new Action(() => - { - if (e.LeftButton == MouseButtonState.Pressed) - { - var data = new DataObject(); - data.SetData("Source", (sender as FrameworkElement).DataContext); - DragDrop.DoDragDrop(sender as DependencyObject, data, DragDropEffects.Move); - e.Handled = true; - } - }), null); - }), CancellationToken.None); + { + Dispatcher.BeginInvoke( + new Action(() => + { + if (e.LeftButton == MouseButtonState.Pressed) + { + var data = new DataObject(); + data.SetData("Source", (sender as FrameworkElement).DataContext); + DragDrop.DoDragDrop(sender as DependencyObject, data, DragDropEffects.Move); + e.Handled = true; + } + }), + null); + }), + CancellationToken.None); } } diff --git a/src/modules/colorPicker/ColorPickerUI/Controls/ColorPickerControl.xaml.cs b/src/modules/colorPicker/ColorPickerUI/Controls/ColorPickerControl.xaml.cs index c50ee3b69f..7c5fe0e26e 100644 --- a/src/modules/colorPicker/ColorPickerUI/Controls/ColorPickerControl.xaml.cs +++ b/src/modules/colorPicker/ColorPickerUI/Controls/ColorPickerControl.xaml.cs @@ -103,28 +103,28 @@ namespace ColorPicker.Controls HueGradientSlider.Background = gradientBrush; } - private static void SetColorVariationsForCurrentColor(DependencyObject d, (double hue, double saturation, double value) hsv) + private static void SetColorVariationsForCurrentColor(DependencyObject d, (double Hue, double Saturation, double Value) hsv) { var hueCoefficient = 0; var hueCoefficient2 = 0; - if (1 - hsv.value < 0.15) + if (1 - hsv.Value < 0.15) { hueCoefficient = 1; } - if (hsv.value - 0.3 < 0) + if (hsv.Value - 0.3 < 0) { hueCoefficient2 = 1; } - var s = hsv.saturation; + var s = hsv.Saturation; var control = (ColorPickerControl)d; - control.colorVariation1Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Min(hsv.hue + (hueCoefficient * 8), 360), s, Math.Min(hsv.value + 0.3, 1))); - control.colorVariation2Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Min(hsv.hue + (hueCoefficient * 4), 360), s, Math.Min(hsv.value + 0.15, 1))); + control.colorVariation1Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Min(hsv.Hue + (hueCoefficient * 8), 360), s, Math.Min(hsv.Value + 0.3, 1))); + control.colorVariation2Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Min(hsv.Hue + (hueCoefficient * 4), 360), s, Math.Min(hsv.Value + 0.15, 1))); - control.colorVariation3Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Max(hsv.hue - (hueCoefficient2 * 4), 0), s, Math.Max(hsv.value - 0.2, 0))); - control.colorVariation4Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Max(hsv.hue - (hueCoefficient2 * 8), 0), s, Math.Max(hsv.value - 0.3, 0))); + control.colorVariation3Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Max(hsv.Hue - (hueCoefficient2 * 4), 0), s, Math.Max(hsv.Value - 0.2, 0))); + control.colorVariation4Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Max(hsv.Hue - (hueCoefficient2 * 8), 0), s, Math.Max(hsv.Value - 0.3, 0))); } private void UpdateValueColorGradient(double posX) @@ -312,9 +312,9 @@ namespace ColorPicker.Controls { var hsv = ColorFormatHelper.ConvertToHSVColor(color); - var huePosition = (hsv.hue / 360) * HueGradientSlider.Maximum; - var saturationPosition = hsv.saturation * SaturationGradientSlider.Maximum; - var valuePosition = hsv.value * ValueGradientSlider.Maximum; + var huePosition = (hsv.Hue / 360) * HueGradientSlider.Maximum; + var saturationPosition = hsv.Saturation * SaturationGradientSlider.Maximum; + var valuePosition = hsv.Value * ValueGradientSlider.Maximum; UpdateHueColorGradient(huePosition); UpdateSaturationColorGradient(saturationPosition); UpdateValueColorGradient(valuePosition); diff --git a/src/modules/colorPicker/ColorPickerUI/Helpers/ColorHelper.cs b/src/modules/colorPicker/ColorPickerUI/Helpers/ColorHelper.cs index fd3b0c2a36..e52e0e8ff9 100644 --- a/src/modules/colorPicker/ColorPickerUI/Helpers/ColorHelper.cs +++ b/src/modules/colorPicker/ColorPickerUI/Helpers/ColorHelper.cs @@ -2,7 +2,6 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Drawing; namespace ColorPicker.Helpers @@ -17,7 +16,7 @@ namespace ColorPicker.Helpers /// /// The to convert /// The int / 255d for each value to get value between 0 and 1 - internal static (double red, double green, double blue) ConvertToDouble(Color color) + internal static (double Red, double Green, double Blue) ConvertToDouble(Color color) => (color.R / 255d, color.G / 255d, color.B / 255d); } } diff --git a/src/modules/colorPicker/ColorPickerUI/ViewModels/ColorEditorViewModel.cs b/src/modules/colorPicker/ColorPickerUI/ViewModels/ColorEditorViewModel.cs index 18e6a11cd5..ae747b0d58 100644 --- a/src/modules/colorPicker/ColorPickerUI/ViewModels/ColorEditorViewModel.cs +++ b/src/modules/colorPicker/ColorPickerUI/ViewModels/ColorEditorViewModel.cs @@ -189,7 +189,7 @@ namespace ColorPicker.ViewModels { ".TXT" => colors.ToTxt(';'), ".JSON" => colors.ToJson(), - _ => string.Empty + _ => string.Empty, }; File.WriteAllText(dialog.FileName, contentToWrite); diff --git a/src/modules/colorPicker/UnitTest-ColorPickerUI/Helpers/ColorConverterTest.cs b/src/modules/colorPicker/UnitTest-ColorPickerUI/Helpers/ColorConverterTest.cs index 5e3f02ff83..34616f7a8d 100644 --- a/src/modules/colorPicker/UnitTest-ColorPickerUI/Helpers/ColorConverterTest.cs +++ b/src/modules/colorPicker/UnitTest-ColorPickerUI/Helpers/ColorConverterTest.cs @@ -5,7 +5,6 @@ using System; using System.Drawing; using System.Globalization; -using ColorPicker.Helpers; using ManagedCommon; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -57,13 +56,13 @@ namespace Microsoft.ColorPicker.UnitTests var result = ColorFormatHelper.ConvertToHSLColor(color); // hue[0°..360°] - Assert.AreEqual(result.hue, hue, 0.2d); + Assert.AreEqual(result.Hue, hue, 0.2d); // saturation[0..1] - Assert.AreEqual(result.saturation * 100d, saturation, 0.2d); + Assert.AreEqual(result.Saturation * 100d, saturation, 0.2d); // lightness[0..1] - Assert.AreEqual(result.lightness * 100d, lightness, 0.2d); + Assert.AreEqual(result.Lightness * 100d, lightness, 0.2d); } // test values taken from https://de.wikipedia.org/wiki/HSV-Farbraum @@ -106,13 +105,13 @@ namespace Microsoft.ColorPicker.UnitTests var result = ColorFormatHelper.ConvertToHSVColor(color); // hue [0°..360°] - Assert.AreEqual(result.hue, hue, 0.2d); + Assert.AreEqual(result.Hue, hue, 0.2d); // saturation[0..1] - Assert.AreEqual(result.saturation * 100d, saturation, 0.2d); + Assert.AreEqual(result.Saturation * 100d, saturation, 0.2d); // value[0..1] - Assert.AreEqual(result.value * 100d, value, 0.2d); + Assert.AreEqual(result.Value * 100d, value, 0.2d); } // test values taken from https://de.wikipedia.org/wiki/HSV-Farbraum @@ -155,13 +154,13 @@ namespace Microsoft.ColorPicker.UnitTests var result = ColorFormatHelper.ConvertToHSBColor(color); // hue [0°..360°] - Assert.AreEqual(result.hue, hue, 0.2d); + Assert.AreEqual(result.Hue, hue, 0.2d); // saturation[0..1] - Assert.AreEqual(result.saturation * 100d, saturation, 0.2d); + Assert.AreEqual(result.Saturation * 100d, saturation, 0.2d); // value[0..1] - Assert.AreEqual(result.brightness * 100d, value, 0.2d); + Assert.AreEqual(result.Brightness * 100d, value, 0.2d); } [TestMethod] @@ -199,16 +198,16 @@ namespace Microsoft.ColorPicker.UnitTests var result = ColorFormatHelper.ConvertToCMYKColor(color); // cyan[0..1] - Assert.AreEqual(result.cyan * 100d, cyan, 0.5d); + Assert.AreEqual(result.Cyan * 100d, cyan, 0.5d); // magenta[0..1] - Assert.AreEqual(result.magenta * 100d, magenta, 0.5d); + Assert.AreEqual(result.Magenta * 100d, magenta, 0.5d); // yellow[0..1] - Assert.AreEqual(result.yellow * 100d, yellow, 0.5d); + Assert.AreEqual(result.Yellow * 100d, yellow, 0.5d); // black[0..1] - Assert.AreEqual(result.blackKey * 100d, blackKey, 0.5d); + Assert.AreEqual(result.BlackKey * 100d, blackKey, 0.5d); } // values taken from https://en.wikipedia.org/wiki/HSL_and_HSV#Examples @@ -249,13 +248,13 @@ namespace Microsoft.ColorPicker.UnitTests var result = ColorFormatHelper.ConvertToHSIColor(color); // hue[0°..360°] - Assert.AreEqual(result.hue, hue, 0.5d); + Assert.AreEqual(result.Hue, hue, 0.5d); // saturation[0..1] - Assert.AreEqual(result.saturation * 100d, saturation, 0.5d); + Assert.AreEqual(result.Saturation * 100d, saturation, 0.5d); // intensity[0..1] - Assert.AreEqual(result.intensity * 100d, intensity, 0.5d); + Assert.AreEqual(result.Intensity * 100d, intensity, 0.5d); } // values taken from https://en.wikipedia.org/wiki/HSL_and_HSV#Examples @@ -297,13 +296,13 @@ namespace Microsoft.ColorPicker.UnitTests var result = ColorFormatHelper.ConvertToHWBColor(color); // hue[0°..360°] - Assert.AreEqual(result.hue, hue, 0.5d); + Assert.AreEqual(result.Hue, hue, 0.5d); // whiteness[0..1] - Assert.AreEqual(result.whiteness * 100d, whiteness, 0.5d); + Assert.AreEqual(result.Whiteness * 100d, whiteness, 0.5d); // blackness[0..1] - Assert.AreEqual(result.blackness * 100d, blackness, 0.5d); + Assert.AreEqual(result.Blackness * 100d, blackness, 0.5d); } // values taken from https://en.wikipedia.org/wiki/HSL_and_HSV#Examples @@ -345,13 +344,13 @@ namespace Microsoft.ColorPicker.UnitTests var result = ColorFormatHelper.ConvertToNaturalColor(color); // hue - Assert.AreEqual(result.hue, hue); + Assert.AreEqual(result.Hue, hue); // whiteness[0..1] - Assert.AreEqual(result.whiteness * 100d, whiteness, 0.5d); + Assert.AreEqual(result.Whiteness * 100d, whiteness, 0.5d); // blackness[0..1] - Assert.AreEqual(result.blackness * 100d, blackness, 0.5d); + Assert.AreEqual(result.Blackness * 100d, blackness, 0.5d); } [TestMethod] @@ -401,13 +400,13 @@ namespace Microsoft.ColorPicker.UnitTests var result = ColorFormatHelper.ConvertToCIELABColor(color); // lightness[0..100] - Assert.AreEqual(Math.Round(result.lightness, 2), lightness); + Assert.AreEqual(Math.Round(result.Lightness, 2), lightness); // chromaticityA[-128..127] - Assert.AreEqual(Math.Round(result.chromaticityA, 2), chromaticityA); + Assert.AreEqual(Math.Round(result.ChromaticityA, 2), chromaticityA); // chromaticityB[-128..127] - Assert.AreEqual(Math.Round(result.chromaticityB, 2), chromaticityB); + Assert.AreEqual(Math.Round(result.ChromaticityB, 2), chromaticityB); } // The following results are computed using LittleCMS2, an open-source color management engine, @@ -465,13 +464,13 @@ namespace Microsoft.ColorPicker.UnitTests var result = ColorFormatHelper.ConvertToCIEXYZColor(color); // x[0..0.95047] - Assert.AreEqual(Math.Round(result.x * 100, 4), x); + Assert.AreEqual(Math.Round(result.X * 100, 4), x); // y[0..1] - Assert.AreEqual(Math.Round(result.y * 100, 4), y); + Assert.AreEqual(Math.Round(result.Y * 100, 4), y); // z[0..1.08883] - Assert.AreEqual(Math.Round(result.z * 100, 4), z); + Assert.AreEqual(Math.Round(result.Z * 100, 4), z); } [TestMethod] diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Controls/CustomSlider.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Controls/CustomSlider.xaml.cs index 3408e43f27..dc8ab881ca 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/Controls/CustomSlider.xaml.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/Controls/CustomSlider.xaml.cs @@ -2,11 +2,11 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Windows.Automation.Peers; +using System.Windows.Controls; + namespace FancyZonesEditor.Controls { - using System.Windows.Automation.Peers; - using System.Windows.Controls; - /// /// Interaction logic for CustomSlider.xaml /// diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Controls/CustomSliderAutomationPeer.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Controls/CustomSliderAutomationPeer.cs index b52306eb57..ba006e2c13 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/Controls/CustomSliderAutomationPeer.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/Controls/CustomSliderAutomationPeer.cs @@ -2,12 +2,12 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Globalization; +using System.Windows.Automation.Peers; +using System.Windows.Controls; + namespace FancyZonesEditor.Controls { - using System.Globalization; - using System.Windows.Automation.Peers; - using System.Windows.Controls; - internal class CustomSliderAutomationPeer : SliderAutomationPeer { private string name = string.Empty; diff --git a/src/modules/imageresizer/tests/Models/ResizeBatchTests.cs b/src/modules/imageresizer/tests/Models/ResizeBatchTests.cs index f919b6039a..240c7efc51 100644 --- a/src/modules/imageresizer/tests/Models/ResizeBatchTests.cs +++ b/src/modules/imageresizer/tests/Models/ResizeBatchTests.cs @@ -86,7 +86,7 @@ namespace ImageResizer.Models var batch = CreateBatch(_ => { }); batch.Files.Add("Image1.jpg"); batch.Files.Add("Image2.jpg"); - var calls = new ConcurrentBag<(int i, double count)>(); + var calls = new ConcurrentBag<(int I, double Count)>(); batch.Process( (i, count) => calls.Add((i, count)), diff --git a/src/modules/imageresizer/ui/Extensions/BitmapMetadataExtension.cs b/src/modules/imageresizer/ui/Extensions/BitmapMetadataExtension.cs index 4bd3905620..6ed051d4f3 100644 --- a/src/modules/imageresizer/ui/Extensions/BitmapMetadataExtension.cs +++ b/src/modules/imageresizer/ui/Extensions/BitmapMetadataExtension.cs @@ -111,9 +111,9 @@ namespace ImageResizer.Extensions /// /// metadata path and metadata value of all successfully read data items. /// - public static List<(string metadataPath, object value)> GetListOfMetadata(this BitmapMetadata metadata) + public static List<(string MetadataPath, object Value)> GetListOfMetadata(this BitmapMetadata metadata) { - var listOfAllMetadata = new List<(string metadataPath, object value)>(); + var listOfAllMetadata = new List<(string MetadataPath, object Value)>(); try { @@ -196,7 +196,7 @@ namespace ImageResizer.Extensions foreach (var metadataItem in listOfMetadata) { // Debug.WriteLine($"modifiableMetadata.RemoveQuerySafe(\"{metadataItem.metadataPath}\");"); - Debug.WriteLine($"{metadataItem.metadataPath} | {metadataItem.value}"); + Debug.WriteLine($"{metadataItem.MetadataPath} | {metadataItem.Value}"); } } @@ -207,9 +207,9 @@ namespace ImageResizer.Extensions /// /// Intented for debug only!!! /// - public static List<(string metadataPath, object value)> GetListOfMetadataForDebug(this BitmapMetadata metadata) + public static List<(string MetadataPath, object Value)> GetListOfMetadataForDebug(this BitmapMetadata metadata) { - var listOfAllMetadata = new List<(string metadataPath, object value)>(); + var listOfAllMetadata = new List<(string MetadataPath, object Value)>(); try { diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/SearchResult.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/SearchResult.cs index 15ad4b9cf9..fbd5fa9144 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/SearchResult.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/SearchResult.cs @@ -2,10 +2,10 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Wox.Plugin.Interfaces; + namespace Microsoft.Plugin.Folder { - using Wox.Plugin.Interfaces; - public class SearchResult : IFileDropResult { public string Path { get; set; } diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/QueryInternalDirectory.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/QueryInternalDirectory.cs index 9757253d11..e576497259 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/QueryInternalDirectory.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/QueryInternalDirectory.cs @@ -44,7 +44,7 @@ namespace Microsoft.Plugin.Folder.Sources return query.Any(c => c.Equals('>')); } - private (string search, string incompleteName) Process(string search) + private (string Search, string IncompleteName) Process(string search) { string incompleteName = string.Empty; if (HasSpecialChars(search) || !_directory.Exists($@"{search}\")) diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/SearchHelper/SearchResult.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/SearchHelper/SearchResult.cs index 72e45b616c..d8487b29b9 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/SearchHelper/SearchResult.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/SearchHelper/SearchResult.cs @@ -2,10 +2,10 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Wox.Plugin.Interfaces; + namespace Microsoft.Plugin.Indexer.SearchHelper { - using Wox.Plugin.Interfaces; - public class SearchResult : IFileDropResult { // Contains the Path of the file or folder diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTest/QueryTests.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTest/QueryTests.cs index cc936eb2b4..56dd89430a 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTest/QueryTests.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTest/QueryTests.cs @@ -29,8 +29,8 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests public void ErrorResultOnInvalidKeywordQuery(string typedString, string expectedResult) { // Setup - Mock
main = new (); - Query expectedQuery = new (typedString, "="); + Mock
main = new(); + Query expectedQuery = new(typedString, "="); // Act var result = main.Object.Query(expectedQuery).FirstOrDefault().SubTitle; @@ -56,8 +56,8 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests public void NoResultOnInvalidGlobalQuery(string typedString) { // Setup - Mock
main = new (); - Query expectedQuery = new (typedString); + Mock
main = new(); + Query expectedQuery = new(typedString); // Act var result = main.Object.Query(expectedQuery).Count; @@ -80,9 +80,9 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests public void NoResultIfQueryEndsWithBinaryOperator(string typedString) { // Setup - Mock
main = new (); - Query expectedQuery = new (typedString); - Query expectedQueryWithKeyword = new ("=" + typedString, "="); + Mock
main = new(); + Query expectedQuery = new(typedString); + Query expectedQueryWithKeyword = new("=" + typedString, "="); // Act var result = main.Object.Query(expectedQuery).Count; @@ -101,9 +101,9 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests public void NoErrorForDivisionByNumberWithDecimalDigits(string typedString) { // Setup - Mock
main = new (); - Query expectedQuery = new (typedString); - Query expectedQueryWithKeyword = new ("=" + typedString, "="); + Mock
main = new(); + Query expectedQuery = new(typedString); + Query expectedQueryWithKeyword = new("=" + typedString, "="); // Act var result = main.Object.Query(expectedQuery).FirstOrDefault().SubTitle; diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/BracketHelper.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/BracketHelper.cs index d095681028..4845c99674 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/BracketHelper.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/BracketHelper.cs @@ -53,7 +53,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator return !trailTest.Any(); } - private static (TrailDirection direction, TrailType type) BracketTrail(char @char) + private static (TrailDirection Direction, TrailType Type) BracketTrail(char @char) { switch (@char) { diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/CalculateHelper.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/CalculateHelper.cs index 6972032c15..ca00f679d3 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/CalculateHelper.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/CalculateHelper.cs @@ -19,7 +19,8 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator @"pi|" + @"==|~=|&&|\|\||" + @"e|[0-9]|0x[0-9a-fA-F]+|0b[01]+|[\+\-\*\/\^\., ""]|[\(\)\|\!\[\]]" + - @")+$", RegexOptions.Compiled); + @")+$", + RegexOptions.Compiled); public static bool InputValid(string input) { diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry/Helper/RegistryHelper.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry/Helper/RegistryHelper.cs index 799caf5ba4..32d94595a1 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry/Helper/RegistryHelper.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry/Helper/RegistryHelper.cs @@ -42,7 +42,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Registry.Helper /// /// The query to search /// A combination of a list of base and the sub keys - internal static (IEnumerable? baseKey, string subKey) GetRegistryBaseKey(in string query) + internal static (IEnumerable? BaseKey, string SubKey) GetRegistryBaseKey(in string query) { if (string.IsNullOrWhiteSpace(query)) { diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/ImageTests.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/ImageTests.cs index bf54887758..9910e44388 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/ImageTests.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/ImageTests.cs @@ -63,9 +63,9 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests public void IconThemeDarkTest(string typedString, string subTitleMatch, string expectedResult) { // Setup - Mock
main = new (); + Mock
main = new(); main.Object.IconTheme = "dark"; - Query expectedQuery = new ("(" + typedString, "("); + Query expectedQuery = new("(" + typedString, "("); // Act string result = main.Object.Query(expectedQuery).FirstOrDefault(predicate: x => x.SubTitle.StartsWith(subTitleMatch, System.StringComparison.CurrentCulture)).IcoPath; @@ -108,9 +108,9 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests public void IconThemeLightTest(string typedString, string subTitleMatch, string expectedResult) { // Setup - Mock
main = new (); + Mock
main = new(); main.Object.IconTheme = "light"; - Query expectedQuery = new ("(" + typedString, "("); + Query expectedQuery = new("(" + typedString, "("); // Act var result = main.Object.Query(expectedQuery).FirstOrDefault(x => x.SubTitle.StartsWith(subTitleMatch, System.StringComparison.CurrentCulture)).IcoPath; diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/QueryTests.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/QueryTests.cs index 36730caa4e..28aabc2aab 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/QueryTests.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/QueryTests.cs @@ -41,8 +41,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests public void CountWithoutPluginKeyword(string typedString, int expectedResultCount) { // Setup - Mock
main = new (); - Query expectedQuery = new (typedString); + Mock
main = new(); + Query expectedQuery = new(typedString); // Act var result = main.Object.Query(expectedQuery).Count; @@ -63,8 +63,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests public void CountWithPluginKeyword(string typedString, int expectedResultCount) { // Setup - Mock
main = new (); - Query expectedQuery = new (typedString, "("); + Mock
main = new(); + Query expectedQuery = new(typedString, "("); // Act var result = main.Object.Query(expectedQuery); @@ -87,8 +87,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests public void ValidateBehaviorOnGlobalQueries(string typedString, int expectedResultCount) { // Setup - Mock
main = new (); - Query expectedQuery = new (typedString); + Mock
main = new(); + Query expectedQuery = new(typedString); // Act var result = main.Object.Query(expectedQuery); @@ -141,8 +141,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests public void CanFindFormatResult(string typedString, string expectedResult) { // Setup - Mock
main = new (); - Query expectedQuery = new (typedString, "("); + Mock
main = new(); + Query expectedQuery = new(typedString, "("); // Act var result = main.Object.Query(expectedQuery).FirstOrDefault(x => x.SubTitle.StartsWith(expectedResult, StringComparison.CurrentCulture)); @@ -160,8 +160,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests public void DateTimeNumberOnlyInput(string typedString, string expectedResult) { // Setup - Mock
main = new (); - Query expectedQuery = new (typedString, "("); + Mock
main = new(); + Query expectedQuery = new(typedString, "("); // Act var result = main.Object.Query(expectedQuery).FirstOrDefault(x => x.SubTitle.StartsWith(expectedResult, StringComparison.CurrentCulture)); @@ -188,8 +188,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests public void InvalidInputNotShowsResults(string typedString) { // Setup - Mock
main = new (); - Query expectedQuery = new (typedString, "("); + Mock
main = new(); + Query expectedQuery = new(typedString, "("); // Act var result = main.Object.Query(expectedQuery).FirstOrDefault(); @@ -206,8 +206,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests public void InvalidNumberInputShowsErrorMessage(string typedString) { // Setup - Mock
main = new (); - Query expectedQuery = new (typedString, "("); + Mock
main = new(); + Query expectedQuery = new(typedString, "("); // Act var result = main.Object.Query(expectedQuery).FirstOrDefault().Title; @@ -224,8 +224,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests public void InvalidInputNotShowsErrorMessage(string typedString) { // Setup - Mock
main = new (); - Query expectedQuery = new (typedString, "("); + Mock
main = new(); + Query expectedQuery = new(typedString, "("); // Act var result = main.Object.Query(expectedQuery).FirstOrDefault(); diff --git a/src/modules/launcher/PowerLauncher/Helper/DragDataObject.cs b/src/modules/launcher/PowerLauncher/Helper/DragDataObject.cs index 39171ecd22..b0584bb23d 100644 --- a/src/modules/launcher/PowerLauncher/Helper/DragDataObject.cs +++ b/src/modules/launcher/PowerLauncher/Helper/DragDataObject.cs @@ -2,15 +2,15 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; +using System.Drawing; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; +using DrawingImaging = System.Drawing.Imaging; +using MediaImaging = System.Windows.Media.Imaging; + namespace PowerLauncher.Helper { - using System; - using System.Drawing; - using System.Runtime.InteropServices; - using System.Runtime.InteropServices.ComTypes; - using DrawingImaging = System.Drawing.Imaging; - using MediaImaging = System.Windows.Media.Imaging; - // based on: https://stackoverflow.com/questions/61041282/showing-image-thumbnail-with-mouse-cursor-while-dragging/61148788#61148788 public static class DragDataObject { diff --git a/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs b/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs index 3b5a59d71e..b977828490 100644 --- a/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs +++ b/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs @@ -153,10 +153,11 @@ namespace PowerLauncher.ViewModel { Task.Run( () => - { - PluginManager.UpdatePluginMetadata(e.Results, pair.Metadata, e.Query); - UpdateResultView(e.Results, e.Query.RawQuery, _updateToken); - }, _updateToken); + { + PluginManager.UpdatePluginMetadata(e.Results, pair.Metadata, e.Query); + UpdateResultView(e.Results, e.Query.RawQuery, _updateToken); + }, + _updateToken); }; } } @@ -553,26 +554,47 @@ namespace PowerLauncher.ViewModel var queryResultsTask = Task.Factory.StartNew( () => - { - Thread.Sleep(20); - - // Keep track of total number of results for telemetry - var numResults = 0; - - // Contains all the plugins for which this raw query is valid - var plugins = pluginQueryPairs.Keys.ToList(); - - var sw = System.Diagnostics.Stopwatch.StartNew(); - - try { - var resultPluginPair = new System.Collections.Concurrent.ConcurrentDictionary>(); + Thread.Sleep(20); - if (_settings.PTRunNonDelayedSearchInParallel) + // Keep track of total number of results for telemetry + var numResults = 0; + + // Contains all the plugins for which this raw query is valid + var plugins = pluginQueryPairs.Keys.ToList(); + + var sw = System.Diagnostics.Stopwatch.StartNew(); + + try { - Parallel.ForEach(pluginQueryPairs, (pluginQueryItem) => + var resultPluginPair = new System.Collections.Concurrent.ConcurrentDictionary>(); + + if (_settings.PTRunNonDelayedSearchInParallel) { - try + Parallel.ForEach(pluginQueryPairs, (pluginQueryItem) => + { + try + { + var plugin = pluginQueryItem.Key; + var query = pluginQueryItem.Value; + query.SelectedItems = _userSelectedRecord.GetGenericHistory(); + var results = PluginManager.QueryForPlugin(plugin, query); + resultPluginPair[plugin.Metadata] = results; + currentCancellationToken.ThrowIfCancellationRequested(); + } + catch (OperationCanceledException) + { + // nothing to do here + } + }); + sw.Stop(); + } + else + { + currentCancellationToken.ThrowIfCancellationRequested(); + + // To execute a query corresponding to each plugin + foreach (KeyValuePair pluginQueryItem in pluginQueryPairs) { var plugin = pluginQueryItem.Key; var query = pluginQueryItem.Value; @@ -581,64 +603,43 @@ namespace PowerLauncher.ViewModel resultPluginPair[plugin.Metadata] = results; currentCancellationToken.ThrowIfCancellationRequested(); } - catch (OperationCanceledException) - { - // nothing to do here - } - }); - sw.Stop(); - } - else - { - currentCancellationToken.ThrowIfCancellationRequested(); - - // To execute a query corresponding to each plugin - foreach (KeyValuePair pluginQueryItem in pluginQueryPairs) - { - var plugin = pluginQueryItem.Key; - var query = pluginQueryItem.Value; - query.SelectedItems = _userSelectedRecord.GetGenericHistory(); - var results = PluginManager.QueryForPlugin(plugin, query); - resultPluginPair[plugin.Metadata] = results; - currentCancellationToken.ThrowIfCancellationRequested(); } - } - lock (_addResultsLock) - { - // Using CurrentCultureIgnoreCase since this is user facing - if (queryText.Equals(_currentQuery, StringComparison.CurrentCultureIgnoreCase)) + lock (_addResultsLock) { - Results.Clear(); - foreach (var p in resultPluginPair) + // Using CurrentCultureIgnoreCase since this is user facing + if (queryText.Equals(_currentQuery, StringComparison.CurrentCultureIgnoreCase)) { - UpdateResultView(p.Value, queryText, currentCancellationToken); + Results.Clear(); + foreach (var p in resultPluginPair) + { + UpdateResultView(p.Value, queryText, currentCancellationToken); + currentCancellationToken.ThrowIfCancellationRequested(); + } + currentCancellationToken.ThrowIfCancellationRequested(); + numResults = Results.Results.Count; + if (!doFinalSort) + { + Results.Sort(queryTuning); + Results.SelectedItem = Results.Results.FirstOrDefault(); + } } currentCancellationToken.ThrowIfCancellationRequested(); - numResults = Results.Results.Count; if (!doFinalSort) { - Results.Sort(queryTuning); - Results.SelectedItem = Results.Results.FirstOrDefault(); + UpdateResultsListViewAfterQuery(queryText); } } - currentCancellationToken.ThrowIfCancellationRequested(); - if (!doFinalSort) + bool noInitialResults = numResults == 0; + + if (!delayedExecution.HasValue || delayedExecution.Value) { - UpdateResultsListViewAfterQuery(queryText); - } - } - - bool noInitialResults = numResults == 0; - - if (!delayedExecution.HasValue || delayedExecution.Value) - { - // Run the slower query of the DelayedExecution plugins - currentCancellationToken.ThrowIfCancellationRequested(); - Parallel.ForEach(plugins, (plugin) => + // Run the slower query of the DelayedExecution plugins + currentCancellationToken.ThrowIfCancellationRequested(); + Parallel.ForEach(plugins, (plugin) => { try { @@ -683,22 +684,23 @@ namespace PowerLauncher.ViewModel // nothing to do here } }); + } + } + catch (OperationCanceledException) + { + // nothing to do here } - } - catch (OperationCanceledException) - { - // nothing to do here - } - queryTimer.Stop(); - var queryEvent = new LauncherQueryEvent() - { - QueryTimeMs = queryTimer.ElapsedMilliseconds, - NumResults = numResults, - QueryLength = queryText.Length, - }; - PowerToysTelemetry.Log.WriteEvent(queryEvent); - }, currentCancellationToken); + queryTimer.Stop(); + var queryEvent = new LauncherQueryEvent() + { + QueryTimeMs = queryTimer.ElapsedMilliseconds, + NumResults = numResults, + QueryLength = queryText.Length, + }; + PowerToysTelemetry.Log.WriteEvent(queryEvent); + }, + currentCancellationToken); if (doFinalSort) { diff --git a/src/modules/poweraccent/PowerAccent.Core/Languages.cs b/src/modules/poweraccent/PowerAccent.Core/Languages.cs index 86b98b5a4e..8fbfeae0ab 100644 --- a/src/modules/poweraccent/PowerAccent.Core/Languages.cs +++ b/src/modules/poweraccent/PowerAccent.Core/Languages.cs @@ -2,12 +2,12 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; +using PowerToys.PowerAccentKeyboardService; +using Windows.Globalization; + namespace PowerAccent.Core { - using System; - using PowerToys.PowerAccentKeyboardService; - using Windows.Globalization; - public enum Language { ALL, diff --git a/src/modules/poweraccent/PowerAccent.Core/PowerAccent.cs b/src/modules/poweraccent/PowerAccent.Core/PowerAccent.cs index f9b9566b3e..28e1f4a3b0 100644 --- a/src/modules/poweraccent/PowerAccent.Core/PowerAccent.cs +++ b/src/modules/poweraccent/PowerAccent.Core/PowerAccent.cs @@ -100,7 +100,8 @@ public class PowerAccent : IDisposable { OnChangeDisplay?.Invoke(true, _characters); } - }, TaskScheduler.FromCurrentSynchronizationContext()); + }, + TaskScheduler.FromCurrentSynchronizationContext()); } private string GetCharacterDescription(string character) diff --git a/src/modules/poweraccent/PowerAccent.Core/Services/SettingsService.cs b/src/modules/poweraccent/PowerAccent.Core/Services/SettingsService.cs index 8cc5789e34..c9fd9156f4 100644 --- a/src/modules/poweraccent/PowerAccent.Core/Services/SettingsService.cs +++ b/src/modules/poweraccent/PowerAccent.Core/Services/SettingsService.cs @@ -2,16 +2,14 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace PowerAccent.Core.Services; - +using System.IO.Abstractions; +using System.Text.Json; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.Enumerations; using Microsoft.PowerToys.Settings.UI.Library.Utilities; using PowerToys.PowerAccentKeyboardService; -using System.IO.Abstractions; -using System.Text.Json; -using static Vanara.PInvoke.LANGID; +namespace PowerAccent.Core.Services; public class SettingsService { private const string PowerAccentModuleName = "QuickAccent"; diff --git a/src/modules/poweraccent/PowerAccent.Core/Tools/WindowsFunctions.cs b/src/modules/poweraccent/PowerAccent.Core/Tools/WindowsFunctions.cs index 93a34c2bd0..e5802565e0 100644 --- a/src/modules/poweraccent/PowerAccent.Core/Tools/WindowsFunctions.cs +++ b/src/modules/poweraccent/PowerAccent.Core/Tools/WindowsFunctions.cs @@ -41,7 +41,7 @@ internal static class WindowsFunctions public static Point GetCaretPosition() { - User32.GUITHREADINFO guiInfo = new (); + User32.GUITHREADINFO guiInfo = default; guiInfo.cbSize = (uint)Marshal.SizeOf(guiInfo); User32.GetGUIThreadInfo(0, ref guiInfo); POINT caretPosition = new POINT(guiInfo.rcCaret.left, guiInfo.rcCaret.top); @@ -59,12 +59,12 @@ internal static class WindowsFunctions public static (Point Location, Size Size, double Dpi) GetActiveDisplay() { - User32.GUITHREADINFO guiInfo = new (); + User32.GUITHREADINFO guiInfo = default; guiInfo.cbSize = (uint)Marshal.SizeOf(guiInfo); User32.GetGUIThreadInfo(0, ref guiInfo); var res = User32.MonitorFromWindow(guiInfo.hwndActive, User32.MonitorFlags.MONITOR_DEFAULTTONEAREST); - User32.MONITORINFO monitorInfo = new (); + User32.MONITORINFO monitorInfo = default; monitorInfo.cbSize = (uint)Marshal.SizeOf(monitorInfo); User32.GetMonitorInfo(res, ref monitorInfo); diff --git a/src/modules/poweraccent/PowerAccent.UI/Program.cs b/src/modules/poweraccent/PowerAccent.UI/Program.cs index 8c664ffba1..eee06b2038 100644 --- a/src/modules/poweraccent/PowerAccent.UI/Program.cs +++ b/src/modules/poweraccent/PowerAccent.UI/Program.cs @@ -47,7 +47,8 @@ internal static class Program { Terminate(); } - }, _tokenSource.Token); + }, + _tokenSource.Token); } private static void Arguments(string[] args) diff --git a/src/modules/poweraccent/PowerAccent.UI/Selector.xaml.cs b/src/modules/poweraccent/PowerAccent.UI/Selector.xaml.cs index acbdef457b..d243c3f20d 100644 --- a/src/modules/poweraccent/PowerAccent.UI/Selector.xaml.cs +++ b/src/modules/poweraccent/PowerAccent.UI/Selector.xaml.cs @@ -13,7 +13,7 @@ namespace PowerAccent.UI; public partial class Selector : Window, IDisposable, INotifyPropertyChanged { - private readonly Core.PowerAccent _powerAccent = new (); + private readonly Core.PowerAccent _powerAccent = new(); private Visibility _characterNameVisibility = Visibility.Visible; @@ -84,7 +84,7 @@ public partial class Selector : Window, IDisposable, INotifyPropertyChanged private void SetWindowPosition() { - Size windowSize = new (((System.Windows.Controls.Panel)Application.Current.MainWindow.Content).ActualWidth, ((System.Windows.Controls.Panel)Application.Current.MainWindow.Content).ActualHeight); + Size windowSize = new(((System.Windows.Controls.Panel)Application.Current.MainWindow.Content).ActualWidth, ((System.Windows.Controls.Panel)Application.Current.MainWindow.Content).ActualHeight); Point position = _powerAccent.GetDisplayCoordinates(windowSize); this.Left = position.X; this.Top = position.Y; @@ -97,7 +97,7 @@ public partial class Selector : Window, IDisposable, INotifyPropertyChanged Position.Left or Position.TopLeft or Position.BottomLeft => HorizontalAlignment.Left, Position.Right or Position.TopRight or Position.BottomRight => HorizontalAlignment.Right, Position.Center or Position.Top or Position.Bottom => HorizontalAlignment.Center, - _ => HorizontalAlignment.Center + _ => HorizontalAlignment.Center, }; } diff --git a/src/modules/previewpane/GcodePreviewHandler/Program.cs b/src/modules/previewpane/GcodePreviewHandler/Program.cs index ec9194fcd2..87cae336f0 100644 --- a/src/modules/previewpane/GcodePreviewHandler/Program.cs +++ b/src/modules/previewpane/GcodePreviewHandler/Program.cs @@ -2,13 +2,13 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Globalization; +using System.Windows.Threading; +using Common.UI; +using interop; + namespace Microsoft.PowerToys.PreviewHandler.Gcode { - using System.Globalization; - using System.Windows.Threading; - using Common.UI; - using interop; - internal static class Program { private static CancellationTokenSource _tokenSource = new CancellationTokenSource(); diff --git a/src/modules/previewpane/GcodeThumbnailProvider/Program.cs b/src/modules/previewpane/GcodeThumbnailProvider/Program.cs index 84bfd5dcaf..8426ca7755 100644 --- a/src/modules/previewpane/GcodeThumbnailProvider/Program.cs +++ b/src/modules/previewpane/GcodeThumbnailProvider/Program.cs @@ -2,10 +2,10 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Globalization; + namespace Microsoft.PowerToys.ThumbnailHandler.Gcode { - using System.Globalization; - internal static class Program { private static GcodeThumbnailProvider _thumbnailProvider; diff --git a/src/modules/previewpane/MarkdownPreviewHandler/Program.cs b/src/modules/previewpane/MarkdownPreviewHandler/Program.cs index 32bd6ac7fa..431afcafb1 100644 --- a/src/modules/previewpane/MarkdownPreviewHandler/Program.cs +++ b/src/modules/previewpane/MarkdownPreviewHandler/Program.cs @@ -2,13 +2,13 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Globalization; +using System.Windows.Threading; +using Common.UI; +using interop; + namespace Microsoft.PowerToys.PreviewHandler.Markdown { - using System.Globalization; - using System.Windows.Threading; - using Common.UI; - using interop; - internal static class Program { private static CancellationTokenSource _tokenSource = new CancellationTokenSource(); diff --git a/src/modules/previewpane/MonacoPreviewHandler/Formatters/JsonFormatter.cs b/src/modules/previewpane/MonacoPreviewHandler/Formatters/JsonFormatter.cs index b2b82f625d..6a9134b438 100644 --- a/src/modules/previewpane/MonacoPreviewHandler/Formatters/JsonFormatter.cs +++ b/src/modules/previewpane/MonacoPreviewHandler/Formatters/JsonFormatter.cs @@ -2,10 +2,10 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Text.Json; + namespace Microsoft.PowerToys.PreviewHandler.Monaco.Formatters { - using System.Text.Json; - public class JsonFormatter : IFormatter { /// diff --git a/src/modules/previewpane/MonacoPreviewHandler/Formatters/XmlFormatter.cs b/src/modules/previewpane/MonacoPreviewHandler/Formatters/XmlFormatter.cs index a7cb976616..6a7067e23c 100644 --- a/src/modules/previewpane/MonacoPreviewHandler/Formatters/XmlFormatter.cs +++ b/src/modules/previewpane/MonacoPreviewHandler/Formatters/XmlFormatter.cs @@ -2,11 +2,11 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Text; +using System.Xml; + namespace Microsoft.PowerToys.PreviewHandler.Monaco.Formatters { - using System.Text; - using System.Xml; - public class XmlFormatter : IFormatter { /// diff --git a/src/modules/previewpane/MonacoPreviewHandler/Program.cs b/src/modules/previewpane/MonacoPreviewHandler/Program.cs index c5d00f2725..8589b12c30 100644 --- a/src/modules/previewpane/MonacoPreviewHandler/Program.cs +++ b/src/modules/previewpane/MonacoPreviewHandler/Program.cs @@ -2,13 +2,13 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Globalization; +using System.Windows.Threading; +using Common.UI; +using interop; + namespace Microsoft.PowerToys.PreviewHandler.Monaco { - using System.Globalization; - using System.Windows.Threading; - using Common.UI; - using interop; - internal static class Program { private static CancellationTokenSource _tokenSource = new CancellationTokenSource(); diff --git a/src/modules/previewpane/PdfPreviewHandler/Program.cs b/src/modules/previewpane/PdfPreviewHandler/Program.cs index 8dadc8205e..ba8771f263 100644 --- a/src/modules/previewpane/PdfPreviewHandler/Program.cs +++ b/src/modules/previewpane/PdfPreviewHandler/Program.cs @@ -1,14 +1,13 @@ // Copyright (c) Microsoft Corporation // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Globalization; +using System.Windows.Threading; +using Common.UI; +using interop; namespace Microsoft.PowerToys.PreviewHandler.Pdf { - using System.Globalization; - using System.Windows.Threading; - using Common.UI; - using interop; - internal static class Program { private static CancellationTokenSource _tokenSource = new CancellationTokenSource(); diff --git a/src/modules/previewpane/PdfThumbnailProvider/Program.cs b/src/modules/previewpane/PdfThumbnailProvider/Program.cs index 0efbd0189e..59cf1acb99 100644 --- a/src/modules/previewpane/PdfThumbnailProvider/Program.cs +++ b/src/modules/previewpane/PdfThumbnailProvider/Program.cs @@ -2,10 +2,10 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Globalization; + namespace Microsoft.PowerToys.ThumbnailHandler.Pdf { - using System.Globalization; - internal static class Program { private static PdfThumbnailProvider _thumbnailProvider; diff --git a/src/modules/previewpane/StlThumbnailProvider/Program.cs b/src/modules/previewpane/StlThumbnailProvider/Program.cs index 79e77c8913..77e904ba1e 100644 --- a/src/modules/previewpane/StlThumbnailProvider/Program.cs +++ b/src/modules/previewpane/StlThumbnailProvider/Program.cs @@ -1,11 +1,10 @@ // Copyright (c) Microsoft Corporation // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Globalization; namespace Microsoft.PowerToys.ThumbnailHandler.Stl { - using System.Globalization; - internal static class Program { private static StlThumbnailProvider _thumbnailProvider; diff --git a/src/modules/previewpane/SvgPreviewHandler/Program.cs b/src/modules/previewpane/SvgPreviewHandler/Program.cs index f9c013b354..f1a170278e 100644 --- a/src/modules/previewpane/SvgPreviewHandler/Program.cs +++ b/src/modules/previewpane/SvgPreviewHandler/Program.cs @@ -2,13 +2,13 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Globalization; +using System.Windows.Threading; +using Common.UI; +using interop; + namespace Microsoft.PowerToys.PreviewHandler.Svg { - using System.Globalization; - using System.Windows.Threading; - using Common.UI; - using interop; - internal static class Program { private static CancellationTokenSource _tokenSource = new CancellationTokenSource(); diff --git a/src/modules/previewpane/SvgThumbnailProvider/Program.cs b/src/modules/previewpane/SvgThumbnailProvider/Program.cs index 18df99e29f..f81a8f46ce 100644 --- a/src/modules/previewpane/SvgThumbnailProvider/Program.cs +++ b/src/modules/previewpane/SvgThumbnailProvider/Program.cs @@ -2,10 +2,10 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Globalization; + namespace Microsoft.PowerToys.ThumbnailHandler.Svg { - using System.Globalization; - internal static class Program { private static SvgThumbnailProvider _thumbnailProvider; diff --git a/src/settings-ui/Settings.UI.Library/SettingsBackupAndRestoreUtils.cs b/src/settings-ui/Settings.UI.Library/SettingsBackupAndRestoreUtils.cs index c30edfdcac..eeaa0aa541 100644 --- a/src/settings-ui/Settings.UI.Library/SettingsBackupAndRestoreUtils.cs +++ b/src/settings-ui/Settings.UI.Library/SettingsBackupAndRestoreUtils.cs @@ -22,7 +22,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library public class SettingsBackupAndRestoreUtils { private static SettingsBackupAndRestoreUtils instance; - private (bool success, string severity, bool lastBackupExists, DateTime? lastRan) lastBackupSettingsResults; + private (bool Success, string Severity, bool LastBackupExists, DateTime? LastRan) lastBackupSettingsResults; private static object backupSettingsInternalLock = new object(); private static object removeOldBackupsLock = new object(); @@ -262,7 +262,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library /// A tuple that indicates if the backup was done or not, and a message. /// The message usually is a localized reference key. /// - public (bool success, string message, string severity) RestoreSettings(string appBasePath, string settingsBackupAndRestoreDir) + public (bool Success, string Message, string Severity) RestoreSettings(string appBasePath, string settingsBackupAndRestoreDir) { try { @@ -554,26 +554,26 @@ namespace Microsoft.PowerToys.Settings.UI.Library /// /// This is a wrapper for BackupSettingsInternal, so we can check the time to run. /// - public (bool success, string message, string severity, bool lastBackupExists) BackupSettings(string appBasePath, string settingsBackupAndRestoreDir, bool dryRun) + public (bool Success, string Message, string Severity, bool LastBackupExists) BackupSettings(string appBasePath, string settingsBackupAndRestoreDir, bool dryRun) { var sw = Stopwatch.StartNew(); var results = BackupSettingsInternal(appBasePath, settingsBackupAndRestoreDir, dryRun); sw.Stop(); Logger.LogInfo($"BackupSettings took {sw.ElapsedMilliseconds}"); - lastBackupSettingsResults = (results.success, results.severity, results.lastBackupExists, DateTime.UtcNow); + lastBackupSettingsResults = (results.Success, results.Severity, results.LastBackupExists, DateTime.UtcNow); return results; } /// /// Method DryRunBackup wrapper function to do a dry-run backup /// - public (bool success, string message, string severity, bool lastBackupExists) DryRunBackup() + public (bool Success, string Message, string Severity, bool LastBackupExists) DryRunBackup() { var settingsUtils = new SettingsUtils(); var appBasePath = Path.GetDirectoryName(settingsUtils.GetSettingsFilePath()); string settingsBackupAndRestoreDir = GetSettingsBackupAndRestoreDir(); var results = BackupSettings(appBasePath, settingsBackupAndRestoreDir, true); - lastBackupSettingsResults = (results.success, results.severity, results.lastBackupExists, DateTime.UtcNow); + lastBackupSettingsResults = (results.Success, results.Severity, results.LastBackupExists, DateTime.UtcNow); return results; } @@ -583,9 +583,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library /// /// A tuple that indicates if the backup was done or not, and other information /// - public (bool success, bool hadError, bool lastBackupExists, DateTime? lastRan) GetLastBackupSettingsResults() + public (bool Success, bool HadError, bool LastBackupExists, DateTime? LastRan) GetLastBackupSettingsResults() { - return (lastBackupSettingsResults.success, lastBackupSettingsResults.severity == "Error", lastBackupSettingsResults.lastBackupExists, lastBackupSettingsResults.lastRan); + return (lastBackupSettingsResults.Success, lastBackupSettingsResults.Severity == "Error", lastBackupSettingsResults.LastBackupExists, lastBackupSettingsResults.LastRan); } /// @@ -595,7 +595,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library /// A tuple that indicates if the backup was done or not, and a message. /// The message usually is a localized reference key. /// - private (bool success, string message, string severity, bool lastBackupExists) BackupSettingsInternal(string appBasePath, string settingsBackupAndRestoreDir, bool dryRun) + private (bool Success, string Message, string Severity, bool LastBackupExists) BackupSettingsInternal(string appBasePath, string settingsBackupAndRestoreDir, bool dryRun) { var lastBackupExists = false; @@ -650,7 +650,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library } var anyFileBackedUp = false; - var skippedSettingsFiles = new Dictionary(); + var skippedSettingsFiles = new Dictionary(); var updatedSettingsFiles = new Dictionary(); foreach (var currentFile in currentSettingsFiles) @@ -717,7 +717,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library { // if we did do a backup, we need to copy in all the settings files we skipped so the backup is complete. // this is needed since we might use the backup on another machine/ - var relativePath = currentFile.Value.path.Substring(appBasePath.Length + 1); + var relativePath = currentFile.Value.Path.Substring(appBasePath.Length + 1); var backupFullPath = Path.Combine(fullBackupDir, relativePath); Logger.LogInfo($"BackupSettings writing, {backupFullPath}, dryRun:{dryRun}"); @@ -726,7 +726,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library TryCreateDirectory(fullBackupDir); TryCreateDirectory(Path.GetDirectoryName(backupFullPath)); - File.WriteAllText(backupFullPath, currentFile.Value.settings); + File.WriteAllText(backupFullPath, currentFile.Value.Settings); } } diff --git a/src/settings-ui/Settings.UI.Library/SettingsUtils.cs b/src/settings-ui/Settings.UI.Library/SettingsUtils.cs index e68a967a89..e09687ff77 100644 --- a/src/settings-ui/Settings.UI.Library/SettingsUtils.cs +++ b/src/settings-ui/Settings.UI.Library/SettingsUtils.cs @@ -189,7 +189,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library /// /// Method BackupSettings Mostly a wrapper for SettingsBackupAndRestoreUtils.BackupSettings /// - public static (bool success, string message, string severity, bool lastBackupExists) BackupSettings() + public static (bool Success, string Message, string Severity, bool LastBackupExists) BackupSettings() { var settingsBackupAndRestoreUtilsX = SettingsBackupAndRestoreUtils.Instance; var settingsUtils = new SettingsUtils(); @@ -202,7 +202,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library /// /// Method RestoreSettings Mostly a wrapper for SettingsBackupAndRestoreUtils.RestoreSettings /// - public static (bool success, string message, string severity) RestoreSettings() + public static (bool Success, string Message, string Severity) RestoreSettings() { var settingsBackupAndRestoreUtilsX = SettingsBackupAndRestoreUtils.Instance; var settingsUtils = new SettingsUtils(); diff --git a/src/settings-ui/Settings.UI/GlobalSuppressions.cs b/src/settings-ui/Settings.UI/GlobalSuppressions.cs deleted file mode 100644 index f0b9b4c388..0000000000 --- a/src/settings-ui/Settings.UI/GlobalSuppressions.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft Corporation -// The Microsoft Corporation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// This file is used by Code Analysis to maintain SuppressMessage -// attributes that are applied to this project. -// Project-level suppressions either have no target or are given -// a specific target and scoped to a namespace, type, member, etc. -using System.Diagnostics.CodeAnalysis; - -[assembly: SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1009:ClosingParenthesisMustBeSpacedCorrectly", Justification = "All current violations are due to Tuple shorthand and so valid.")] - -[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:PrefixLocalCallsWithThis", Justification = "We follow the C# Core Coding Style which avoids using `this` unless absolutely necessary.")] - -[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1200:UsingDirectivesMustBePlacedWithinNamespace", Justification = "We follow the C# Core Coding Style which puts using statements outside the namespace.")] -[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1201:ElementsMustAppearInTheCorrectOrder", Justification = "It is not a priority and have hight impact in code changes.")] -[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1202:ElementsMustBeOrderedByAccess", Justification = "It is not a priority and have hight impact in code changes.")] -[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1203:ConstantsMustAppearBeforeFields", Justification = "It is not a priority and have hight impact in code changes.")] -[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1204:StaticElementsMustAppearBeforeInstanceElements", Justification = "It is not a priority and have hight impact in code changes.")] - -[assembly: SuppressMessage("StyleCop.CSharp.NamingRules", "SA1309:FieldNamesMustNotBeginWithUnderscore", Justification = "We follow the C# Core Coding Style which uses underscores as prefixes rather than using `this.`.")] - -[assembly: SuppressMessage("StyleCop.CSharp.SpecialRules", "SA0001:XmlCommentAnalysisDisabled", Justification = "Not enabled as we don't want or need XML documentation.")] -[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1629:DocumentationTextMustEndWithAPeriod", Justification = "Not enabled as we don't want or need XML documentation.")] - -// Non general suppressions -[assembly: SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Used in a lot of places for meaningful method names")] -[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Static methods may improve performance but decrease maintainability")] -[assembly: SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "Renaming everything would be a lot of work. It does not do any harm if an EventHandler delegate ends with the suffix EventHandler. Besides this, the Rule causes some false positives.")] -[assembly: SuppressMessage("Performance", "CA1838:Avoid 'StringBuilder' parameters for P/Invokes", Justification = "We are not concerned about the performance impact of marshaling a StringBuilder")] diff --git a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs index 7d066af3c1..e7447ed1c9 100644 --- a/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs @@ -418,16 +418,16 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels var resultText = string.Empty; - if (!results.lastRan.HasValue) + if (!results.LastRan.HasValue) { // not ran since started. return GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsNoChecked"); // "Current Settings Unknown"; } else { - if (results.success) + if (results.Success) { - if (results.lastBackupExists) + if (results.LastBackupExists) { // if true, it means a backup would have been made resultText = GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsDiffer"); // "Current Settings Differ"; @@ -440,7 +440,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels } else { - if (results.hadError) + if (results.HadError) { // if false and error we don't really know resultText = GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsUnknown"); // "Current Settings Unknown"; @@ -452,7 +452,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels } } - return $"{resultText} {GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsStatusAt")} {results.lastRan.Value.ToLocalTime().ToString("G", CultureInfo.CurrentCulture)}"; + return $"{resultText} {GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsStatusAt")} {results.LastRan.Value.ToLocalTime().ToString("G", CultureInfo.CurrentCulture)}"; } } catch (Exception e) @@ -683,13 +683,13 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels } var results = SettingsUtils.RestoreSettings(); - _backupRestoreMessageSeverity = results.severity; + _backupRestoreMessageSeverity = results.Severity; - if (!results.success) + if (!results.Success) { _settingsBackupRestoreMessageVisible = true; - _settingsBackupMessage = GetResourceString(results.message); + _settingsBackupMessage = GetResourceString(results.Message); NotifyAllBackupAndRestoreProperties(); @@ -720,8 +720,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels var results = SettingsUtils.BackupSettings(); _settingsBackupRestoreMessageVisible = true; - _backupRestoreMessageSeverity = results.severity; - _settingsBackupMessage = GetResourceString(results.message); + _backupRestoreMessageSeverity = results.Severity; + _settingsBackupMessage = GetResourceString(results.Message); // now we do a dry run to get the results for "setting match" var settingsUtils = new SettingsUtils();