Skip to content

Commit 774bd81

Browse files
authored
Update dev analyzers; fix some findings (apache#1168, apache#924, apache#1211, apache#1097) (apache#1294)
* Upgrade CodeAnalysis.Dev to 1.0.0-alpha.34 * Upgrade CodeAnalysis.Dev to 1.0.0-alpha.36 * Suppress noisy rules for now * Fix LuceneDev6001 errors * Fix LuceneDev4001 and LuceneDev6003 warnings
1 parent ffbfb36 commit 774bd81

7 files changed

Lines changed: 21 additions & 8 deletions

File tree

.build/dependencies.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<!-- J2N will break binary compatibility in 3.0.0 to fix the APIs of collection types -->
4141
<J2NPackageVersion>[2.2.0-alpha-0042, 3.0.0)</J2NPackageVersion>
4242
<LiquidTestReportsMarkdownPackageVersion>1.0.9</LiquidTestReportsMarkdownPackageVersion>
43-
<LuceneNetCodeAnalysisDevPackageVersion>1.0.0-alpha.18</LuceneNetCodeAnalysisDevPackageVersion>
43+
<LuceneNetCodeAnalysisDevPackageVersion>1.0.0-alpha.36</LuceneNetCodeAnalysisDevPackageVersion>
4444
<MicrosoftAspNetCoreHttpAbstractionsPackageVersion>2.3.0</MicrosoftAspNetCoreHttpAbstractionsPackageVersion>
4545
<MicrosoftAspNetCoreTestHostPackageVersion>8.0.19</MicrosoftAspNetCoreTestHostPackageVersion>
4646
<MicrosoftBclMemoryPackageVersion>10.0.0-rc.1.25451.107</MicrosoftBclMemoryPackageVersion>

Directory.Build.targets

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@
3131
<NoWarn Label="Java array parameters can sometimes be replaced with .NET out or ref parameters">$(NoWarn);LuceneDev1003</NoWarn>
3232
<NoWarn Label="Return array may be able to be replaced with out values">$(NoWarn);LuceneDev1004</NoWarn>
3333
<NoWarn Label="Floating point values embedded in strings should be formatted with J2N.Numerics Single or Double ToString methods">$(NoWarn);LuceneDev1006</NoWarn>
34+
<NoWarn Label="Generic Dictionary indexer '...' may throw KeyNotFoundException. Use TryGetValue instead.">$(NoWarn);LuceneDev1007</NoWarn>
35+
<NoWarn Label="Generic Dictionary indexer '...' may throw KeyNotFoundException. Use TryGetValue and check the value for null.">$(NoWarn);LuceneDev1008</NoWarn>
36+
<NoWarn Label="Call to 'Parse' on numeric type 'Single' should specify an IFormatProvider (typically CultureInfo.InvariantCulture).">$(NoWarn);LuceneDev2000</NoWarn>
37+
<NoWarn Label="Call to 'ToString' on numeric type 'Int64' should specify an IFormatProvider (typically CultureInfo.InvariantCulture).">$(NoWarn);LuceneDev2001</NoWarn>
38+
<NoWarn Label="Call to 'Convert.ToString' should specify an IFormatProvider (typically CultureInfo.InvariantCulture).">$(NoWarn);LuceneDev2002</NoWarn>
39+
<NoWarn Label="Call to 'string.Format' with a numeric argument should specify an IFormatProvider (typically CultureInfo.InvariantCulture).">$(NoWarn);LuceneDev2003</NoWarn>
40+
<NoWarn Label="Call to 'TryParse' on J2N numeric type 'Int32' should specify an IFormatProvider (typically CultureInfo.InvariantCulture).">$(NoWarn);LuceneDev2004</NoWarn>
41+
<NoWarn Label="Numeric value of type 'Int32' is concatenated to a string and will be formatted using the current culture. Wrap with .ToString(CultureInfo.InvariantCulture) explicitly.">$(NoWarn);LuceneDev2005</NoWarn>
42+
<NoWarn Label="Numeric value of type 'Int32' is interpolated into a string and will be formatted using the current culture. Use FormattableString.Invariant or wrap with .ToString(CultureInfo.InvariantCulture) explicitly.">$(NoWarn);LuceneDev2006</NoWarn>
43+
<NoWarn Label="Call to 'Parse' passes a non-invariant IFormatProvider. Use CultureInfo.InvariantCulture unless current-culture behavior is intentional.">$(NoWarn);LuceneDev2007</NoWarn>
3444

3545
</PropertyGroup>
3646

src/Lucene.Net.Analysis.Common/Analysis/Util/StemmerUtil.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static bool StartsWith(ReadOnlySpan<char> s, ReadOnlySpan<char> prefix)
7878
}
7979

