Skip to content

fix: analyzer diagnostics should point to parameters, not methods #4899

@thomhurst

Description

@thomhurst

Description

Throughout TUnit.Analyzers/, diagnostics consistently point to the method location instead of the specific parameter that has the issue:

Diagnostic.Create(Rules.MissingTimeoutCancellationTokenAttributes,
    context.Symbol.Locations.FirstOrDefault())  // Reports at method, not parameter

When the parameter is the problem, the diagnostic should point to it:

parameter.Locations.FirstOrDefault() ?? context.Symbol.Locations.FirstOrDefault()

CombinedDataSourceAnalyzer.cs line 93 already shows the correct pattern — apply it consistently.

Impact

Users are directed to the wrong location, making it harder to understand and fix the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or requestgood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions