Skip to content

Commit 004505d

Browse files
mandel-macaqueGitHub Actions Autoformatter
andauthored
[RGen] Add analyzer rules for async methods in a class. (#23774)
Ensure that: 1. If a method can be async, that is marked as such (warning). 2. Make sure marked async methods return void (error). 3. Make sure marked async methods have a delegate (error). 4. Make sure that Async methods have diff async names if the parameters are the same (error). The tests showed a number of bugs in the async generation when we use the async flag with no parameters. Those got fixed. --------- Co-authored-by: GitHub Actions Autoformatter <[email protected]>
1 parent 97d260a commit 004505d

File tree

8 files changed

+679
-6
lines changed

8 files changed

+679
-6
lines changed

src/rgen/Microsoft.Macios.Bindings.Analyzer/Resources.Designer.cs

Lines changed: 135 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rgen/Microsoft.Macios.Bindings.Analyzer/Resources.resx

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,4 +469,69 @@
469469
<value>Duplicate selector</value>
470470
</data>
471471

472+
<!-- RBI0035 -->
473+
474+
<data name="RBI0035Description" xml:space="preserve">
475+
<value>A method marked as an async method should have void as its return type.</value>
476+
</data>
477+
<data name="RBI0035MessageFormat" xml:space="preserve">
478+
<value>The method '{0}' was marked as async but its return type is not void</value>
479+
<comment>{0} is the name of the method.</comment>
480+
</data>
481+
<data name="RBI0035Title" xml:space="preserve">
482+
<value>Async method not returning void</value>
483+
</data>
484+
485+
<!-- RBI0036 -->
486+
487+
<data name="RBI0036Description" xml:space="preserve">
488+
<value>A method marked as an async method should have at least one parameter that is a delegate.</value>
489+
</data>
490+
<data name="RBI0036MessageFormat" xml:space="preserve">
491+
<value>The method '{0}' was marked as async but has 0 parameters when at least a single delegate parameter is required</value>
492+
<comment>{0} is the name of the method.</comment>
493+
</data>
494+
<data name="RBI0036Title" xml:space="preserve">
495+
<value>No parameters in async method</value>
496+
</data>
497+
498+
<!-- RBI0037 -->
499+
500+
<data name="RBI0037Description" xml:space="preserve">
501+
<value>A method marked as an async method should have its last parameter be a delegate.</value>
502+
</data>
503+
<data name="RBI0037MessageFormat" xml:space="preserve">
504+
<value>The method '{0}' was marked as async but its last parameter is not a delegate</value>
505+
<comment>{0} is the name of the method.</comment>
506+
</data>
507+
<data name="RBI0037Title" xml:space="preserve">
508+
<value>Last parameter is not a delegate</value>
509+
</data>
510+
511+
<!-- RBI0038 -->
512+
513+
<data name="RBI0038Description" xml:space="preserve">
514+
<value>A method that could be async was not marked as async.</value>
515+
</data>
516+
<data name="RBI0038MessageFormat" xml:space="preserve">
517+
<value>The method '{0}' was not marked as async but it can be</value>
518+
<comment>{0} is the name of the method.</comment>
519+
</data>
520+
<data name="RBI0038Title" xml:space="preserve">
521+
<value>Possible async method missing async flag</value>
522+
</data>
523+
524+
<!-- RBI0039 -->
525+
526+
<data name="RBI0039Description" xml:space="preserve">
527+
<value>Two methods marked as async will result in the same async name.</value>
528+
</data>
529+
<data name="RBI0039MessageFormat" xml:space="preserve">
530+
<value>The async name '{0}' used by '{1}' is already used by '{2}'</value>
531+
<comment>{0} is the name of the async method, {1} is the name of the sync method and {2} is the name of the first ocurrance.</comment>
532+
</data>
533+
<data name="RBI0039Title" xml:space="preserve">
534+
<value>Duplicated async name</value>
535+
</data>
536+
472537
</root>

src/rgen/Microsoft.Macios.Bindings.Analyzer/RgenDiagnostics.cs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,4 +526,79 @@ public static class RgenDiagnostics {
526526
description: new LocalizableResourceString (nameof (Resources.RBI0034Description), Resources.ResourceManager,
527527
typeof (Resources))
528528
);
529+
530+
/// <summary>
531+
/// Diagnostic descriptor for when a marked async method has not void return.
532+
/// </summary>
533+
internal static readonly DiagnosticDescriptor RBI0035 = new (
534+
"RBI0035",
535+
new LocalizableResourceString (nameof (Resources.RBI0035Title), Resources.ResourceManager, typeof (Resources)),
536+
new LocalizableResourceString (nameof (Resources.RBI0035MessageFormat), Resources.ResourceManager,
537+
typeof (Resources)),
538+
"Usage",
539+
DiagnosticSeverity.Error,
540+
isEnabledByDefault: true,
541+
description: new LocalizableResourceString (nameof (Resources.RBI0035Description), Resources.ResourceManager,
542+
typeof (Resources))
543+
);
544+
545+
/// <summary>
546+
/// Diagnostic descriptor for when a marked async method has no parameters.
547+
/// </summary>
548+
internal static readonly DiagnosticDescriptor RBI0036 = new (
549+
"RBI0036",
550+
new LocalizableResourceString (nameof (Resources.RBI0036Title), Resources.ResourceManager, typeof (Resources)),
551+
new LocalizableResourceString (nameof (Resources.RBI0036MessageFormat), Resources.ResourceManager,
552+
typeof (Resources)),
553+
"Usage",
554+
DiagnosticSeverity.Error,
555+
isEnabledByDefault: true,
556+
description: new LocalizableResourceString (nameof (Resources.RBI0036Description), Resources.ResourceManager,
557+
typeof (Resources))
558+
);
559+
560+
/// <summary>
561+
/// Diagnostic descriptor for when a marked async method has no delegate as the last parameter.
562+
/// </summary>
563+
internal static readonly DiagnosticDescriptor RBI0037 = new (
564+
"RBI0037",
565+
new LocalizableResourceString (nameof (Resources.RBI0037Title), Resources.ResourceManager, typeof (Resources)),
566+
new LocalizableResourceString (nameof (Resources.RBI0037MessageFormat), Resources.ResourceManager,
567+
typeof (Resources)),
568+
"Usage",
569+
DiagnosticSeverity.Error,
570+
isEnabledByDefault: true,
571+
description: new LocalizableResourceString (nameof (Resources.RBI0037Description), Resources.ResourceManager,
572+
typeof (Resources))
573+
);
574+
575+
/// <summary>
576+
/// Diagnostic descriptor for when a method that could be async was not marked.
577+
/// </summary>
578+
internal static readonly DiagnosticDescriptor RBI0038 = new (
579+
"RBI0038",
580+
new LocalizableResourceString (nameof (Resources.RBI0038Title), Resources.ResourceManager, typeof (Resources)),
581+
new LocalizableResourceString (nameof (Resources.RBI0038MessageFormat), Resources.ResourceManager,
582+
typeof (Resources)),
583+
"Usage",
584+
DiagnosticSeverity.Warning,
585+
isEnabledByDefault: true,
586+
description: new LocalizableResourceString (nameof (Resources.RBI0038Description), Resources.ResourceManager,
587+
typeof (Resources))
588+
);
589+
590+
/// <summary>
591+
/// Diagnostic descriptor for when two methods with the same parameters have the same async name.
592+
/// </summary>
593+
internal static readonly DiagnosticDescriptor RBI0039 = new (
594+
"RBI0039",
595+
new LocalizableResourceString (nameof (Resources.RBI0039Title), Resources.ResourceManager, typeof (Resources)),
596+
new LocalizableResourceString (nameof (Resources.RBI0039MessageFormat), Resources.ResourceManager,
597+
typeof (Resources)),
598+
"Usage",
599+
DiagnosticSeverity.Error,
600+
isEnabledByDefault: true,
601+
description: new LocalizableResourceString (nameof (Resources.RBI0039Description), Resources.ResourceManager,
602+
typeof (Resources))
603+
);
529604
}

0 commit comments

Comments
 (0)