8080
// LUCENENET: use more efficient implementation in MemoryExtensions
81-
return s.StartsWith(prefix, StringComparison.Ordinal);
81+
return s.StartsWith(prefix);
8282
}
8383

8484
/// <summary>
@@ -147,7 +147,7 @@ public static bool EndsWith(ReadOnlySpan<char> s, ReadOnlySpan<char> suffix)
147147
}
148148

149149
// LUCENENET: use more efficient implementation in MemoryExtensions
150-
return s.EndsWith(suffix, StringComparison.Ordinal);
150+
return s.EndsWith(suffix);
151151
}
152152

153153
/// <summary>

src/Lucene.Net.TestFramework/Support/Util/NUnitTestFixtureBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ internal static bool CanImplicitlyConvertTo(this Type from, Type to)
420420
return true;
421421

422422
// Look for the marker that indicates from was null
423-
if (from is null && (to.GetTypeInfo().IsClass || to.FullName.StartsWith("System.Nullable")))
423+
if (from is null && (to.GetTypeInfo().IsClass || to.FullName.StartsWith("System.Nullable", StringComparison.Ordinal)))
424424
return true;
425425

426426
if (convertibleValueTypes.ContainsKey(to) && convertibleValueTypes[to].Contains(from))

src/Lucene.Net.Tests.Highlighter/VectorHighlight/BreakIteratorBoundaryScannerTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ public void TestICUSentenceBoundary()
9494
BreakIterator bi = BreakIterator.GetSentenceInstance(CultureInfo.CurrentCulture);
9595
IBoundaryScanner scanner = new BreakIteratorBoundaryScanner(bi);
9696

97-
int start = TEXT.IndexOf("any application");
98-
int expected = TEXT.IndexOf("It is a");
97+
int start = TEXT.IndexOf("any application", StringComparison.Ordinal);
98+
int expected = TEXT.IndexOf("It is a", StringComparison.Ordinal);
9999
TestFindStartOffset(text, start, expected, scanner);
100100

101-
expected = TEXT.IndexOf("application that requires") + "application that requires\n".Length;
101+
expected = TEXT.IndexOf("application that requires", StringComparison.Ordinal) + "application that requires\n".Length;
102102
TestFindEndOffset(text, start, expected, scanner);
103103
}
104104

src/Lucene.Net.Tests/Support/TestHelpers.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,9 @@ public enum TestEnum
321321
E4,
322322
}
323323

324+
#pragma warning disable LuceneDev4001
324325
[MethodImpl(MethodImplOptions.NoInlining)]
326+
#pragma warning restore LuceneDev4001
325327
public static void DoNotIgnore<T>(T value, int consumed)
326328
{
327329
}

src/dotnet/Lucene.Net.Tests.CodeAnalysis/Verifiers/DiagnosticVerifier.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.Linq;
77
using System.Text;
8+
using System;
89

910
namespace TestHelper
1011
{
@@ -260,7 +261,7 @@ private static string FormatDiagnostics(DiagnosticAnalyzer analyzer, params Diag
260261
Assert.IsTrue(location.IsInSource,
261262
$"Test base does not currently handle diagnostics in metadata locations. Diagnostic in metadata: {diagnostics[i]}\r\n");
262263

263-
string resultMethodName = diagnostics[i].Location.SourceTree.FilePath.EndsWith(".cs") ? "GetCSharpResultAt" : "GetBasicResultAt";
264+
string resultMethodName = diagnostics[i].Location.SourceTree.FilePath.EndsWith(".cs", StringComparison.OrdinalIgnoreCase) ? "GetCSharpResultAt" : "GetBasicResultAt";
264265
var linePosition = diagnostics[i].Location.GetLineSpan().StartLinePosition;
265266

266267
builder.AppendFormat("{0}({1}, {2}, {3}.{4})",

0 commit comments

Comments
 (0)