Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dotnet/roslyn-analyzers
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7.0.0
Choose a base ref
...
head repository: dotnet/roslyn-analyzers
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7.0.1
Choose a head ref
  • 2 commits
  • 6 files changed
  • 2 contributors

Commits on Dec 8, 2022

  1. update version for servicing

    jmarolf committed Dec 8, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    5766f0b View commit details

Commits on Jan 11, 2023

  1. [release/7.0] Fix bugs found in MAUI repo (#6405)

    * Update md files
    buyaa-n authored Jan 11, 2023
    1
    Copy the full SHA
    897aa84 View commit details
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
<PropertyGroup>
<VersionPrefix>3.3.4</VersionPrefix>
<PreReleaseVersionLabel>beta1</PreReleaseVersionLabel>
<NetAnalyzersVersionPrefix>7.0.0</NetAnalyzersVersionPrefix>
<NetAnalyzersVersionPrefix>7.0.1</NetAnalyzersVersionPrefix>
<NetAnalyzersPreReleaseVersionLabel>preview1</NetAnalyzersPreReleaseVersionLabel>
<AnalyzerUtilitiesVersionPrefix>$(VersionPrefix)</AnalyzerUtilitiesVersionPrefix>
<!--
Original file line number Diff line number Diff line change
@@ -563,10 +563,13 @@ static bool IsKnownValueGuarded(
}
}

if (attribute.SupportedFirst != null &&
info.Version.IsGreaterThanOrEqualTo(attribute.SupportedFirst))
var checkVersion = attribute.SupportedSecond ?? attribute.SupportedFirst;

if (checkVersion != null &&
info.Version.IsGreaterThanOrEqualTo(checkVersion))
{
attribute.SupportedFirst = null;
attribute.SupportedSecond = null;
RemoveUnsupportedWithLessVersion(info.Version, attribute);
RemoveOtherSupportsOnDifferentPlatforms(attributes, info.PlatformName);
}
@@ -816,8 +819,11 @@ static void ReportSupportedDiagnostic(IOperation operation, OperationBlockAnalys
csPlatformNames = string.Join(CommaSeparator, csPlatformNames, PlatformCompatibilityAllPlatforms);
}

var rule = supportedRule ? SwitchSupportedRule(callsite) : SwitchRule(callsite, true);
context.ReportDiagnostic(operation.CreateDiagnostic(rule, operationName, JoinNames(platformNames), csPlatformNames));
if (!platformNames.IsEmpty)
{
var rule = supportedRule ? SwitchSupportedRule(callsite) : SwitchRule(callsite, true);
context.ReportDiagnostic(operation.CreateDiagnostic(rule, operationName, JoinNames(platformNames), csPlatformNames));
}

