Skip to content

bug: TimeoutCancellationTokenAnalyzer only validates last parameter #4860

@thomhurst

Description

@thomhurst

Description

File: TUnit.Analyzers/TimeoutCancellationTokenAnalyzer.cs (Lines 43-63)

The analyzer only checks if the last parameter is a CancellationToken. It doesn't validate:

  1. That CancellationToken is the only parameter after the context parameter
  2. That if there's a TestContext parameter, CancellationToken comes after it
  3. Methods with multiple parameters where CancellationToken isn't last

Impact

False negatives — methods with wrong parameter order (e.g., Method(CancellationToken ct, TestContext ctx)) won't be detected.

Suggested Fix

Validate parameter order more thoroughly:

Valid:   (TimeoutContext ctx, CancellationToken ct)
Valid:   (CancellationToken ct)
Invalid: (TestContext ctx) - missing CancellationToken
Invalid: (CancellationToken ct, TestContext ctx) - wrong order

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions