8000 Housekeeping fix some of the code analyser warnings by ChrisPulman · Pull Request #1869 · reactiveui/refit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Housekeeping fix some of the code analyser warnings #1869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .props  (1)


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)buildtask.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<RefitTargets>net462;netstandard2.0;net6.0;net8.0</RefitTargets>
<NoWarn>IDE0040;CA1054;CA1510</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
Expand Down
13 changes: 7 additions & 6 deletions Refit.GeneratorTests/Refit.GeneratorTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
<PackageReference Include="xunit" Version="2.9.1"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2"/>
<PackageReference Include="System.Collections.Immutable" Version="9.0.0-rc.1.24431.7" />
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="System.Formats.Asn1" Version="8.0.1" />
<PackageReference Include="xunit" Version="2.9.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
<PackageReference Include="Verify.DiffPlex" Version="3.1.0" />
<PackageReference Include="Verify.SourceGenerators" Version="2.4.3" />
<PackageReference Include="Verify.Xunit" Version="26.6.0" />
Expand All @@ -37,7 +38,7 @@
<Link>%(RecursiveDir)\resources\%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Using Include="Xunit"/>
<Using Include="Xunit" />
</ItemGroup>

<ItemGroup>
Expand Down
22 changes: 11 additions & 11 deletions Refit.Tests/AuthenticatedClientHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void NullTokenGetterThrows()
}

[Fact]
public async void AuthenticatedHandlerIgnoresUnAuth()
public async Task AuthenticatedHandlerIgnoresUnAuth()
{
var handler = new MockHttpMessageHandler();
var settings = new RefitSettings()
Expand All @@ -104,7 +104,7 @@ public async void AuthenticatedHandlerIgnoresUnAuth()
}

[Fact]
public async void AuthenticatedHandlerUsesAuth()
public async Task AuthenticatedHandlerUsesAuth()
{
var handler = new MockHttpMessageHandler();
var settings = new RefitSettings()
Expand All @@ -128,7 +128,7 @@ public async void AuthenticatedHandlerUsesAuth()
}

[Fact]
public async void AuthenticatedHandlerWithParamUsesAuth()
public async Task AuthenticatedHandlerWithParamUsesAuth()
{
var handler = new MockHttpMessageHandler();
var settings = new RefitSettings()
Expand All @@ -152,7 +152,7 @@ public async void AuthenticatedHandlerWithParamUsesAuth()
}

[Fact]
public async void AuthenticatedHandlerWithTokenInParameterUsesAuth()
public async Task AuthenticatedHandlerWithTokenInParameterUsesAuth()
{
var handler = new MockHttpMessageHandler();
var settings = new RefitSettings() { HttpMessageHandlerFactory = () => handler };
Expand All @@ -172,7 +172,7 @@ public async void AuthenticatedHandlerWithTokenInParameterUsesAuth()
}

[Fact]
public async void AuthenticatedHandlerWithTokenInHeaderCollectionUsesAuth()
public async Task AuthenticatedHandlerWithTokenInHeaderCollectionUsesAuth()
{
var handler = new MockHttpMessageHandler();
var settings = new RefitSettings() { HttpMessageHandlerFactory = () => handler };
Expand All @@ -198,7 +198,7 @@ public async void AuthenticatedHandlerWithTokenInHeaderCollectionUsesAuth()
}

[Fact]
public async void AuthenticatedHandlerWithAuthorizeAttributeAndHeaderCollectionUsesAuth()
public async Task AuthenticatedHandlerWithAuthorizeAttributeAndHeaderCollectionUsesAuth()
{
var handler = new MockHttpMessageHandler();
var settings = new RefitSettings() { HttpMessageHandlerFactory = () => handler };
Expand Down Expand Up @@ -234,7 +234,7 @@ public async void AuthenticatedHandlerWithAuthorizeAttributeAndHeaderCollectionU
}

