in theory this fixes all SA1649 issues now with any project with stylecop enabled (#5786)

This commit is contained in:
Clint Rutkas
2020-08-07 11:56:28 -07:00
committed by GitHub
parent 34c3b50b48
commit ada42f6e94
12 changed files with 157 additions and 169 deletions

View File

@@ -1,27 +1,25 @@
// Copyright (c) Microsoft Corporation // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib namespace Microsoft.PowerToys.Settings.UI.Lib
{ {
#pragma warning disable SA1649 // File name should match first type name public class GenericProperty<T>
{
public class GenericProperty<T> [JsonPropertyName("value")]
{ public T Value { get; set; }
[JsonPropertyName("value")]
public T Value { get; set; } public GenericProperty(T value)
{
public GenericProperty(T value) Value = value;
{ }
Value = value;
} // Added a parameterless constructor because of an exception during deserialization. More details here: https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-how-to#deserialization-behavior
public GenericProperty()
// Added a parameterless constructor because of an exception during deserialization. More details here: https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-how-to#deserialization-behavior {
public GenericProperty() }
{ }
} }
}
}

View File

@@ -4,8 +4,6 @@
using System.Text.Json; using System.Text.Json;
#pragma warning disable SA1649 // File name should match first type name
namespace Microsoft.PowerToys.Settings.UI.Lib namespace Microsoft.PowerToys.Settings.UI.Lib
{ {
// Represents a powertoys module settings setnt to the runner. // Represents a powertoys module settings setnt to the runner.

View File

@@ -103,7 +103,7 @@
<Compile Include="Helpers\IThrottledActionInvoker.cs" /> <Compile Include="Helpers\IThrottledActionInvoker.cs" />
<Compile Include="Helpers\ThrottledActionInvoker.cs" /> <Compile Include="Helpers\ThrottledActionInvoker.cs" />
<Compile Include="Settings\IUserSettings.cs" /> <Compile Include="Settings\IUserSettings.cs" />
<Compile Include="Settings\SettingItem.cs" /> <Compile Include="Settings\SettingItem`1.cs" />
<Compile Include="Settings\UserSettings.cs" /> <Compile Include="Settings\UserSettings.cs" />
<Compile Include="Telemetry\ColorPickerCancelledEvent.cs" /> <Compile Include="Telemetry\ColorPickerCancelledEvent.cs" />
<Compile Include="Telemetry\ColorPickerShowEvent.cs" /> <Compile Include="Telemetry\ColorPickerShowEvent.cs" />

View File

@@ -6,7 +6,6 @@ using System.ComponentModel;
namespace ColorPicker.Settings namespace ColorPicker.Settings
{ {
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:File name should match first type name", Justification = "Generic, file is named correctly")]
public sealed class SettingItem<T> : INotifyPropertyChanged public sealed class SettingItem<T> : INotifyPropertyChanged
{ {
private T _value; private T _value;

View File

@@ -16,7 +16,6 @@ namespace Wox.Infrastructure.Storage
/// Storage object using binary data /// Storage object using binary data
/// Normally, it has better performance, but not readable /// Normally, it has better performance, but not readable
/// </summary> /// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:File name should match first type name", Justification = "Generic, file is named correctly")]
public class BinaryStorage<T> : IStorage<T> public class BinaryStorage<T> : IStorage<T>
{ {
// This storage helper returns whether or not to delete the binary storage items // This storage helper returns whether or not to delete the binary storage items

View File

@@ -1,22 +1,21 @@
// Copyright (c) Microsoft Corporation // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System.Collections.Generic; using System.Collections.Generic;
namespace Wox.Infrastructure.Storage namespace Wox.Infrastructure.Storage
{ {
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:File name should match first type name", Justification = "Generic, file is named correctly")] public interface IRepository<T>
public interface IRepository<T> {
{ void Add(T insertedItem);
void Add(T insertedItem);
void Remove(T removedItem);
void Remove(T removedItem);
bool Contains(T item);
bool Contains(T item);
void Set(IList<T> list);
void Set(IList<T> list);
bool Any();
bool Any(); }
} }
}

View File

@@ -1,23 +1,22 @@
// Copyright (c) Microsoft Corporation // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace Wox.Infrastructure.Storage namespace Wox.Infrastructure.Storage
{ {
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:File name should match first type name", Justification = "Generic, file is named correctly")] public interface IStorage<T>
public interface IStorage<T> {
{ /// <summary>
/// <summary> /// Saves the data
/// Saves the data /// </summary>
/// </summary> /// <param name="data">data to be saved</param>
/// <param name="data">data to be saved</param> void Save(T data);
void Save(T data);
/// <summary>
/// <summary> /// Attempts to load data, otherwise it will return the default provided
/// Attempts to load data, otherwise it will return the default provided /// </summary>
/// </summary> /// <param name="defaultData">default data value</param>
/// <param name="defaultData">default data value</param> /// <returns>The loaded data or default</returns>
/// <returns>The loaded data or default</returns> T TryLoad(T defaultData);
T TryLoad(T defaultData); }
} }
}

View File

@@ -13,7 +13,6 @@ namespace Wox.Infrastructure.Storage
/// <summary> /// <summary>
/// Serialize object using json format. /// Serialize object using json format.
/// </summary> /// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:File name should match first type name", Justification = "Generic, file is named correctly")]
public class JsonStorage<T> public class JsonStorage<T>
{ {
private readonly JsonSerializerSettings _serializerSettings; private readonly JsonSerializerSettings _serializerSettings;

View File

@@ -1,89 +1,88 @@
// Copyright (c) Microsoft Corporation // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Wox.Infrastructure.Logger; using Wox.Infrastructure.Logger;
namespace Wox.Infrastructure.Storage namespace Wox.Infrastructure.Storage
{ {
/// <summary> /// <summary>
/// The intent of this class is to provide a basic subset of 'list' like operations, without exposing callers to the internal representation /// The intent of this class is to provide a basic subset of 'list' like operations, without exposing callers to the internal representation
/// of the data structure. Currently this is implemented as a list for it's simplicity. /// of the data structure. Currently this is implemented as a list for it's simplicity.
/// </summary> /// </summary>
/// <typeparam name="T">typeof</typeparam> /// <typeparam name="T">typeof</typeparam>
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:File name should match first type name", Justification = "Generic, file is named correctly")] public class ListRepository<T> : IRepository<T>, IEnumerable<T>
public class ListRepository<T> : IRepository<T>, IEnumerable<T> {
{ public IList<T> Items { get { return _items.Values.ToList(); } }
public IList<T> Items { get { return _items.Values.ToList(); } }
private ConcurrentDictionary<int, T> _items = new ConcurrentDictionary<int, T>();
private ConcurrentDictionary<int, T> _items = new ConcurrentDictionary<int, T>();
public ListRepository()
public ListRepository() {
{ }
}
public void Set(IList<T> items)
public void Set(IList<T> items) {
{ // enforce that internal representation
// enforce that internal representation try
try {
{ _items = new ConcurrentDictionary<int, T>(items.ToDictionary(i => i.GetHashCode()));
_items = new ConcurrentDictionary<int, T>(items.ToDictionary(i => i.GetHashCode())); }
} catch (ArgumentException e)
catch (ArgumentException e) {
{ Log.Info($"|LisRepository.Set| Trying to insert a duplicate item", e.Message);
Log.Info($"|LisRepository.Set| Trying to insert a duplicate item", e.Message); }
} }
}
public bool Any()
public bool Any() {
{ return _items.Any();
return _items.Any(); }
}
public void Add(T insertedItem)
public void Add(T insertedItem) {
{ if (!_items.TryAdd(insertedItem.GetHashCode(), insertedItem))
if (!_items.TryAdd(insertedItem.GetHashCode(), insertedItem)) {
{ Log.Error($"|ListRepository.Add| Item Already Exists <{insertedItem}>");
Log.Error($"|ListRepository.Add| Item Already Exists <{insertedItem}>"); }
} }
}
public void Remove(T removedItem)
public void Remove(T removedItem) {
{ if (!_items.TryRemove(removedItem.GetHashCode(), out _))
if (!_items.TryRemove(removedItem.GetHashCode(), out _)) {
{ Log.Error($"|ListRepository.Remove| Item Not Found <{removedItem}>");
Log.Error($"|ListRepository.Remove| Item Not Found <{removedItem}>"); }
} }
}
public ParallelQuery<T> AsParallel()
public ParallelQuery<T> AsParallel() {
{ return _items.Values.AsParallel();
return _items.Values.AsParallel(); }
}
public bool Contains(T item)
public bool Contains(T item) {
{ return _items.ContainsKey(item.GetHashCode());
return _items.ContainsKey(item.GetHashCode()); }
}
public IEnumerator<T> GetEnumerator()
public IEnumerator<T> GetEnumerator() {
{ return _items.Values.GetEnumerator();
return _items.Values.GetEnumerator(); }
}
IEnumerator IEnumerable.GetEnumerator()
IEnumerator IEnumerable.GetEnumerator() {
{ return _items.GetEnumerator();
return _items.GetEnumerator(); }
}
public int Count()
public int Count() {
{ return _items.Count;
return _items.Count; }
} }
} }
}

View File

@@ -6,7 +6,6 @@ using System.IO;
namespace Wox.Infrastructure.Storage namespace Wox.Infrastructure.Storage
{ {
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:File name should match first type name", Justification = "Generic, file is named correctly")]
public class PluginJsonStorage<T> : JsonStorage<T> where T : new() public class PluginJsonStorage<T> : JsonStorage<T> where T : new()
{ {
public PluginJsonStorage() public PluginJsonStorage()

View File

@@ -6,7 +6,6 @@ using System.IO;
namespace Wox.Infrastructure.Storage namespace Wox.Infrastructure.Storage
{ {
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:File name should match first type name", Justification = "Generic, file is named correctly")]
public class WoxJsonStorage<T> : JsonStorage<T> where T : new() public class WoxJsonStorage<T> : JsonStorage<T> where T : new()
{ {
public WoxJsonStorage() public WoxJsonStorage()