Skip to content

Commit

Permalink
Add Source Generator Analyzer Rules (#1048)
Browse files Browse the repository at this point in the history
Add analyzer rules for the source-generated function metadata preview
  • Loading branch information
satvu committed Sep 28, 2022
1 parent e2df0bb commit 0ed601e
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 1 deletion.
1 change: 0 additions & 1 deletion docs/analyzer-rules/AZFW0004.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
| **Category** |[Startup]|
| **Severity** |Error|


## Cause

This rule is triggered when a worker extension startup type does not have a parameterless constructor.
Expand Down
27 changes: 27 additions & 0 deletions docs/analyzer-rules/AZFW0005.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# AZFW0005: Multiple Azure Functions Binding Attributes grouped together

| | Value |
|-|-|
| **Rule ID** |AZFW0005|
| **Category** |[AzureFunctionsSyntax]|
| **Severity** |Error|

## Cause

This rule is triggered when multiple Azure Functions Binding Attributes are grouped together on a method, parameter, or property syntax.

## Rule description

Azure Functions Binding Attributes are used to decorate a method, parameter, or property syntax. Only one binding can be associated with any syntax.

## How to fix violations

If you have multiple bindings on a property syntax, refactor your code to create new properties to handle the different bindings. Create only one binding per property.

If you have multiple bindings on a parameter syntax, refactor your code to add new parameters to handle the different bindings. Create only one binding per parameter.

If you have multiple bindings on a method, create a custom return type with the Output Binding attributes decorating the custom return type's properties. Create only one binding per property. See the documented guidance for [multiple Output Bindings](https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide#multiple-output-bindings) for more information.

## When to suppress warnings

This rule should not be suppressed because this error will prevent your Azure Functions from running.
23 changes: 23 additions & 0 deletions docs/analyzer-rules/AZFW0006.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# AZFW0006: Symbol Not Found

| | Value |
|-|-|
| **Rule ID** |AZFW0006|
| **Category** |[AzureFunctionsSyntax]|
| **Severity** |Warning|

## Cause

This rule is triggered when a Symbol necessary for Azure Function metadata generation cannot be found in the user compilation.

## Rule description

Symbols are searched for and loaded from the user compilation to gather Function metadata information. If the are not found, then the user's Azure Function will not run.

## How to fix violations

Make sure you have added all necessary imports to your compilation.

## When to suppress warnings

This rule should not be suppressed because this error will prevent your Azure Functions from running.
23 changes: 23 additions & 0 deletions docs/analyzer-rules/AZFW0007.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# AZFW0007: Multiple HTTP response binding types for Azure Function

| | Value |
|-|-|
| **Rule ID** |AZFW0007|
| **Category** |[AzureFunctionsSyntax]|
| **Severity** |Error|

## Cause

This rule is triggered when there are multiple HTTP response binding types associated with an Azure Function.

## Rule description

Each Azure Function can have only one HTTP response binding type.

## How to fix violations

Make sure you have only one HTTP response binding type associated with an Azure Function. If you have a custom return type, please check all of the properties to verify that there is only one HTTP response binding type.

## When to suppress warnings

This rule should not be suppressed because this error will prevent your Azure Functions from running.
25 changes: 25 additions & 0 deletions docs/analyzer-rules/AZFW0008.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# AZFW0008: Invalid EventHubs Trigger

| | Value |
|-|-|
| **Rule ID** |AZFW0008|
| **Category** |[AzureFunctionsSyntax]|
| **Severity** |Error|

## Cause

This rule is triggered when the EventHubs trigger of an Azure Function is invalid.

## Rule description

EventHubs triggers must correctly declare a compatible "IsBatched" value and parameter input type. For example, for EventHubs triggers where `IsBatched = true`, the input parameter type must be an iterable collection.

_**Note:**_ The default value of IsBatched is true. If you are not explicitly providing a value, the parameter type should be a collection type.

## How to fix violations

If you have an EventHubs trigger where `IsBatched = true` (it is true by default), make sure your input parameter type is an iterable collection.

## When to suppress warnings

This rule should not be suppressed because this error will prevent your Azure Functions from running.
2 changes: 2 additions & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
<!-- Please add your release notes in the following format:
- My change description (#PR/#issue)
-->

- Add new analyzer rules for the source-generatued function metadata preview (#1048)

0 comments on commit 0ed601e

Please sign in to comment.