Skip to content

Commit

Permalink
chore: Code cleanup (#1135)
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Skender <[email protected]>
  • Loading branch information
DaveSkender authored Jan 3, 2024
1 parent 96708d2 commit 7de4279
Show file tree
Hide file tree
Showing 134 changed files with 98 additions and 499 deletions.
29 changes: 16 additions & 13 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ charset = utf-8
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
max_line_length = 150
Expand All @@ -15,7 +16,9 @@ max_line_length = 150
csharp_indent_block_contents = true

# IDE0161 Convert to file-scoped namespace
csharp_style_namespace_declarations= file_scoped:suggestion
csharp_style_namespace_declarations = file_scoped:suggestion
csharp_using_directive_placement = outside_namespace:warning
dotnet_style_namespace_match_folder = false:none

# CA1051: Do not declare visible instance fields
dotnet_diagnostic.CA1051.severity = silent
Expand All @@ -25,7 +28,7 @@ dotnet_diagnostic.CA1303.severity = none

# CA1720: Identifier contains type name
dotnet_diagnostic.CA1720.severity = silent
dotnet_diagnostic.IDE0090.severity= suggestion
dotnet_diagnostic.IDE0090.severity = suggestion
dotnet_diagnostic.SA1413.severity = silent
dotnet_diagnostic.SA1200.severity = silent

Expand All @@ -49,7 +52,6 @@ dotnet_diagnostic.SA1117.severity = none

# SA1118: Parameter should not span multiple lines
dotnet_diagnostic.SA1118.severity = silent
csharp_using_directive_placement = outside_namespace:warning

# SA1202: Elements should be ordered by access
dotnet_diagnostic.SA1202.severity = silent
Expand Down Expand Up @@ -79,15 +81,15 @@ dotnet_diagnostic.SA1602.severity = silent
dotnet_diagnostic.SA1633.severity = none

# Misc IDE
dotnet_diagnostic.IDE0055.severity=suggestion
dotnet_diagnostic.IDE0059.severity=suggestion
dotnet_diagnostic.IDE0060.severity=suggestion
dotnet_diagnostic.IDE0062.severity=suggestion
dotnet_diagnostic.IDE0063.severity=suggestion
dotnet_diagnostic.IDE0065.severity=suggestion
dotnet_diagnostic.IDE0066.severity=suggestion
dotnet_diagnostic.IDE0071.severity=suggestion
dotnet_diagnostic.IDE0047.severity=suggestion
dotnet_diagnostic.IDE0055.severity = suggestion
dotnet_diagnostic.IDE0059.severity = suggestion
dotnet_diagnostic.IDE0060.severity = suggestion
dotnet_diagnostic.IDE0062.severity = suggestion
dotnet_diagnostic.IDE0063.severity = suggestion
dotnet_diagnostic.IDE0065.severity = suggestion
dotnet_diagnostic.IDE0066.severity = suggestion
dotnet_diagnostic.IDE0071.severity = suggestion
dotnet_diagnostic.IDE0047.severity = suggestion
csharp_indent_labels = no_change
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:suggestion
Expand Down Expand Up @@ -137,6 +139,8 @@ csharp_style_prefer_primary_constructors = true:suggestion

# IDE0058: Expression value is never used
dotnet_diagnostic.IDE0058.severity = none
dotnet_diagnostic.IDE0077.severity = warning
dotnet_diagnostic.IDE0100.severity = suggestion

[*.{cs,vb}]
tab_width = 4
Expand Down Expand Up @@ -216,6 +220,5 @@ dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_property = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_event = false:silent
dotnet_style_namespace_match_folder= false:silent
dotnet_style_allow_multiple_blank_lines_experimental = false:suggestion
dotnet_style_allow_statement_immediately_after_block_experimental = false:suggestion
10 changes: 9 additions & 1 deletion .github/workflows/build-indicators.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
--logger trx
--results-directory ./test-other
- name: Update tests summary
- name: Post tests summary
uses: bibipkins/[email protected]
if: ${{ github.event_name == 'pull_request' && (success() || (failure() && (steps.test-library.conclusion == 'failure' || steps.test-other.conclusion == 'failure'))) }}
with:
Expand All @@ -72,3 +72,11 @@ jobs:
coverage-path: ./test-indicators/**/coverage.cobertura.xml
coverage-type: cobertura
coverage-threshold: 95

- name: Post coverage to Codacy
uses: codacy/codacy-coverage-reporter-action@v1
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: ./test-indicators/**/coverage.cobertura.xml
# or a comma-separated list for multiple reports
# coverage-reports: <PATH_TO_REPORT>, <PATH_TO_REPORT>
18 changes: 9 additions & 9 deletions docs/GemFile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ GEM
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
addressable (2.8.5)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
base64 (0.2.0)
bigdecimal (3.1.4)
bigdecimal (3.1.5)
coffee-script (2.4.1)
coffee-script-source
execjs
Expand All @@ -41,7 +41,7 @@ GEM
ethon (0.16.0)
ffi (>= 1.15.0)
execjs (2.9.1)
faraday (2.7.11)
faraday (2.8.1)
base64
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
Expand Down Expand Up @@ -227,7 +227,7 @@ GEM
gemoji (~> 3.0)
html-pipeline (~> 2.2)
jekyll (>= 3.0, < 5.0)
json (2.6.3)
json (2.7.1)
json-minify (0.0.3)
json (> 0)
kramdown (2.3.2)
Expand All @@ -245,9 +245,9 @@ GEM
jekyll-seo-tag (~> 2.1)
minitest (5.20.0)
mutex_m (0.2.0)
nokogiri (1.15.4-x64-mingw-ucrt)
nokogiri (1.15.5-x64-mingw-ucrt)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-linux)
nokogiri (1.15.5-x86_64-linux)
racc (~> 1.4)
octokit (4.25.1)
faraday (>= 1, < 3)
Expand Down Expand Up @@ -277,16 +277,16 @@ GEM
unf (~> 0.1.4)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
typhoeus (1.4.0)
typhoeus (1.4.1)
ethon (>= 0.9.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
unf (0.1.4)
unf_ext
unf_ext (0.0.9)
unf_ext (0.0.9-x64-mingw-ucrt)
unf_ext (0.0.9.1)
unf_ext (0.0.9.1-x64-mingw-ucrt)
unicode-display_width (1.8.0)
wdm (0.1.1)
webrick (1.8.1)
Expand Down
5 changes: 0 additions & 5 deletions src/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage(
Expand Down
7 changes: 1 addition & 6 deletions src/Indicators.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>https://github.com/DaveSkender/Stock.Indicators/releases</PackageReleaseNotes>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageLicenseFile></PackageLicenseFile>
<PackageIcon>icon.png</PackageIcon>

<IncludeSymbols>true</IncludeSymbols>
Expand All @@ -60,19 +59,15 @@
<ItemGroup>
<None Include="..\README.md">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
<None Include="..\LICENSE">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
<None Include="..\NOTICE">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
<None Include="icon.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

Expand All @@ -81,7 +76,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/_common/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ public enum SyncType
AppendOnly,
RemoveOnly,
FullMatch
}
}
8 changes: 3 additions & 5 deletions src/_common/Math/NullMath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ public static decimal Round(this decimal value, int digits)
=> Math.Round(value, digits);

