# LS3002: CancellationToken Is Not the Last Parameter

## Intent

LS3002 is a compiler check that reports a cancellation token parameter that is not the last parameter or is not named cancellationToken, which is easy to pass in the wrong position and hides what it is where the method is called. This page states what the rule reports, where the warning sits, and how to place and name the token.

## Reference

### What the rule enforces

LS3002 enforces [Name asynchronous methods completely](https://litespec.dev/2.0.0/backend/dotnet/naming.md#name-asynchronous-methods-completely) (`litespec/backend/dotnet/naming#name-asynchronous-methods-completely`). It runs in all five projects. Its category is `LiteSpec.Style`. It reports a warning and is enabled by default, as the [Analyzers overview](https://litespec.dev/2.0.0/analyzers/README.md) describes.

### What the rule reports

The rule reports a `CancellationToken` parameter that is not the last parameter, or that is not named exactly `cancellationToken`. The token may sit second to last when the last parameter is a `params` array. The diagnostic sits on the token parameter.

### Failing example

```csharp
public Task LoadAsync(CancellationToken cancellationToken, string name) => Task.CompletedTask;
```

### Passing example

```csharp
public Task SaveAsync(CancellationToken cancellationToken, params string[] names) => Task.CompletedTask;
```

### How to fix

Move the token to the last position, or before a trailing `params` array, and name it `cancellationToken`.

## Notes

### What the rule ignores

The rule does not report methods without a token, overrides, explicit interface implementations, or implementations of members from outside interfaces. It does not run outside the five projects.
