Azure / Azure/azure-sdk-tools

C# Analyzer: Don't warn about required CancellationToken if [EditorBrowsable(Never)]

Open
#1,634 0 comments 0 reactions 0 assignees View on GitHub
API Analyzer Client
Dominant language
C#
Stars
135
Forks
260
Avg merge
3d 1h
Merged PRs (30d)
143

Description

Imagine we have an API in v1 that looks like

```C#
public Response GimmeFoo(string id, CancellationToken cancellationToken = default);
```

and we want to add a new parameter. We'd version that by changing to

```C#
[EditorBrowsable(EditorBrowsableState.Never)]
public Response GimmeFoo(string id, CancellationToken cancellationToken);

public Response GimmeFoo(string id, int size = 10, CancellationToken cancellationToken = default);
```

Unfortunately the analyzer complains about the old API with `Client method should have cancellationToken as the last optional parameter (both name and it being optional matters)`.

We should relax the optional requirement for `CancellationToken`s when `[EditorBrowsable(Never)]` has been applied to an API.

Contributor guide

Open the contributing guide

Research direction

Start by locating the C# analyzer rule that emits the quoted cancellationToken diagnostic and inspect how EditorBrowsable(Never) is represented. The change is done when an API hidden with EditorBrowsable(Never) no longer triggers the optional-token warning, while the existing warning remains for visible APIs.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.