[Fact]
public async void AuthenticatedHandlerWithDuplicatedAuthorizationHeaderUsesAuth()
public async Task AuthenticatedHandlerWithDuplicatedAuthorizationHeaderUsesAuth()
{
var handler = new MockHttpMessageHandler();
var settings = new RefitSettings() { HttpMessageHandlerFactory = () => handler };
Expand Down Expand Up @@ -271,7 +271,7 @@ public async void AuthenticatedHandlerWithDuplicatedAuthorizationHeaderUsesAuth(
}

[Fact]
public async void AuthenticatedHandlerPostTokenInHeaderCollectionUsesAuth()
public async Task AuthenticatedHandlerPostTokenInHeaderCollectionUsesAuth()
{
var handler = new MockHttpMessageHandler();
var settings = new RefitSettings() { HttpMessageHandlerFactory = () => handler };
Expand Down Expand Up @@ -304,7 +304,7 @@ public async void AuthenticatedHandlerPostTokenInHeaderCollectionUsesAuth()
}

[Fact]
public async void AuthentictedMethodFromBaseClassWithHeadersAttributeUsesAuth()
public async Task AuthentictedMethodFromBaseClassWithHeadersAttributeUsesAuth()
{
var handler = new MockHttpMessageHandler();
var settings = new RefitSettings()
Expand All @@ -331,7 +331,7 @@ public async void AuthentictedMethodFromBaseClassWithHeadersAttributeUsesAuth()
}

[Fact]
public async void AuthentictedMethodFromInheritedClassWithHeadersAttributeUsesAuth()
public async Task AuthentictedMethodFromInheritedClassWithHeadersAttributeUsesAuth()
{
var handler = new MockHttpMessageHandler();
var settings = new RefitSettings()
Expand All @@ -358,7 +358,7 @@ public async void AuthentictedMethodFromInheritedClassWithHeadersAttributeUsesAu
}

[Fact]
public async void AuthentictedMethodFromInheritedClassWithHeadersAttributeUsesAuth_WithCRLFCheck()
public async Task AuthentictedMethodFromInheritedClassWithHeadersAttributeUsesAuth_WithCRLFCheck()
{
var handler = new MockHttpMessageHandler();
var settings = new RefitSettings()
Expand Down
75 changes: 73 additions & 2 deletions Refit.Xml/XmlContentSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ public class XmlContentSerializer : IHttpContentSerializer
readonly XmlContentSerializerSettings settings;
readonly ConcurrentDictionary<Type, XmlSerializer> serializerCache = new();

/// <summary>
/// Initializes a new instance of the <see cref="XmlContentSerializer"/> class.
/// </summary>
public XmlContentSerializer()
: this(new XmlContentSerializerSettings()) { }

/// <summary>
/// Initializes a new instance of the <see cref="XmlContentSerializer"/> class.
/// </summary>
/// <param name="settings">The settings.</param>
/// <exception cref="System.ArgumentNullException">settings</exception>
public XmlContentSerializer(XmlContentSerializerSettings settings)
{
this.settings = settings ?? throw new ArgumentNullException(nameof(settings));
Expand Down Expand Up @@ -76,7 +84,7 @@ public HttpContent ToHttpContent<T>(T item)
new XmlSerializer(
t,
settings.XmlAttributeOverrides,
Array.Empty<Type>(),
[],
null,
settings.XmlDefaultNamespace
)
Expand Down Expand Up @@ -110,21 +118,40 @@ await content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false)
}
}

/// <summary>
/// XmlReaderWriterSettings.
/// </summary>
public class XmlReaderWriterSettings
{
XmlReaderSettings readerSettings;
XmlWriterSettings writerSettings;

/// <summary>
/// Initializes a new instance of the <see cref="XmlReaderWriterSettings"/> class.
/// </summary>
public XmlReaderWriterSettings()
: this(new XmlReaderSettings(), new XmlWriterSettings()) { }

/// <summary>
/// Initializes a new instance of the <see cref="XmlReaderWriterSettings"/> class.
/// </summary>
/// <param name="readerSettings">The reader settings.</param>
public XmlReaderWriterSettings(XmlReaderSettings readerSettings)
: this(readerSettings, new XmlWriterSettings()) { }

/// <summary>
/// Initializes a new instance of the <see cref="XmlReaderWriterSettings"/> class.
/// </summary>
/// <param name="writerSettings">The writer settings.</param>
public XmlReaderWriterSettings(XmlWriterSettings writerSettings)
: this(new XmlReaderSettings(), writerSettings) { }

#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
/// <summary>
/// Initializes a new instance of the <see cref="XmlReaderWriterSettings"/> class.
/// </summary>
/// <param name="readerSettings">The reader settings.</param>
/// <param name="writerSettings">The writer settings.</param>
public XmlReaderWriterSettings(
XmlReaderSettings readerSettings,
XmlWriterSettings writerSettings
Expand All @@ -135,6 +162,13 @@ XmlWriterSettings writerSettings
WriterSettings = writerSettings;
}

/// <summary>
/// Gets or sets the reader settings.
/// </summary>
/// <value>
/// The reader settings.
/// </value>
/// <exception cref="System.ArgumentNullException">value</exception>
public XmlReaderSettings ReaderSettings
{
get
Expand All @@ -145,6 +179,13 @@ public XmlReaderSettings ReaderSettings
set => readerSettings = value ?? throw new ArgumentNullException(nameof(value));
}

/// <summary>
/// Gets or sets the writer settings.
/// </summary>
/// <value>
/// The writer settings.
/// </value>
/// <exception cref="System.ArgumentNullException">value</exception>
public XmlWriterSettings WriterSettings
{
get
Expand All @@ -167,25 +208,55 @@ void ApplyOverrideSettings()
}
}

