Skip to content

Commit

Permalink
Analyzer fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-safar committed Jan 18, 2023
1 parent f20262d commit 1b45ed3
Show file tree
Hide file tree
Showing 34 changed files with 54 additions and 93 deletions.
1 change: 1 addition & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
<add key="dotnet6" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json" />
<add key="dotnet7" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json" />
<add key="dotnet8" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json" />
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
</packageSources>
<disabledPackageSources />
Expand Down
4 changes: 2 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<MicrosoftNetCompilersToolsetVersion>$(MicrosoftCodeAnalysisVersion)</MicrosoftNetCompilersToolsetVersion>
<MicrosoftCodeAnalysisCSharpAnalyzerTestingXunitVersion>1.0.1-beta1.*</MicrosoftCodeAnalysisCSharpAnalyzerTestingXunitVersion>
<MicrosoftCodeAnalysisBannedApiAnalyzersVersion>3.3.2</MicrosoftCodeAnalysisBannedApiAnalyzersVersion>
<MicrosoftCodeAnalysisNetAnalyzersVersion>7.0.0-preview1.22513.1</MicrosoftCodeAnalysisNetAnalyzersVersion>
<MicrosoftILVerificationVersion>7.0.0-preview.7.22375.6</MicrosoftILVerificationVersion>
<MicrosoftCodeAnalysisNetAnalyzersVersion>8.0.0-preview1.22566.1</MicrosoftCodeAnalysisNetAnalyzersVersion>
<MicrosoftILVerificationVersion>8.0.0-alpha.1.23067.11</MicrosoftILVerificationVersion>
<!-- This controls the version of the cecil package, or the version of cecil in the project graph
when we build the cecil submodule. The reference assembly package will depend on this version of cecil.
Keep this in sync with ProjectInfo.cs in the submodule. -->
Expand Down
2 changes: 1 addition & 1 deletion src/ILLink.RoslynAnalyzer/TrimAnalysis/ParameterProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ partial struct ParameterProxy
{
public ParameterProxy (IParameterSymbol parameter)
{
Method = (new ((IMethodSymbol) parameter.ContainingSymbol));
Method = new ((IMethodSymbol) parameter.ContainingSymbol);
Index = (ParameterIndex) parameter.Ordinal + (Method.HasImplicitThis () ? 1 : 0);
}

Expand Down
4 changes: 2 additions & 2 deletions src/ILLink.Shared/DataFlow/DefaultValueDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public DefaultValueDictionary<TKey, TValue> Clone ()
// This type should never be used as a dictionary key.
public override int GetHashCode () => throw new NotImplementedException ();

public static bool operator ==(DefaultValueDictionary<TKey, TValue> left, DefaultValueDictionary<TKey, TValue> right) => left.Equals(right);
public static bool operator !=(DefaultValueDictionary<TKey, TValue> left, DefaultValueDictionary<TKey, TValue> right) => !(left == right);
public static bool operator == (DefaultValueDictionary<TKey, TValue> left, DefaultValueDictionary<TKey, TValue> right) => left.Equals (right);
public static bool operator != (DefaultValueDictionary<TKey, TValue> left, DefaultValueDictionary<TKey, TValue> right) => !(left == right);
}
}
4 changes: 2 additions & 2 deletions src/ILLink.Shared/DataFlow/MaybeLattice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public Maybe<T> Clone ()
return new (value);
}

public static bool operator ==(Maybe<T> left, Maybe<T> right) => left.Equals(right);
public static bool operator !=(Maybe<T> left, Maybe<T> right) => !(left == right);
public static bool operator == (Maybe<T> left, Maybe<T> right) => left.Equals (right);
public static bool operator != (Maybe<T> left, Maybe<T> right) => !(left == right);
}

public struct MaybeLattice<T, TValueLattice> : ILattice<Maybe<T>>
Expand Down
4 changes: 2 additions & 2 deletions src/ILLink.Shared/DataFlow/ValueSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public bool Equals (ValueSet<TValue> other)
}
}

public static bool operator ==(ValueSet<TValue> left, ValueSet<TValue> right) => left.Equals(right);
public static bool operator !=(ValueSet<TValue> left, ValueSet<TValue> right) => !(left == right);
public static bool operator == (ValueSet<TValue> left, ValueSet<TValue> right) => left.Equals (right);
public static bool operator != (ValueSet<TValue> left, ValueSet<TValue> right) => !(left == right);

