Skip to content

Commit

Permalink
Remove error when targeting net8.0-browser1.0 TFM
Browse files Browse the repository at this point in the history
  • Loading branch information
akoeplinger committed Jun 22, 2023
1 parent 455013a commit 066999a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public sealed class UseValidPlatformString : DiagnosticAnalyzer
private const string IsPrefix = "Is";
private const string VersionSuffix = "VersionAtLeast";
private const string macOS = nameof(macOS);
private const string Browser = nameof(Browser);

private static readonly LocalizableString s_localizableTitle = CreateLocalizableResourceString(nameof(UseValidPlatformStringTitle));
private static readonly LocalizableString s_localizableDescription = CreateLocalizableResourceString(nameof(UseValidPlatformStringDescription));
Expand Down Expand Up @@ -84,6 +85,12 @@ public override void Initialize(AnalysisContext context)
knownPlatforms.Add("OSX", versions);
}
if (knownPlatforms.TryGetValue(Browser, out versions) && versions == 0)
{
// Browser is a special case, we don't have a version guard method for it but we need to support a browser1.0 target platform
knownPlatforms[Browser] = 2;
}
context.RegisterOperationAction(context => AnalyzeOperation(context.Operation, context, knownPlatforms), OperationKind.Invocation);
context.RegisterSymbolAction(context => AnalyzeSymbol(
static (context, diagnostic) => context.ReportDiagnostic(diagnostic),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ public static void InvalidVersion() { }
[{|#3:SupportedOSPlatform(""watchOs7.1.0.2"")|}] // Version '7.1.0.2' is not valid for platform 'watchOs'. Use a version with 2-3 parts for this platform.
public static void InvalidVersion2() { }
[{|#4:UnsupportedOSPlatform(""browser1.0."")|}] // Version '1.0.' is not valid for platform 'browser'. Do not use versions for this platform.
[{|#4:UnsupportedOSPlatform(""linux1.0."")|}] // Version '1.0.' is not valid for platform 'linux'. Do not use versions for this platform.
public static void InvalidVersion3() { }
}";
await VerifyAnalyzerCsAsync(csSource,
VerifyCS.Diagnostic(UseValidPlatformString.UnknownPlatform).WithLocation(0).WithArguments("window"),
VerifyCS.Diagnostic(UseValidPlatformString.UnknownPlatform).WithLocation(1).WithArguments("watch"),
VerifyCS.Diagnostic(UseValidPlatformString.InvalidVersion).WithLocation(2).WithArguments("7", "windows", "-4"),
VerifyCS.Diagnostic(UseValidPlatformString.InvalidVersion).WithLocation(3).WithArguments("7.1.0.2", "watchOs", "-3"),
VerifyCS.Diagnostic(UseValidPlatformString.NoVersion).WithLocation(4).WithArguments("1.0.", "browser"));
VerifyCS.Diagnostic(UseValidPlatformString.NoVersion).WithLocation(4).WithArguments("1.0.", "linux"));
}

[Fact]
Expand All @@ -157,7 +157,7 @@ End Sub
Public Shared Sub InvalidVersion2()
End Sub
<[|UnsupportedOSPlatform(""browser1.0."")|]>
<[|UnsupportedOSPlatform(""linux1.0."")|]>
Public Shared Sub InvalidVersion3()
End Sub
End Class";
Expand Down Expand Up @@ -413,7 +413,7 @@ public class Test
[{|#0:SupportedOSPlatform(""MacOS1.2.3.4"")|}] // Version '1.2.3.4' is not valid for platform 'MacOS'. Use a version with 2-3 parts for this platform.
[SupportedOSPlatform(""Osx2.3"")]
[SupportedOSPlatform(""Linux"")]
[[|SupportedOSPlatform(""Browser4.3"")|]] // Browser should not have a version
[[|SupportedOSPlatform(""Linux4.3"")|]] // Linux should not have a version
public void SupportedOSPlatformMac4PartsInvalid() { }
[SupportedOSPlatform(""MacOS1.2"")]
Expand Down

0 comments on commit 066999a

Please sign in to comment.