mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
[Analyzers] Update StyleCop and enable SA1200 (#22707)
* update StyleCop and enable SA1200 * Fix merge issues * fix build and added using rule
This commit is contained in:
committed by
GitHub
parent
617150cf50
commit
6d138e80fb
@@ -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.
|
||||
/// </returns>
|
||||
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
|
||||
/// <remarks>
|
||||
/// This is a wrapper for BackupSettingsInternal, so we can check the time to run.
|
||||
/// </remarks>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method <c>DryRunBackup</c> wrapper function to do a dry-run backup
|
||||
/// </summary>
|
||||
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
|
||||
/// <returns>
|
||||
/// A tuple that indicates if the backup was done or not, and other information
|
||||
/// </returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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.
|
||||
/// </returns>
|
||||
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<string, (string path, string settings)>();
|
||||
var skippedSettingsFiles = new Dictionary<string, (string Path, string Settings)>();
|
||||
var updatedSettingsFiles = new Dictionary<string, string>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -189,7 +189,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
/// <summary>
|
||||
/// Method <c>BackupSettings</c> Mostly a wrapper for SettingsBackupAndRestoreUtils.BackupSettings
|
||||
/// </summary>
|
||||
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
|
||||
/// <summary>
|
||||
/// Method <c>RestoreSettings</c> Mostly a wrapper for SettingsBackupAndRestoreUtils.RestoreSettings
|
||||
/// </summary>
|
||||
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();
|
||||
|
||||
@@ -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")]
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user