Skip to content

Commit

Permalink
Update Dependencies (#74)
Browse files Browse the repository at this point in the history
* switch to `Directory.Packages.props`
* Update dependencies
* modernize code
  • Loading branch information
viceroypenguin authored Jan 25, 2024
1 parent 3369e03 commit d9dd19e
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 123 deletions.
69 changes: 36 additions & 33 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,26 @@
root = true

[*]
charset = utf-8
indent_style = tab
insert_final_newline = true

# Build scripts
[*.{yml,yaml}]
indent_style = spaces
indent_size = 2

# Code files
[*.{cs,csx,vb,vbx}]
indent_size = 4
charset = utf-8-bom

# XML project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj,props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
indent_style = tab
indent_size = 2

# Dotnet code style settings:
# Code files
[*.cs]
indent_size = 4
tab_width = 4
max_line_length = 150

# IDE0055: Fix formatting
dotnet_diagnostic.IDE0055.severity = warning
## Dotnet code style settings:

# Sort using and Import directives with System.* appearing first
dotnet_sort_system_directives_first = true
Expand All @@ -34,10 +32,10 @@ dotnet_separate_import_directive_groups = false
dotnet_style_require_accessibility_modifiers = for_non_interface_members:error

# Avoid "this." and "Me." if not necessary
dotnet_style_qualification_for_field = false:refactoring
dotnet_style_qualification_for_property = false:refactoring
dotnet_style_qualification_for_method = false:refactoring
dotnet_style_qualification_for_event = false:refactoring
dotnet_style_qualification_for_field = false
dotnet_style_qualification_for_property = false
dotnet_style_qualification_for_method = false
dotnet_style_qualification_for_event = false

# Use language keywords instead of framework type names for type references
dotnet_style_predefined_type_for_locals_parameters_members = true:error
Expand All @@ -49,11 +47,7 @@ dotnet_style_collection_initializer = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_compound_assignment = true:warning
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_operator_placement_when_wrapping = beginning_of_line

# Constants are PascalCase
dotnet_naming_rule.constants_should_be_pascal_case.severity = suggestion
Expand Down Expand Up @@ -87,16 +81,15 @@ dotnet_naming_symbols.non_private_static_fields.required_modifiers = static

dotnet_naming_style.non_private_static_field_style.capitalization = pascal_case

# Static fields are camelCase and start with s_
dotnet_naming_rule.static_fields_should_be_camel_case.severity = suggestion
dotnet_naming_rule.static_fields_should_be_camel_case.symbols = static_fields
dotnet_naming_rule.static_fields_should_be_camel_case.style = static_field_style
# Static fields are PascalCase
dotnet_naming_rule.static_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.static_fields_should_be_pascal_case.symbols = static_fields
dotnet_naming_rule.static_fields_should_be_pascal_case.style = static_field_style

dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.required_modifiers = static

dotnet_naming_style.static_field_style.capitalization = camel_case
dotnet_naming_style.static_field_style.required_prefix = s_
dotnet_naming_style.static_field_style.capitalization = pascal_case

# Instance fields are camelCase and start with _
dotnet_naming_rule.instance_fields_should_be_camel_case.severity = suggestion
Expand Down Expand Up @@ -135,8 +128,8 @@ dotnet_naming_symbols.all_members.applicable_kinds = *

dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# CSharp code style settings:
[*.cs]
## C# style settings:

# Newline settings
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
Expand Down Expand Up @@ -166,6 +159,9 @@ csharp_style_expression_bodied_operators = false:none
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = true:silent

# Prefer local method constructs to have a block body
csharp_style_expression_bodied_local_functions = true:suggestion

# Prefer property-like constructs to have an expression-body
csharp_style_expression_bodied_properties = true:suggestion
csharp_style_expression_bodied_indexers = true:suggestion
Expand Down Expand Up @@ -212,18 +208,25 @@ csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false

# Blocks are allowed
csharp_prefer_braces = true:silent
csharp_preserve_single_line_blocks = true:silent
csharp_preserve_single_line_statements = true:silent
csharp_prefer_braces = when_multiline:silent
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true

# Specific diagnostics
# Style Analytics
dotnet_analyzer_diagnostic.category-Style.severity = warning
dotnet_diagnostic.IDE0046.severity = none # IDE0046: Convert to conditional expression
dotnet_diagnostic.IDE0130.severity = none # IDE0130: Namespace does not match folder structure

# XML Documentation
dotnet_diagnostic.CS0105.severity = error # CS0105: Using directive is unnecessary.
dotnet_diagnostic.CS1573.severity = error # CS1573: Missing XML comment for parameter
dotnet_diagnostic.CS1591.severity = error # CS1591: Missing XML comment for publicly visible type or member
dotnet_diagnostic.CS1712.severity = error # CS1712: Type parameter has no matching typeparam tag in the XML comment (but other type parameters do)

# Async
dotnet_diagnostic.CS1998.severity = error # CS1998: Async method lacks 'await' operators and will run synchronously
dotnet_diagnostic.CS4014.severity = error # CS4014: Because this call is not awaited, execution of the current method continues before the call is completed
dotnet_diagnostic.CA2007.severity = none # CA2007: Consider calling ConfigureAwait on the awaited task
dotnet_diagnostic.CA2007.severity = error # CA2007: Consider calling ConfigureAwait on the awaited task

# Documentation
dotnet_diagnostic.CS1573.severity = error # CS1573: Missing XML comment for parameter
dotnet_diagnostic.CS1591.severity = error # CS1591: Missing XML comment for publicly visible type or member
# Dispose things need disposing
dotnet_diagnostic.CA2000.severity = error # CA2000: Dispose objects before losing scope
1 change: 1 addition & 0 deletions AlphaVantage.Net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".root", ".root", "{D5051E17
.github\workflows\build.yml = .github\workflows\build.yml
.github\dependabot.yml = .github\dependabot.yml
Directory.Build.props = Directory.Build.props
Directory.Packages.props = Directory.Packages.props
LICENSE.txt = LICENSE.txt
readme.md = readme.md
EndProjectSection
Expand Down
2 changes: 2 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

<AnalysisLevel>latest-all</AnalysisLevel>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>

<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
Expand Down
55 changes: 55 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageVersion Include="Refit" Version="7.0.0" />
<PackageVersion Include="Refit.HttpClientFactory" Version="7.0.0" />
<PackageVersion Include="System.Net.Http.Json" Version="8.0.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageVersion Include="Refit" Version="7.0.0" />
<PackageVersion Include="Refit.HttpClientFactory" Version="7.0.0" />
<PackageVersion Include="System.Net.Http.Json" Version="7.0.1" />
<PackageVersion Include="System.Text.Json" Version="7.0.3" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageVersion Include="Refit" Version="6.3.2" />
<PackageVersion Include="Refit.HttpClientFactory" Version="6.3.2" />
<PackageVersion Include="System.Net.Http.Json" Version="6.0.0" />
<PackageVersion Include="System.Text.Json" Version="6.0.7" />
</ItemGroup>

<ItemGroup>
<PackageVersion Include="CommunityToolkit.Diagnostics" Version="8.2.2" />
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.0" />
<PackageVersion Include="CsvHelper" Version="30.0.3" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="MinVer" Version="4.3.0" />
<PackageVersion Include="PolySharp" Version="1.14.1" />
<PackageVersion Include="System.Threading.RateLimiting" Version="8.0.0" />
<PackageVersion Include="xunit" Version="2.6.6" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.6" />
</ItemGroup>
</Project>
55 changes: 14 additions & 41 deletions Source/AlphaVantage.Net/AlphaVantage.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>

<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -46,46 +44,21 @@
<Using Include="System.Text.Json" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Refit" Version="7.0.0" />
<PackageReference Include="Refit.HttpClientFactory" Version="7.0.0" />
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Refit" Version="7.0.0" />
<PackageReference Include="Refit.HttpClientFactory" Version="7.0.0" />
<PackageReference Include="System.Net.Http.Json" Version="7.0.1" />
<PackageReference Include="System.Text.Json" Version="7.0.3" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Refit" Version="6.3.2" />
<PackageReference Include="Refit.HttpClientFactory" Version="6.3.2" />
<PackageReference Include="System.Net.Http.Json" Version="6.0.0" />
<PackageReference Include="System.Text.Json" Version="6.0.7" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Diagnostics" Version="8.2.2" />
<PackageReference Include="CsvHelper" Version="30.0.1" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="4.3.0" PrivateAssets="All" />
<PackageReference Include="PolySharp" Version="1.13.2" PrivateAssets="All" />
<PackageReference Include="System.Threading.RateLimiting" Version="7.0.1" />
<PackageReference Include="CommunityToolkit.Diagnostics" />
<PackageReference Include="CsvHelper" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Http" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
<PackageReference Include="MinVer" PrivateAssets="All" />
<PackageReference Include="PolySharp" PrivateAssets="All" />
<PackageReference Include="Refit" />
<PackageReference Include="Refit.HttpClientFactory" />
<PackageReference Include="System.Net.Http.Json" />
<PackageReference Include="System.Text.Json" />
<PackageReference Include="System.Threading.RateLimiting" />
</ItemGroup>

<PropertyGroup Label="MinVer">
Expand Down
7 changes: 4 additions & 3 deletions Source/AlphaVantage.Net/AlphaVantageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public AlphaVantageClient(

private async Task<TResponse> WrapJsonCall<TResponse>(Func<Task<TResponse>> apiCall, CancellationToken cancellationToken)
{
using var lease = await _rateLimiter.AcquireAsync(cancellationToken);
using var lease = await _rateLimiter.AcquireAsync(cancellationToken).ConfigureAwait(false);
if (!lease.IsAcquired)
ThrowHelper.ThrowTimeoutException();

Expand All @@ -100,7 +100,7 @@ private async Task<TResponse> WrapJsonCall<TResponse>(Func<Task<TResponse>> apiC

private async Task<IReadOnlyList<TResponse>> WrapCsvCall<TResponse>(Func<Task<Stream>> apiCall, CancellationToken cancellationToken)
{
using var lease = await _rateLimiter.AcquireAsync(cancellationToken);
using var lease = await _rateLimiter.AcquireAsync(cancellationToken).ConfigureAwait(false);
if (!lease.IsAcquired)
ThrowHelper.ThrowTimeoutException();

Expand All @@ -113,7 +113,8 @@ private async Task<IReadOnlyList<TResponse>> WrapCsvCall<TResponse>(Func<Task<St
#if NET7_0_OR_GREATER
cancellationToken
#endif
);
).ConfigureAwait(false);

var json = JsonSerializer.Deserialize<JsonElement>(str);
var error = json.GetProperty("Error Message").GetString()!;
throw new AlphaVantageException(error, str);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static IServiceCollection AddAlphaVantageClient(
Guard.IsNotNull(services);
Guard.IsNotNull(sectionPath);

services
_ = services
.AddOptions<AlphaVantageOptions>()
.BindConfiguration(sectionPath);
services.DoAddAlphaVantageClient();
Expand All @@ -56,32 +56,32 @@ public static IServiceCollection AddAlphaVantageClient(
Guard.IsNotNull(services);
Guard.IsNotNull(configureOptions);

services.Configure(configureOptions);
_ = services.Configure(configureOptions);
services.DoAddAlphaVantageClient();

return services;
}

private static void DoAddAlphaVantageClient(this IServiceCollection services)
{
services.PostConfigure<AlphaVantageOptions>(o =>
_ = services.PostConfigure<AlphaVantageOptions>(o =>
{
Guard.IsNotNull(o.ApiKey, "AlphaVantage ApiKey");
Guard.IsGreaterThan(o.MaxApiCallsPerMinute, 0, "AlphaVantage MaxApiCallsPerMinute");
});

services.AddSingleton(sp =>
_ = services.AddSingleton(sp =>
new AlphaVantageClient.RateLimiter(
sp.GetRequiredService<IOptions<AlphaVantageOptions>>().Value.MaxApiCallsPerMinute));
services
_ = services
.AddRefitClient<IAlphaVantageApi>(settings: new()
{
ContentSerializer = new SystemTextJsonContentSerializer(AlphaVantageClient.JsonSerializerOptions),
})
.ConfigureHttpClient(c => c.BaseAddress = new Uri("https://www.alphavantage.co/"))
.ConfigurePrimaryHttpMessageHandler(() =>
new HttpClientHandler { AutomaticDecompression = System.Net.DecompressionMethods.All, });
services.AddTransient(sp =>
_ = services.AddTransient(sp =>
new AlphaVantageClient(
sp.GetRequiredService<AlphaVantageClient.RateLimiter>(),
sp.GetRequiredService<IAlphaVantageApi>(),
Expand Down
4 changes: 3 additions & 1 deletion Source/AlphaVantage.Net/EnumConverterFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ internal static T ParseEnumValue<T>(string? text) where T : struct, Enum
{
if (Enum.TryParse<T>(text, out var e)
|| Enum.TryParse(text, ignoreCase: true, out e))
{
return e;
}

foreach (var value in typeof(T).GetFields(BindingFlags.Public | BindingFlags.Static))
{
Expand All @@ -59,7 +61,7 @@ internal static T ParseEnumValue<T>(string? text) where T : struct, Enum
return ThrowHelper.ThrowInvalidOperationException<T>("Unknown enum value.");
}

private Dictionary<Type, JsonConverter> _converters = new();
private Dictionary<Type, JsonConverter> _converters = [];

[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1812:Avoid uninstantiated internal classes", Justification = "Activated on L28")]
internal sealed class EnumMemberEnumConverterNotNull<T> : JsonConverter<T>
Expand Down
6 changes: 2 additions & 4 deletions Source/AlphaVantage.Net/Fundamentals/EarningsResponse.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using System.Text.Json.Serialization;

namespace AlphaVantage.Fundamentals;
namespace AlphaVantage.Fundamentals;

/// <summary>
/// Annual and quarterly earnings information for an equity.
/// </summary>
public sealed class EarningsResponse
{
#pragma warning disable CS1591
public required string symbol { get; set; }
public required string Symbol { get; set; }
public required IReadOnlyList<AnnualEarnings> AnnualEarnings { get; set; }
public required IReadOnlyList<QuarterlyEarnings> QuarterlyEarnings { get; set; }
#pragma warning restore CS1591
Expand Down
Loading

0 comments on commit d9dd19e

Please sign in to comment.