[Wox.Infrastructure] Enable analyzer and fix warnings (#16996)

This commit is contained in:
CleanCodeDeveloper
2022-03-14 16:44:17 +01:00
committed by GitHub
parent 7365ba14d0
commit 561882c2f1
7 changed files with 15 additions and 10 deletions

View File

@@ -28,7 +28,7 @@ namespace Wox.Infrastructure
{
if (obj == null)
{
throw new NullReferenceException();
throw new ArgumentNullException(nameof(obj));
}
else
{
@@ -40,7 +40,7 @@ namespace Wox.Infrastructure
{
if (obj == null)
{
throw new NullReferenceException();
throw new ArgumentNullException(nameof(obj));
}
}

View File

@@ -16,9 +16,9 @@ namespace Wox.Infrastructure.Image
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Suppressing this to enable FxCop. We are logging the exception, and going forward general exceptions should not be caught")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA5350:Do Not Use Weak Cryptographic Algorithms", Justification = "Level of protection needed for the image data does not require a security guarantee")]
public string GetHashFromImage(ImageSource imageSource)
public string GetHashFromImage(ImageSource image)
{
if (!(imageSource is BitmapSource image))
if (!(image is BitmapSource bitmapSource))
{
return null;
}
@@ -30,7 +30,7 @@ namespace Wox.Infrastructure.Image
// PngBitmapEncoder enc2 = new PngBitmapEncoder();
// enc2.Frames.Add(BitmapFrame.Create(tt));
var enc = new JpegBitmapEncoder();
var bitmapFrame = BitmapFrame.Create(image);
var bitmapFrame = BitmapFrame.Create(bitmapSource);
bitmapFrame.Freeze();
enc.Frames.Add(bitmapFrame);
enc.Save(outStream);

View File

@@ -123,7 +123,7 @@ namespace Wox.Infrastructure.Image
return hBitmap;
}
throw new COMException($"Error while extracting thumbnail for {fileName}", Marshal.GetExceptionForHR((int)hr));
throw new InvalidComObjectException($"Error while extracting thumbnail for {fileName}", Marshal.GetExceptionForHR((int)hr));
}
}
}

View File

@@ -29,12 +29,12 @@ namespace Wox.Infrastructure.Storage
{
}
public void SetList(IList<T> items)
public void SetList(IList<T> list)
{
// enforce that internal representation
try
{
_items = new ConcurrentDictionary<int, T>(items.ToDictionary(i => i.GetHashCode()));
_items = new ConcurrentDictionary<int, T>(list.ToDictionary(i => i.GetHashCode()));
}
catch (ArgumentException e)
{

View File

@@ -99,7 +99,7 @@ namespace Wox.Infrastructure.Storage
suffix = jsonSuffix;
}
string filePath = associatedFilePath.Substring(0, associatedFilePath.Length - suffix.Length) + "_version.txt";
string filePath = string.Concat(associatedFilePath.AsSpan(0, associatedFilePath.Length - suffix.Length), "_version.txt");
return filePath;
}

View File

@@ -101,7 +101,9 @@ namespace Wox.Infrastructure
{
var fullStringToCompare = fullStringToCompareWithoutCase[compareStringIndex].ToString();
var querySubstring = currentQuerySubstring[currentQuerySubstringCharacterIndex].ToString();
#pragma warning disable CA1309 // Use ordinal string comparison (We are looking for a fuzzy match here)
compareResult = string.Compare(fullStringToCompare, querySubstring, CultureInfo.CurrentCulture, CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace) != 0;
#pragma warning restore CA1309 // Use ordinal string comparison
}
else
{
@@ -262,12 +264,13 @@ namespace Wox.Infrastructure
}
}
// Using CurrentCultureIgnoreCase since this relates to queries input by user
#pragma warning disable CA1309 // Use ordinal string comparison (Using CurrentCultureIgnoreCase since this relates to queries input by user)
if (string.Equals(query, stringToCompare, StringComparison.CurrentCultureIgnoreCase))
{
var bonusForExactMatch = 10;
score += bonusForExactMatch;
}
#pragma warning restore CA1309 // Use ordinal string comparison
return score;
}

View File

@@ -13,6 +13,8 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<Platforms>x64</Platforms>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisMode>Recommended</AnalysisMode>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">