agoda-com / agoda-com/AgodaAnalyzers
AG0045: false positive on string literals containing '/' with no Playwright usage
- Linguagem predominante
- C#
- Estrelas
- 25
- Forks
- 15
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
## Summary
AG0045 fires on a file that has no `Microsoft.Playwright` import and no Playwright API usage. The analyzer's heuristic appears to match any string literal containing forward-slash characters (`/`), regardless of whether the string is ever passed to a Playwright locator API.
## Reproduction
**File:** `src/Agoda.Supply.IAM.IntegrationTests/OneTimeSetup.cs`
**Repo:** `full-stack/supply/ycs/supply-iam` (internal GitLab)
**Analyzer version:** `1.1.185`
```csharp
// No Microsoft.Playwright import — usings are:
// System, System.Collections.Generic, System.Threading.Tasks,
// Agoda.Supply.AspNet.Testing.Pact, NUnit.Framework
[SetUpFixture]
public class SetUpFixture
{
private const string PactPath = "../../../../Agoda.Supply.IAM.Contract/pacts/ui"; // AG0045 fires here
...
}
```
The string is a relative filesystem path passed to a Pact stub server manager — it is never used with any Playwright API.
## Expected behaviour
AG0045 should only fire when:
1. The file imports `Microsoft.Playwright`, **and**
2. The string is passed to a Playwright locator API (`.Locator()`, `.QuerySelectorAsync()`, etc.)
## Actual behaviour
AG0045 fires on any string literal that matches an XPath-like pattern (contains `/`), even when there is no Playwright dependency in the file at all.
## Workaround applied
Rewrote the path literal as `Path.Combine(...)` with separate segments to avoid the heuristic:
```csharp
private static readonly string PactPath = Path.Combine(
"..", "..", "..", "..", "Agoda.Supply.IAM.Contract", "pacts", "ui");
```
This is a pure refactor with no behaviour change, but teams should not need to restructure code to avoid an analyzer misfiring on a completely unrelated construct.
## Suggested fix
Add a precondition check to the AG0045 diagnostic: only emit the warning if `Microsoft.Playwright` (or a Playwright-wrapping namespace) is referenced in the compilation unit or project.
Guia de contribuição
Avaliação
Esta issue ainda não foi avaliada.