Skip to content

Commit c15d0ab

Browse files
[RGen] Update string strategy to fail on empty selectors. (#23646)
Do not allow selectors to be null or empty.
2 parents c7b89e7 + db1d4ec commit c15d0ab

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

src/rgen/Microsoft.Macios.Bindings.Analyzer/Validators/ExportMethodAttributeValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ internal static bool FlagsAreValid (ExportMethod exportData, RootContext context
231231
/// <returns><c>true</c> if the data is valid; otherwise, <c>false</c>.</returns>
232232
internal static bool SelectorIsNotNull (string? selector, RootContext context, out ImmutableArray<Diagnostic> diagnostics,
233233
Location? location = null)
234-
=> StringStrategies.IsNotNull (
234+
=> StringStrategies.IsNotNullOrEmpty (
235235
selector: selector,
236236
descriptor: RBI0022, // A export property must have a selector defined
237237
diagnostics: out diagnostics,

src/rgen/Microsoft.Macios.Bindings.Analyzer/Validators/ExportPropertyAttributeValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ExportPropertyAttributeValidator : Validator<ExportData<Property>> {
2525
/// <returns><c>true</c> if the data is valid; otherwise, <c>false</c>.</returns>
2626
internal static bool SelectorIsNotNull (string? selector, RootContext context, out ImmutableArray<Diagnostic> diagnostics,
2727
Location? location = null)
28-
=> StringStrategies.IsNotNull (
28+
=> StringStrategies.IsNotNullOrEmpty (
2929
selector: selector,
3030
descriptor: RBI0018, // A export property must have a selector defined
3131
diagnostics: out diagnostics,

src/rgen/Microsoft.Macios.Bindings.Analyzer/Validators/FieldValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class FieldValidator : Validator<Property> {
2525
/// <returns><c>true</c> if the selector is not null or empty; otherwise, <c>false</c>.</returns>
2626
internal static bool SelectorIsNotNull (string? selector, RootContext context, out ImmutableArray<Diagnostic> diagnostics,
2727
Location? location = null)
28-
=> StringStrategies.IsNotNull (
28+
=> StringStrategies.IsNotNullOrEmpty (
2929
selector: selector,
3030
descriptor: RBI0018, // A export property must have a selector defined
3131
diagnostics: out diagnostics,

src/rgen/Microsoft.Macios.Bindings.Analyzer/Validators/StringStrategies.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ public static class StringStrategies {
1717
/// <param name="diagnostics">When this method returns, contains an array of diagnostics if the data is invalid; otherwise, an empty array.</param>
1818
/// <param name="location">The code location to be used for the diagnostics.</param>
1919
/// <returns><c>true</c> if the data is valid; otherwise, <c>false</c>.</returns>
20-
internal static bool IsNotNull (string? selector, DiagnosticDescriptor descriptor, out ImmutableArray<Diagnostic> diagnostics,
20+
internal static bool IsNotNullOrEmpty (string? selector, DiagnosticDescriptor descriptor, out ImmutableArray<Diagnostic> diagnostics,
2121
Location? location = null)
2222
{
2323
diagnostics = ImmutableArray<Diagnostic>.Empty;
24-
if (selector is not null)
24+
if (!string.IsNullOrEmpty (selector))
2525
return true;
2626
diagnostics = [
2727
Diagnostic.Create (

tests/rgen/Microsoft.Macios.Bindings.Analyzer.Tests/Validators/FieldValidatorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public void ValidateValidFieldPropertyTests ()
154154

155155
[Theory]
156156
[InlineData ("validSelector", true, 0)]
157-
[InlineData ("", true, 0)]
157+
[InlineData ("", false, 1)]
158158
[InlineData (null, false, 1)]
159159
[InlineData ("another_valid_selector", true, 0)]
160160
[InlineData ("valid123", true, 0)]

0 commit comments

Comments
 (0)