public override int GetHashCode ()
{
Expand Down
4 changes: 2 additions & 2 deletions src/linker/Linker.Dataflow/HoistedLocalKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public HoistedLocalKey (FieldDefinition field)

public override int GetHashCode () => Field.GetHashCode ();

public static bool operator ==(HoistedLocalKey left, HoistedLocalKey right) => left.Equals(right);
public static bool operator !=(HoistedLocalKey left, HoistedLocalKey right) => !(left == right);
public static bool operator == (HoistedLocalKey left, HoistedLocalKey right) => left.Equals (right);
public static bool operator != (HoistedLocalKey left, HoistedLocalKey right) => !(left == right);
}
}
4 changes: 2 additions & 2 deletions src/linker/Linker.Dataflow/ValueNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ValueBasicBlockPair (MultiValue value, int basicBlockIndex)

public override int GetHashCode () => HashUtils.Combine (Value.GetHashCode (), BasicBlockIndex);

public static bool operator ==(ValueBasicBlockPair left, ValueBasicBlockPair right) => left.Equals(right);
public static bool operator !=(ValueBasicBlockPair left, ValueBasicBlockPair right) => !(left == right);
public static bool operator == (ValueBasicBlockPair left, ValueBasicBlockPair right) => left.Equals (right);
public static bool operator != (ValueBasicBlockPair left, ValueBasicBlockPair right) => !(left == right);
}
}
2 changes: 1 addition & 1 deletion src/linker/Linker/LinkerAttributesInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public IEnumerable<T> GetAttributes<T> () where T : Attribute
return attributeList.Cast<T> ();
}

