Azure / Azure/azure-functions-host

Support C# discard parameters binding

Open
#7,735 3 comments 5 reactions 0 assignees View on GitHub
enhancement
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

#### 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.

Contributor guide

Open the contributing guide

Research direction

Start by locating the binding name validation check in the host, then trace how parameter names are validated for TimerTrigger and HttpRequest. Done means names such as _, _1, and _2 are accepted without breaking existing binding validation; verify both trigger scenarios with the relevant test suite.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.