if (!obsoletedPlatforms.IsEmpty)
{
6 changes: 3 additions & 3 deletions src/NetAnalyzers/Microsoft.CodeAnalysis.NetAnalyzers.sarif
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
{
"tool": {
"name": "Microsoft.CodeAnalysis.CSharp.NetAnalyzers",
"version": "7.0.0",
"version": "7.0.1",
"language": "en-US"
},
"rules": {
@@ -538,7 +538,7 @@
{
"tool": {
"name": "Microsoft.CodeAnalysis.NetAnalyzers",
"version": "7.0.0",
"version": "7.0.1",
"language": "en-US"
},
"rules": {
@@ -5815,7 +5815,7 @@
{
"tool": {
"name": "Microsoft.CodeAnalysis.VisualBasic.NetAnalyzers",
"version": "7.0.0",
"version": "7.0.1",
"language": "en-US"
},
"rules": {
5 changes: 0 additions & 5 deletions src/NetAnalyzers/RulesMissingDocumentation.md
Original file line number Diff line number Diff line change
@@ -2,8 +2,3 @@

Rule ID | Missing Help Link | Title |
--------|-------------------|-------|
CA1311 | <https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1311> | Specify a culture or use an invariant version |
CA1421 | <https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1421> | This method uses runtime marshalling even when the 'DisableRuntimeMarshallingAttribute' is applied |
CA1852 | <https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1852> | Seal internal types |
CA1853 | <https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1853> | Unnecessary call to 'Dictionary.ContainsKey(key)' |
CA1855 | <https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1855> | Prefer 'Clear' over 'Fill' |
Original file line number Diff line number Diff line change
@@ -454,6 +454,37 @@ public void ObsoletedOnLinuxAndWindows10() { }
await VerifyAnalyzerCSAsync(csSource, s_msBuildPlatforms);
}

[Fact]
public async Task CalledApiHasSupportedAndObsoletedAttributes_CallsiteSupressesSupportedAttributeWarnsForObsoletedOnly()
{
var source = @"
using System;
using System.Runtime.Versioning;
class Program
{
[Mock.ObsoletedOSPlatform(""ios7.0"", ""Use 'NSString.GetBoundingRect (CGSize, NSStringDrawingOptions, UIStringAttributes, NSStringDrawingContext)' instead."")]
[Mock.ObsoletedOSPlatform(""maccatalyst7.0"", ""Use 'NSString.GetBoundingRect (CGSize, NSStringDrawingOptions, UIStringAttributes, NSStringDrawingContext)' instead."")]
[SupportedOSPlatform(""ios"")]
[SupportedOSPlatform(""maccatalyst"")]
public static void M3() { }
[SupportedOSPlatform(""ios"")]
public static void M1()
{
{|CA1422:M3()|}; // This call site is reachable on: 'ios', 'maccatalyst'. 'Program.M3()' is obsoleted on: 'ios' 7.0 and later (Use 'NSString.GetBoundingRect (CGSize, NSStringDrawingOptions, UIStringAttributes, NSStringDrawingContext)' instead.), 'maccatalyst' 7.0 and later (Use 'NSString.GetBoundingRect (CGSize, NSStringDrawingOptions, UIStringAttributes, NSStringDrawingContext)' instead.).
}
[SupportedOSPlatform(""ios10.0"")]
public static void M2()
{
{|CA1422:M3()|}; // This call site is reachable on: 'ios' 10.0 and later, 'maccatalyst' 10.0 and later. 'Program.M3()' is obsoleted on: 'ios' 7.0 and later (Use 'NSString.GetBoundingRect (CGSize, NSStringDrawingOptions, UIStringAttributes, NSStringDrawingContext)' instead.), 'maccatalyst' 7.0 and later (Use 'NSString.GetBoundingRect (CGSize, NSStringDrawingOptions, UIStringAttributes, NSStringDrawingContext)' instead.).
}
}" + MockObsoletedAttributeCS;

await VerifyAnalyzerCSAsync(source);
}

private readonly string MockObsoletedAttributeCS = @"
namespace Mock
{
Original file line number Diff line number Diff line change
@@ -4968,6 +4968,39 @@ void M1()
await VerifyAnalyzerCSAsync(source);
}

[Fact, WorkItem(4372, "https://github.com/dotnet/roslyn-analyzers/issues/6158")]
public async Task ChildApiNarrowedParentSupport_GuardingVersionShouldBeComparedWithChildVersion()
{
var source = @"
using System;
using System.Runtime.Versioning;
[SupportedOSPlatform(""ios"")]
[SupportedOSPlatform(""tvos"")]
[SupportedOSPlatform(""maccatalyst"")]
class Program
{
[SupportedOSPlatform(""tvos10.2"")]
[SupportedOSPlatform(""ios10.3"")]
[SupportedOSPlatform(""maccatalyst10.3"")]
public static int P1 => 1;
}
class Test
{
[SupportedOSPlatform(""ios10.0"")]
public void M1()
{
var rate = (OperatingSystem.IsIOSVersionAtLeast(10, 3) || OperatingSystem.IsMacCatalystVersionAtLeast(10, 3) || OperatingSystem.IsTvOSVersionAtLeast(10, 3))
? Program.P1 : 0; // guarded
if (OperatingSystem.IsIOSVersionAtLeast(10, 3) || OperatingSystem.IsMacCatalystVersionAtLeast(10, 3) || OperatingSystem.IsTvOSVersionAtLeast(10))
rate = [|Program.P1|]; // version of TvOS is not guarded
}
}";

await VerifyAnalyzerCSAsync(source);
}

[Fact]
public async Task ApiAndGuardAttributeBothHasVersions_AttributeVersionWins()
{