public static double Null2NaN(this double? value)
=> (value is null)
? double.NaN
: (double)value;
=> value ?? double.NaN;

public static double? NaN2Null(this double? value)
=> (value is double and double.NaN)
=> (value is not null and double.NaN)
? null
: value;

public static double? NaN2Null(this double value)
=> (value is double and double.NaN)
=> double.IsNaN(value)
? null
: value;
}
8 changes: 3 additions & 5 deletions src/_common/Math/Numerix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,18 @@ public static double Slope(double[] x, double[] y)

// least squares method
double sumSqX = 0;
double sumSqY = 0;
double sumSqXY = 0;
double sumSqXy = 0;

for (int i = 0; i < length; i++)
{
double devX = x[i] - avgX;
double devY = y[i] - avgY;

sumSqX += devX * devX;
sumSqY += devY * devY;
sumSqXY += devX * devY;
sumSqXy += devX * devY;
}

double slope = sumSqXY / sumSqX;
double slope = sumSqXy / sumSqX;

return slope;
}
Expand Down
6 changes: 0 additions & 6 deletions src/_common/Quotes/Quote.Aggregates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ public static IEnumerable<Quote> Aggregate<TQuote>(
TimeSpan timeSpan)
where TQuote : IQuote
{
// handle no quotes scenario
if (quotes == null || !quotes.Any())
{
return new List<Quote>();
}

if (timeSpan <= TimeSpan.Zero)
{
throw new ArgumentOutOfRangeException(nameof(timeSpan), timeSpan,
Expand Down
3 changes: 0 additions & 3 deletions src/_common/Quotes/Quote.Exceptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;

namespace Skender.Stock.Indicators;

public class InvalidQuotesException : ArgumentOutOfRangeException
Expand Down
4 changes: 1 addition & 3 deletions src/_common/Quotes/Quote.Validation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ public static IEnumerable<TQuote> Validate<TQuote>(

// check for duplicates
DateTime lastDate = DateTime.MinValue;
for (int i = 0; i < quotesList.Count; i++)
foreach (var q in quotesList)
{
TQuote q = quotesList[i];

if (lastDate == q.Date)
{
throw new InvalidQuotesException(
Expand Down
4 changes: 2 additions & 2 deletions src/_common/Results/Result.Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static IEnumerable<TResult> Condense<TResult>(

resultsList
.RemoveAll(match:
x => x.Value is null or (double and double.NaN));
x => x.Value is null or (not null and double.NaN));

return resultsList.ToSortedList();
}
Expand All @@ -43,7 +43,7 @@ public static IEnumerable<TResult> Condense<TResult>(

for (int i = first; i < reList.Count; i++)
{
IReusableResult? r = reList[i];
IReusableResult r = reList[i];
prices.Add(new(r.Date, r.Value.Null2NaN()));
}

Expand Down
2 changes: 1 addition & 1 deletion src/_common/Results/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</summary>
<param name="reusable">Indicator results to evaluate.</param>
<returns>Collection of tuple time series of
results with specified handline of nulls, without pruning.</returns>
results with specified handling of nulls, without pruning.</returns>
</type>
<type name="Prune">
<summary> Removes the recommended quantity of results from the beginning of the results list
Expand Down
2 changes: 1 addition & 1 deletion src/a-d/Dpo/Dpo.Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ public static IEnumerable<DpoResult> GetDpo(
int lookbackPeriods) => priceTuples
.ToSortedList()
.CalcDpo(lookbackPeriods);
}
}
2 changes: 1 addition & 1 deletion src/e-k/Epma/Epma.Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ public static IEnumerable<EpmaResult> GetEpma(
int lookbackPeriods) => priceTuples
.ToSortedList()
.CalcEpma(lookbackPeriods);
}
}
2 changes: 1 addition & 1 deletion src/e-k/Hma/Hma.Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ public static IEnumerable<HmaResult> GetHma(
int lookbackPeriods) => priceTuples
.ToSortedList()
.CalcHma(lookbackPeriods);
}
}
2 changes: 1 addition & 1 deletion src/m-r/ParabolicSar/ParabolicSar.Series.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal static List<ParabolicSarResult> CalcParabolicSar(
// roll through quotes
for (int i = 0; i < length; i++)
{
QuoteD? q = qdList[i];
QuoteD q = qdList[i];

ParabolicSarResult r = new(q.Date);
results.Add(r);
Expand Down
2 changes: 1 addition & 1 deletion src/m-r/PivotPoints/PivotPoints.Series.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ internal static TPivotPoint GetPivotPointWoodie<TPivotPoint>(
}

// pivot type lookup
internal static TPivotPoint? GetPivotPoint<TPivotPoint>(
internal static TPivotPoint GetPivotPoint<TPivotPoint>(
PivotPointType pointType, decimal open, decimal high, decimal low, decimal close)
where TPivotPoint : IPivotPoint, new()
=> pointType switch
Expand Down
20 changes: 10 additions & 10 deletions src/m-r/RollingPivots/RollingPivots.Series.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ internal static List<RollingPivotsResult> CalcRollingPivots<TQuote>(
}

// pivot points
RollingPivotsResult? wp = GetPivotPoint<RollingPivotsResult>(
RollingPivotsResult wp = GetPivotPoint<RollingPivotsResult>(
pointType, q.Open, windowHigh, windowLow, windowClose);

r.PP = wp?.PP;
r.S1 = wp?.S1;
r.S2 = wp?.S2;
r.S3 = wp?.S3;
r.S4 = wp?.S4;
r.R1 = wp?.R1;
r.R2 = wp?.R2;
r.R3 = wp?.R3;
r.R4 = wp?.R4;
r.PP = wp.PP;
r.S1 = wp.S1;
r.S2 = wp.S2;
r.S3 = wp.S3;
r.S4 = wp.S4;
r.R1 = wp.R1;
r.R2 = wp.R2;
r.R3 = wp.R3;
r.R4 = wp.R4;
}

results.Add(r);
Expand Down
2 changes: 1 addition & 1 deletion src/s-z/Sma/Sma.Analysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static IEnumerable<SmaAnalysis> CalcSmaAnalysis(
int lookbackPeriods)
{
// initialize
List<SmaAnalysis>? results = tpList
List<SmaAnalysis> results = tpList
.CalcSma(lookbackPeriods)
.Select(x => new SmaAnalysis(x.Date) { Sma = x.Sma })
.ToList();
Expand Down
Loading

0 comments on commit 7de4279

Please sign in to comment.