static Attribute? ProcessRequiresUnreferencedCodeAttribute (LinkContext context, ICustomAttributeProvider provider, CustomAttribute customAttribute)
static RequiresUnreferencedCodeAttribute? ProcessRequiresUnreferencedCodeAttribute (LinkContext context, ICustomAttributeProvider provider, CustomAttribute customAttribute)
{
if (!(provider is MethodDefinition || provider is TypeDefinition))
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,7 @@ static bool IsMessageMatch (Diagnostic actual, ImmutableArray<string> actualArgu

public MatchQuality (int value)
{
if (value < 0) {
throw new ArgumentOutOfRangeException (nameof (value));
}
ArgumentOutOfRangeException.ThrowIfNegative (value);

_value = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public class ExpectedInstructionSequenceAttribute : BaseInAssemblyAttribute
{
public ExpectedInstructionSequenceAttribute (string[] opCodes)
{
if (opCodes == null)
throw new ArgumentNullException (nameof (opCodes));
ArgumentNullException.ThrowIfNull (opCodes);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ public ExpectedInstructionSequenceOnMemberInAssemblyAttribute (string assemblyFi
{
if (string.IsNullOrEmpty (assemblyFileName))
throw new ArgumentNullException (nameof (assemblyFileName));
if (type == null)
throw new ArgumentNullException (nameof (type));
ArgumentNullException.ThrowIfNull (type);
if (string.IsNullOrEmpty (memberName))
throw new ArgumentNullException (nameof (memberName));
if (opCodes == null)
throw new ArgumentNullException (nameof (opCodes));
ArgumentNullException.ThrowIfNull (opCodes);
}

public ExpectedInstructionSequenceOnMemberInAssemblyAttribute (string assemblyFileName, string typeName, string memberName, string[] opCodes)
Expand All @@ -28,8 +26,7 @@ public ExpectedInstructionSequenceOnMemberInAssemblyAttribute (string assemblyFi
throw new ArgumentNullException (nameof (typeName));
if (string.IsNullOrEmpty (memberName))
throw new ArgumentNullException (nameof (memberName));
if (opCodes == null)
throw new ArgumentNullException (nameof (opCodes));
ArgumentNullException.ThrowIfNull (opCodes);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ public class ExpectedLocalsSequenceAttribute : BaseInAssemblyAttribute
{
public ExpectedLocalsSequenceAttribute (string[] types)
{
if (types == null)
throw new ArgumentNullException (nameof (types));
ArgumentNullException.ThrowIfNull (types);
}

public ExpectedLocalsSequenceAttribute (Type[] types)
{
if (types == null)
throw new ArgumentNullException (nameof (types));
ArgumentNullException.ThrowIfNull (types);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public class IgnoreTestCaseAttribute : Attribute

public IgnoreTestCaseAttribute (string reason)
{
if (reason == null)
throw new ArgumentNullException (nameof (reason));
ArgumentNullException.ThrowIfNull (reason);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public KeptAttributeAttribute (string attributeName)

public KeptAttributeAttribute (Type type)
{
if (type == null)
throw new ArgumentNullException (nameof (type));
ArgumentNullException.ThrowIfNull (type);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public KeptAttributeOnFixedBufferTypeAttribute (string attributeName)

public KeptAttributeOnFixedBufferTypeAttribute (Type type)
{
if (type == null)
throw new ArgumentNullException (nameof (type));
ArgumentNullException.ThrowIfNull (type);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public class KeptBaseOnTypeInAssemblyAttribute : BaseInAssemblyAttribute
{
public KeptBaseOnTypeInAssemblyAttribute (string assemblyFileName, Type type, string baseAssemblyFileName, Type baseType)
{
if (type == null)
throw new ArgumentNullException (nameof (type));
ArgumentNullException.ThrowIfNull (type);
if (string.IsNullOrEmpty (assemblyFileName))
throw new ArgumentException ("Value cannot be null or empty.", nameof (assemblyFileName));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ public sealed class KeptBaseTypeAttribute : KeptAttribute
{
public KeptBaseTypeAttribute (Type baseType)
{
if (baseType == null)
throw new ArgumentNullException (nameof (baseType));
ArgumentNullException.ThrowIfNull (baseType);
}

public KeptBaseTypeAttribute (Type baseType, params object[] typeArguments)
{
if (baseType == null)
throw new ArgumentNullException (nameof (baseType));
if (typeArguments == null)
throw new ArgumentNullException (nameof (typeArguments));
ArgumentNullException.ThrowIfNull (baseType);
ArgumentNullException.ThrowIfNull (typeArguments);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public class KeptExportedTypeAttribute : KeptAttribute
{
public KeptExportedTypeAttribute (Type type)
{
if (type is null)
throw new ArgumentNullException (nameof (type));
ArgumentNullException.ThrowIfNull (type);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public KeptInitializerData ()

public KeptInitializerData (int occurrenceIndexInBody)
{
if (occurrenceIndexInBody < 0)
throw new ArgumentOutOfRangeException (nameof (occurrenceIndexInBody));
ArgumentOutOfRangeException.ThrowIfNegative (occurrenceIndexInBody);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ public class KeptInterfaceAttribute : KeptAttribute

public KeptInterfaceAttribute (Type interfaceType)
{
if (interfaceType == null)
throw new ArgumentNullException (nameof (interfaceType));
ArgumentNullException.ThrowIfNull (interfaceType);
}

public KeptInterfaceAttribute (Type interfaceType, params object[] typeArguments)
{
if (interfaceType == null)
throw new ArgumentNullException (nameof (interfaceType));
if (typeArguments == null)
throw new ArgumentNullException (nameof (typeArguments));
ArgumentNullException.ThrowIfNull (interfaceType);
ArgumentNullException.ThrowIfNull (typeArguments);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public class KeptInterfaceOnTypeInAssemblyAttribute : BaseInAssemblyAttribute
{
public KeptInterfaceOnTypeInAssemblyAttribute (string assemblyFileName, Type type, string interfaceAssemblyFileName, Type interfaceType)
{
if (type == null)
throw new ArgumentNullException (nameof (type));
ArgumentNullException.ThrowIfNull (type);
if (string.IsNullOrEmpty (assemblyFileName))
throw new ArgumentException ("Value cannot be null or empty.", nameof (assemblyFileName));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,16 @@ public KeptMemberInAssemblyAttribute (string assemblyFileName, Type type, params
{
if (string.IsNullOrEmpty (assemblyFileName))
throw new ArgumentNullException (nameof (assemblyFileName));
if (type == null)
throw new ArgumentNullException (nameof (type));
if (memberNames == null)
throw new ArgumentNullException (nameof (memberNames));
ArgumentNullException.ThrowIfNull (type);
ArgumentNullException.ThrowIfNull (memberNames);
}

public KeptMemberInAssemblyAttribute (string assemblyFileName, string typeName, params string[] memberNames)
{
if (string.IsNullOrEmpty (assemblyFileName))
throw new ArgumentNullException (nameof (assemblyFileName));
if (typeName == null)
throw new ArgumentNullException (nameof (typeName));
if (memberNames == null)
throw new ArgumentNullException (nameof (memberNames));
ArgumentNullException.ThrowIfNull (typeName);
ArgumentNullException.ThrowIfNull (memberNames);
}

public string ExpectationAssemblyName { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public class KeptOverrideAttribute : KeptAttribute

public KeptOverrideAttribute (Type typeWithOverriddenMethod)
{
if (typeWithOverriddenMethod == null)
throw new ArgumentNullException (nameof (typeWithOverriddenMethod));
ArgumentNullException.ThrowIfNull (typeWithOverriddenMethod);
TypeWithOverriddenMethodDeclaration = typeWithOverriddenMethod;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public KeptReferencesInAssemblyAttribute (string assemblyFileName, string[] expe
if (string.IsNullOrEmpty (assemblyFileName))
throw new ArgumentNullException (nameof (assemblyFileName));

if (expectedReferenceAssemblyNames == null)
throw new ArgumentNullException (nameof (expectedReferenceAssemblyNames));
ArgumentNullException.ThrowIfNull (expectedReferenceAssemblyNames);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public KeptSecurityAttribute (string attributeName)

public KeptSecurityAttribute (Type type)
{
if (type == null)
throw new ArgumentNullException (nameof (type));
ArgumentNullException.ThrowIfNull (type);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public class KeptTypeInAssemblyAttribute : BaseInAssemblyAttribute
{
public KeptTypeInAssemblyAttribute (string assemblyFileName, Type type)
{
if (type == null)
throw new ArgumentNullException (nameof (type));
ArgumentNullException.ThrowIfNull (type);
if (string.IsNullOrEmpty (assemblyFileName))
throw new ArgumentException ("Value cannot be null or empty.", nameof (assemblyFileName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public class RemovedInterfaceOnTypeInAssemblyAttribute : BaseInAssemblyAttribute
{
public RemovedInterfaceOnTypeInAssemblyAttribute (string assemblyFileName, Type type, string interfaceAssemblyFileName, Type interfaceType)
{
if (type == null)
throw new ArgumentNullException (nameof (type));
ArgumentNullException.ThrowIfNull (type);
if (string.IsNullOrEmpty (assemblyFileName))
throw new ArgumentException ("Value cannot be null or empty.", nameof (assemblyFileName));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,16 @@ public RemovedMemberInAssemblyAttribute (string assemblyFileName, Type type, par
{
if (string.IsNullOrEmpty (assemblyFileName))
throw new ArgumentNullException (nameof (assemblyFileName));
if (type == null)
throw new ArgumentNullException (nameof (type));
if (memberNames == null)
throw new ArgumentNullException (nameof (memberNames));
ArgumentNullException.ThrowIfNull (type);
ArgumentNullException.ThrowIfNull (memberNames);
}

public RemovedMemberInAssemblyAttribute (string assemblyFileName, string typeName, params string[] memberNames)
{
if (string.IsNullOrEmpty (assemblyFileName))
throw new ArgumentNullException (nameof (assemblyFileName));
if (typeName == null)
throw new ArgumentNullException (nameof (typeName));
if (memberNames == null)
throw new ArgumentNullException (nameof (memberNames));
ArgumentNullException.ThrowIfNull (typeName);
ArgumentNullException.ThrowIfNull (memberNames);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public class RemovedTypeInAssemblyAttribute : BaseInAssemblyAttribute
{
public RemovedTypeInAssemblyAttribute (string assemblyFileName, Type type)
{
if (type == null)
throw new ArgumentNullException (nameof (type));
ArgumentNullException.ThrowIfNull (type);
if (string.IsNullOrEmpty (assemblyFileName))
throw new ArgumentException ("Value cannot be null or empty.", nameof (assemblyFileName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public class TestCaseRequirementsAttribute : BaseExpectedLinkedBehaviorAttribute
{
public TestCaseRequirementsAttribute (TestRunCharacteristics targetFrameworkCharacteristics, string reason)
{
if (reason == null)
throw new ArgumentNullException (nameof (reason));
ArgumentNullException.ThrowIfNull (reason);
}
}
}
Loading

0 comments on commit 1b45ed3

Please sign in to comment.