NehanPathan opened a new issue, #1211: URL: https://github.com/apache/lucenenet/issues/1211
### Is there an existing issue for this? - [x] I have searched the existing issues ### Is your feature request related to a problem? Please describe the problem. Currently, calls to StartsWith(), EndsWith(), IndexOf(), and LastIndexOf() on string, Span<char>, ReadOnlySpan<char>, Memory<char>, and ReadOnlyMemory<char> may be made without explicitly specifying StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase. This can lead to subtle bugs due to culture-sensitive comparisons. Additionally, single-character string arguments are sometimes used instead of char overloads, which is less efficient. The project also has custom types like J2N.Text.StringBuilderExtensions, OpenStringBuilder, and ValueStringBuilder that need similar enforcement. ### Describe the solution you'd like Create new Roslyn analyzers for Lucene.NET that enforce the following rules: 1. **String overloads** must be called with `StringComparison.Ordinal` or `StringComparison.OrdinalIgnoreCase`. Violation should emit a compiler error. 2. **Span overloads** should only be called with `StringComparison.Ordinal` or `StringComparison.OrdinalIgnoreCase` when applicable. Violation should emit a compiler warning. 3. **Single-character strings** should use the `char` overload of `StartsWith/EndsWith/IndexOf/LastIndexOf`. Violation should emit an informational diagnostic. 4. The rules should also apply to `J2N.Text.StringBuilderExtensions`, `OpenStringBuilder`, and `ValueStringBuilder`. Each analyzer should include: * Unit tests * Sample usage in `Lucene.Net.CodeAnalysis.Sample` for IDE/live testing * Proper diagnostic ID assignment in `DiagnosticCategoryAndIdRanges.txt` * Entries in `AnalyzerReleases.Unshipped.md` Alternative solutions considered: * Using existing analyzers (SonarCloud or Microsoft analyzers) is insufficient because they don’t fully handle all custom types and escaped characters in single-character strings. ### Additional context This task aligns with Lucene.NET’s goal to enforce safe and consistent API usage while maintaining performance and .NET best practices. Proper analyzers will help contributors avoid subtle bugs and improve code quality. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
