Skip to content

Commit

Permalink
Clean up analysis warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dstelljes committed Oct 4, 2023
1 parent 69e8a5d commit 8a614b4
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 20 deletions.
3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project>

<PropertyGroup>
<AnalysisLevel>7</AnalysisLevel>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)\Chr.Avro.snk</AssemblyOriginatorKeyFile>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<Authors>C.H. Robinson</Authors>
Expand All @@ -21,7 +22,7 @@
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.376">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.507">
<IncludeAssets>Analyzers</IncludeAssets>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
Expand Down
5 changes: 3 additions & 2 deletions src/Chr.Avro.Binary/Serialization/BinaryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public BinaryReader(ReadOnlySpan<byte> data)
/// <summary>
/// Gets the current position of the reader.
/// </summary>
public long Index => index;
public readonly long Index => index;

/// <summary>
/// Reads a Boolean value from the current position and advances the reader.
Expand Down Expand Up @@ -142,7 +142,8 @@ public long ReadInteger()
{
throw new InvalidEncodingException(index, "Unable to read a valid variable-length integer. This may indicate invalid encoding earlier in the stream.");
}
} while (current > 0x7F);
}
while (current > 0x7F);

return (-(result & 0x01)) ^ ((result >> 0x01) & 0x7FFFFFFFFFFFFFFF);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Chr.Avro.Codegen/Codegen/CSharpCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public virtual CompilationUnitSyntax GenerateCompilationUnit(Schema schema)
.GroupBy(s => s.Namespace)
.OrderBy(g => g.Key);

if (candidates.Count() < 1)
if (!candidates.Any())
{
throw new UnsupportedSchemaException(schema, $"Code can only be generated for enums and records.");
}
Expand Down Expand Up @@ -307,7 +307,7 @@ protected virtual TypeSyntax GetPropertyType(Schema schema, bool nullable = fals

try
{
return GetPropertyType(others.Single(), nulls.Count() > 0);
return GetPropertyType(others.Single(), nulls.Any());
}
catch (InvalidOperationException exception)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Chr.Avro.Codegen/Codegen/NamespaceRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public override SyntaxNode VisitTypeArgumentList(TypeArgumentListSyntax node)
// VisitQualifiedName doesn’t hit these
var children = node.ChildNodes().OfType<NameSyntax>();

if (children.Count() > 0)
if (children.Any())
{
result = result.ReplaceNodes(children, (child, rewritten) => Reduce(child));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,8 @@ public virtual JsonSerializerBuilderCaseResult BuildExpression(Expression value,
? fields
.Select(field =>
{
var match = symbols.Find(symbol => IsMatch(symbol, field));

if (match == null)
{
throw new UnsupportedTypeException(type, $"{type} has a field {field.Name} that cannot be serialized.");
}
var match = symbols.Find(symbol => IsMatch(symbol, field))
?? throw new UnsupportedTypeException(type, $"{type} has a field {field.Name} that cannot be serialized.");

if (symbols.FindLast(symbol => IsMatch(symbol, field)) != match)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Chr.Avro/Abstract/FixedSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public int Size
{
if (value < 0)
{
throw new ArgumentOutOfRangeException("A fixed schema cannot have a negative size.");
throw new ArgumentOutOfRangeException(nameof(value), "A fixed schema cannot have a negative size.");
}

size = value;
Expand Down
4 changes: 2 additions & 2 deletions src/Chr.Avro/Abstract/ObjectDefaultValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ObjectDefaultValue<TValue> : DefaultValue
/// <param name="schema">
/// A <see cref="Schema" /> that can be used to read the value.
/// </param>
public ObjectDefaultValue(TValue value, Schema schema)
public ObjectDefaultValue(TValue? value, Schema schema)
: base(schema)
{
Value = value;
Expand All @@ -26,7 +26,7 @@ public ObjectDefaultValue(TValue value, Schema schema)
/// <summary>
/// Gets or sets the <see cref="object" /> representation of the value.
/// </summary>
public TValue Value { get; set; }
public TValue? Value { get; set; }

/// <inheritdoc />
/// <exception cref="UnsupportedTypeException">
Expand Down
2 changes: 1 addition & 1 deletion src/Chr.Avro/Abstract/RecordSchemaBuilderCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace Chr.Avro.Abstract
using System.Text.RegularExpressions;
using Chr.Avro.Infrastructure;
#if !NET6_0_OR_GREATER
using NullabilityInfo = Chr.Avro.Infrastructure.NullabilityInfo;
using NullabilityInfoContext = Chr.Avro.Infrastructure.NullabilityInfoContext;
using NullabilityState = Chr.Avro.Infrastructure.NullabilityState;
using NullabilityInfo = Chr.Avro.Infrastructure.NullabilityInfo;
#endif

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/Chr.Avro/Infrastructure/ConstrainedSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace Chr.Avro.Infrastructure
/// The type of the elements in the <see cref="ConstrainedSet{T}" />.
/// </typeparam>
internal class ConstrainedSet<T> : ICollection<T>, IReadOnlyCollection<T>
where T : notnull
{
private readonly IDictionary<T, LinkedListNode<T>> dictionary;

Expand Down
1 change: 1 addition & 0 deletions src/Chr.Avro/Infrastructure/ConstrainedSetExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ internal static class ConstrainedSetExtensions
/// A new <see cref="ConstrainedSet{T}" /> instance.
/// </returns>
internal static ConstrainedSet<T> ToConstrainedSet<T>(this IEnumerable<T> enumerable, Func<T, ConstrainedSet<T>, bool>? predicate = null)
where T : notnull
{
if (enumerable == null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Chr.Avro/Serialization/ArrayDeserializerBuilderCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected virtual Expression BuildIntermediateCollection(Type type, Type itemTyp
var itemType = type.GetEnumerableType() ?? throw new ArgumentException($"{type} is not an enumerable type.");

return type.GetConstructors()
.Where(constructor => constructor.GetParameters().Count() == 1)
.Where(constructor => constructor.GetParameters().Length == 1)
.FirstOrDefault(constructor => constructor.GetParameters().First().ParameterType
.IsAssignableFrom(typeof(IEnumerable<>).MakeGenericType(itemType)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Chr.Avro/Serialization/MapDeserializerBuilderCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected virtual Expression BuildIntermediateDictionary(Type type, Type keyType
var (keyType, valueType) = type.GetDictionaryTypes() ?? throw new ArgumentException($"{type} is not a dictionary type.");

return type.GetConstructors()
.Where(constructor => constructor.GetParameters().Count() == 1)
.Where(constructor => constructor.GetParameters().Length == 1)
.FirstOrDefault(constructor => constructor.GetParameters().First().ParameterType
.IsAssignableFrom(typeof(IDictionary<,>).MakeGenericType(keyType, valueType)));
}
Expand Down
1 change: 0 additions & 1 deletion tests/Chr.Avro.Binary.Tests/BinaryReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public class BinaryReaderTests
new object[] { "𝄟", new byte[] { 0x08, 0xF0, 0x9D, 0x84, 0x9F } },
};


[Theory]
[MemberData(nameof(BooleanEncodings))]
[InlineData(true, new byte[] { 0x02 })]
Expand Down
1 change: 0 additions & 1 deletion tests/Chr.Avro.Binary.Tests/UnionSerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ public void PartiallySelectedTypes()
},
});


var serializerCases = BinarySerializerBuilder.CreateDefaultCaseBuilders().ToList();
serializerCases.Insert(0, builder => new OrderSerializerBuilderCase(builder));

Expand Down

0 comments on commit 8a614b4

Please sign in to comment.