azure-functions-host icon indicating copy to clipboard operation
azure-functions-host copied to clipboard

Support C# discard parameters binding

Open aj-patterson opened this issue 3 years ago • 3 comments

What problem would the feature you're requesting solve? Please describe.

In some cases, the trigger binding parameter is not actually used in the function body, often with TimerTrigger and occasionally HttpRequest where the binding itself has already provided us all the information we need. This unused parameter causes C# analyzers to notify developers that it can be deleted, but obviously it's required for the function to work. Typically a resolution for this would be to make the parameter a discard parameter (named '_', '_1', '_2', etc.), but these names fail the binding name validation check.

Describe the solution you'd like

Allow parameter bindings to be named with a preceding underscore.

Describe alternatives you've considered

Disabling/Ignoring analyzer rule: The rule is on by default, and is usually helpful, so I'd not like to disable it. I can add a pragma ignore for affected functions, but this is frequent enough the ignores would become clutter. Finding a use for the parameter: In the case of Http Triggers, I could do some header inspection to search for correlation id or some other value, which would silence the warning. Correlation Id is a good practice anyway. Does not resolve Timer Trigger issue, however.

aj-patterson avatar Oct 01 '21 15:10 aj-patterson

Hi @aj-patterson, Thank you for your feedback! We will check for the possibilities internally and update you with the findings.

v-bbalaiagar avatar Oct 04 '21 08:10 v-bbalaiagar

Hi @aj-patterson, Discussed this request internally, adding this issue as a feature request to consider this in future implementations.

v-bbalaiagar avatar Oct 11 '21 16:10 v-bbalaiagar

It would also be useful for Python code to accept snake case binding names, as mentioned in the Stack Overflow question What is a valid binding name for azure function?. So, all underscores should be accepted, not preceding ones only.

Adrien-LUDWIG avatar Apr 10 '24 14:04 Adrien-LUDWIG