/// <summary>
/// XmlContentSerializerSettings.
/// </summary>
public class XmlContentSerializerSettings
{
/// <summary>
/// Initializes a new instance of the <see cref="XmlContentSerializerSettings"/> class.
/// </summary>
public XmlContentSerializerSettings()
{
XmlDefaultNamespace = null;
XmlReaderWriterSettings = new XmlReaderWriterSettings();
XmlNamespaces = new XmlSerializerNamespaces(
new[] { new XmlQualifiedName(string.Empty, string.Empty), }
[new XmlQualifiedName(string.Empty, string.Empty),]
);

XmlAttributeOverrides = new XmlAttributeOverrides();
}

/// <summary>
/// Gets or sets the XML default namespace.
/// </summary>
/// <value>
/// The XML default namespace.
/// </value>
public string? XmlDefaultNamespace { get; set; }

/// <summary>
/// Gets or sets the XML reader writer settings.
/// </summary>
/// <value>
/// The XML reader writer settings.
/// </value>
public XmlReaderWriterSettings XmlReaderWriterSettings { get; set; }

/// <summary>
/// Gets or sets the XML namespaces.
/// </summary>
/// <value>
/// The XML namespaces.
/// </value>
public XmlSerializerNamespaces XmlNamespaces { get; set; }

/// <summary>
/// Gets or sets the XML attribute overrides.
/// </summary>
/// <value>
/// The XML attribute overrides.
/// </value>
public XmlAttributeOverrides XmlAttributeOverrides { get; set; }
}
}
5 changes: 2 additions & 3 deletions Refit/FormValueMultimap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ namespace Refit
/// same or different values.</remarks>
class FormValueMultimap : IEnumerable<KeyValuePair<string?, string?>>
{
static readonly Dictionary<Type, PropertyInfo[]> PropertyCache = new();
static readonly Dictionary<Type, PropertyInfo[]> PropertyCache = [];

readonly IList<KeyValuePair<string?, string?>> formEntries =
new List<KeyValuePair<string?, string?>>();
readonly IList<KeyValuePair<string?, string?>> formEntries = [];

readonly IHttpContentSerializer contentSerializer;

Expand Down
13 changes: 13 additions & 0 deletions Refit/RefitSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,24 @@
/// <summary>
/// Optional Key-Value pairs, which are displayed in the property <see cref="HttpRequestMessage.Properties"/>.
/// </summary>
public Dictionary<string, object>? HttpRequestMessageOptions { get; set; }

Check warning on line 136 in Refit/RefitSettings.cs

View workflow job for this annotation

GitHub Actions / build / build

Change 'HttpRequestMessageOptions' to be read-only by removing the property setter (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2227)

#if NET6_0_OR_GREATER

/// <summary>
/// Gets or sets the version.
/// </summary>
/// <value>
/// The version.
/// </value>
public Version Version { get; set; } = HttpVersion.Version11;

/// <summary>
/// Gets or sets the version policy.
/// </summary>
/// <value>
/// The version policy.
/// </value>
public System.Net.Http.HttpVersionPolicy VersionPolicy { get; set; } = HttpVersionPolicy.RequestVersionOrLower;
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion Refit/RestMethodInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ static void VerifyUrlPathIsSane(string relativePath)
);

// CRLF injection protection
if (relativePath.Contains("\r") || relativePath.Contains("\n"))
if (relativePath.Contains('\r') || relativePath.Contains('\n'))
throw new ArgumentException(
$"URL path {relativePath} must not contain CR or LF characters"
);
Expand Down
Loading
Loading
0