Skip to content

Commit 210d3a1

Browse files
authored
style: fix warn, minor updates (#228)
* style: private naming with _ * style: fix SA1137 by format * style: remove .DotSettings * style: remove redundant default
1 parent 9a209e9 commit 210d3a1

File tree

11 files changed

+61
-113
lines changed

11 files changed

+61
-113
lines changed

Prometheus.Client.sln

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "root", "root", "{7847B574-8
1313
.gitignore = .gitignore
1414
Directory.Build.props = Directory.Build.props
1515
LICENSE = LICENSE
16-
Prometheus.Client.sln.DotSettings = Prometheus.Client.sln.DotSettings
1716
Prometheus.Client.snk = Prometheus.Client.snk
1817
README.md = README.md
1918
stylecop.json = stylecop.json

Prometheus.Client.sln.DotSettings

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/Prometheus.Client.Abstractions/IMetricFamily.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public interface IMetricFamily<TMetric, TLabels>
2222
#if HasITuple
2323
where TLabels : struct, ITuple, IEquatable<TLabels>
2424
#else
25-
where TLabels : struct, IEquatable<TLabels>
25+
where TLabels : struct, IEquatable<TLabels>
2626
#endif
2727
{
2828
string Name { get; }

src/Prometheus.Client/Counter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Prometheus.Client;
88
/// <inheritdoc cref="ICounter" />
99
public sealed class Counter : MetricBase<MetricConfiguration>, ICounter
1010
{
11-
private ThreadSafeDouble _value = default;
11+
private ThreadSafeDouble _value;
1212

1313
public Counter(MetricConfiguration configuration, IReadOnlyList<string> labels)
1414
: base(configuration, labels)

src/Prometheus.Client/CounterInt64.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Prometheus.Client;
77

88
public sealed class CounterInt64 : MetricBase<MetricConfiguration>, ICounter<long>
99
{
10-
private ThreadSafeLong _value = default;
10+
private ThreadSafeLong _value;
1111

1212
public CounterInt64(MetricConfiguration configuration, IReadOnlyList<string> labels)
1313
: base(configuration, labels)

src/Prometheus.Client/LabelsHelper.cs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,26 @@ public static int GetSize<TTuple>()
4646
#if HasITuple
4747
return default(TTuple).Length;
4848
#else
49-
int GetTupleSize(Type tupleType)
49+
int GetTupleSize(Type tupleType)
50+
{
51+
var typeParams = tupleType.GenericTypeArguments;
52+
if (typeParams.Length == 8)
5053
{
51-
var typeParams = tupleType.GenericTypeArguments;
52-
if (typeParams.Length == 8)
53-
{
54-
return 7 + GetTupleSize(typeParams[7]);
55-
}
56-
57-
return typeParams.Length;
54+
return 7 + GetTupleSize(typeParams[7]);
5855
}
5956

60-
return GetTupleSize(typeof(TTuple));
57+
return typeParams.Length;
58+
}
59+
60+
return GetTupleSize(typeof(TTuple));
6161
#endif
6262
}
6363

6464
public static int GetHashCode<TTuple>(TTuple values)
6565
#if HasITuple
6666
where TTuple : struct, ITuple, IEquatable<TTuple>
6767
#else
68-
where TTuple : struct, IEquatable<TTuple>
68+
where TTuple : struct, IEquatable<TTuple>
6969
#endif
7070
{
7171
return TupleHelper<TTuple>.GetTupleHashCode(values);
@@ -80,7 +80,7 @@ public static int GetHashCode(IReadOnlyList<string> values)
8080
for (var i = 0; i < values.Count; i++)
8181
{
8282
var val = values[i];
83-
if(val == null)
83+
if (val == null)
8484
throw new ArgumentException("Label value cannot be empty");
8585

8686
result = HashCombine(result, val.GetHashCode());
@@ -93,7 +93,7 @@ public static string[] ToArray<TTuple>(TTuple values)
9393
#if HasITuple
9494
where TTuple : struct, ITuple, IEquatable<TTuple>
9595
#else
96-
where TTuple : struct, IEquatable<TTuple>
96+
where TTuple : struct, IEquatable<TTuple>
9797
#endif
9898
{
9999
if (!Validate(typeof(TTuple)))
@@ -106,7 +106,7 @@ public static TTuple FromArray<TTuple>(IReadOnlyList<string> values)
106106
#if HasITuple
107107
where TTuple : struct, ITuple, IEquatable<TTuple>
108108
#else
109-
where TTuple : struct, IEquatable<TTuple>
109+
where TTuple : struct, IEquatable<TTuple>
110110
#endif
111111
{
112112
return TupleHelper<TTuple>.FromArray(values);
@@ -176,8 +176,8 @@ Expression BuildUpTuple(Type tupleType, ParameterExpression source, int offset)
176176
}
177177
else
178178
{
179-
if(tupleType.GenericTypeArguments[i] != typeof(string))
180-
throw new NotSupportedException($"Cannot use {tupleType.GenericTypeArguments[i] .Name} as label name");
179+
if (tupleType.GenericTypeArguments[i] != typeof(string))
180+
throw new NotSupportedException($"Cannot use {tupleType.GenericTypeArguments[i].Name} as label name");
181181

182182
args[i] = Expression.Property(source, "Item", Expression.Constant(offset + i));
183183
}
@@ -235,25 +235,25 @@ private static class TupleHelper<TTuple>
235235
#if HasITuple
236236
where TTuple : struct, ITuple, IEquatable<TTuple>
237237
#else
238-
where TTuple : struct, IEquatable<TTuple>
238+
where TTuple : struct, IEquatable<TTuple>
239239
#endif
240240
{
241241
private static readonly int _size;
242242
private static readonly Func<IReadOnlyList<string>, TTuple> _parser;
243-
private static readonly Func<TTuple, string[], Func<string, int, string[], string[]>, string[]> FormatReducer;
244-
private static readonly Func<TTuple, int, Func<string, int, int, int>, int> HashCodeReducer;
243+
private static readonly Func<TTuple, string[], Func<string, int, string[], string[]>, string[]> _formatReducer;
244+
private static readonly Func<TTuple, int, Func<string, int, int, int>, int> _hashCodeReducer;
245245

246246
static TupleHelper()
247247
{
248248
_size = LabelsHelper.GetSize<TTuple>();
249249
_parser = LabelsHelper.GenerateParser<TTuple>();
250-
FormatReducer = LabelsHelper.MakeReducer<TTuple, string[]>();
251-
HashCodeReducer = LabelsHelper.MakeReducer<TTuple, int>();
250+
_formatReducer = LabelsHelper.MakeReducer<TTuple, string[]>();
251+
_hashCodeReducer = LabelsHelper.MakeReducer<TTuple, int>();
252252
}
253253

254254
public static string[] ToArray(TTuple values)
255255
{
256-
return FormatReducer(values, new string[_size], (item, index, aggregated) =>
256+
return _formatReducer(values, new string[_size], (item, index, aggregated) =>
257257
{
258258
aggregated[index] = item;
259259
return aggregated;
@@ -262,10 +262,11 @@ public static string[] ToArray(TTuple values)
262262

263263
public static int GetTupleHashCode(TTuple values)
264264
{
265-
return HashCodeReducer(values, 0, (item, _, aggregated) =>
265+
return _hashCodeReducer(values, 0, (item, _, aggregated) =>
266266
{
267-
if(item == null)
267+
if (item == null)
268268
throw new ArgumentException("Label value cannot be empty");
269+
269270
return HashCombine(aggregated, item.GetHashCode());
270271
});
271272
}

src/Prometheus.Client/MetricFactory.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public IMetricFamily<ICounter, TLabels> CreateCounter<TLabels>(string name, stri
3838
#if HasITuple
3939
where TLabels : struct, ITuple, IEquatable<TLabels>
4040
#else
41-
where TLabels : struct, IEquatable<TLabels>
41+
where TLabels : struct, IEquatable<TLabels>
4242
#endif
4343
{
4444
var metric = TryGetByName<IMetricFamily<ICounter, TLabels>>(name);
@@ -91,7 +91,7 @@ public IMetricFamily<ICounter<long>, TLabels> CreateCounterInt64<TLabels>(string
9191
#if HasITuple
9292
where TLabels : struct, ITuple, IEquatable<TLabels>
9393
#else
94-
where TLabels : struct, IEquatable<TLabels>
94+
where TLabels : struct, IEquatable<TLabels>
9595
#endif
9696
{
9797
var metric = TryGetByName<IMetricFamily<ICounter<long>, TLabels>>(name);
@@ -139,7 +139,7 @@ public IMetricFamily<IGauge, TLabels> CreateGauge<TLabels>(string name, string h
139139
#if HasITuple
140140
where TLabels : struct, ITuple, IEquatable<TLabels>
141141
#else
142-
where TLabels : struct, IEquatable<TLabels>
142+
where TLabels : struct, IEquatable<TLabels>
143143
#endif
144144
{
145145
var metric = TryGetByName<IMetricFamily<IGauge, TLabels>>(name);
@@ -197,7 +197,7 @@ public IMetricFamily<IGauge<long>, TLabels> CreateGaugeInt64<TLabels>(string nam
197197
#if HasITuple
198198
where TLabels : struct, ITuple, IEquatable<TLabels>
199199
#else
200-
where TLabels : struct, IEquatable<TLabels>
200+
where TLabels : struct, IEquatable<TLabels>
201201
#endif
202202
{
203203
var metric = TryGetByName<IMetricFamily<IGauge<long>, TLabels>>(name);
@@ -250,7 +250,7 @@ public IMetricFamily<IHistogram, TLabels> CreateHistogram<TLabels>(string name,
250250
#if HasITuple
251251
where TLabels : struct, ITuple, IEquatable<TLabels>
252252
#else
253-
where TLabels : struct, IEquatable<TLabels>
253+
where TLabels : struct, IEquatable<TLabels>
254254
#endif
255255
{
256256
var metric = TryGetByName<IMetricFamily<IHistogram, TLabels>>(name);
@@ -313,7 +313,7 @@ public IMetricFamily<IUntyped, TLabels> CreateUntyped<TLabels>(string name, stri
313313
#if HasITuple
314314
where TLabels : struct, ITuple, IEquatable<TLabels>
315315
#else
316-
where TLabels : struct, IEquatable<TLabels>
316+
where TLabels : struct, IEquatable<TLabels>
317317
#endif
318318
{
319319
var metric = TryGetByName<IMetricFamily<IUntyped, TLabels>>(name);
@@ -411,7 +411,7 @@ public IMetricFamily<ISummary, TLabels> CreateSummary<TLabels>(
411411
#if HasITuple
412412
where TLabels : struct, ITuple, IEquatable<TLabels>
413413
#else
414-
where TLabels : struct, IEquatable<TLabels>
414+
where TLabels : struct, IEquatable<TLabels>
415415
#endif
416416
{
417417
var metric = TryGetByName<IMetricFamily<ISummary, TLabels>>(name);
@@ -474,7 +474,7 @@ public void Release<TMetric, TLabels>(IMetricFamily<TMetric, TLabels> metricFami
474474
#if HasITuple
475475
where TLabels : struct, ITuple, IEquatable<TLabels>
476476
#else
477-
where TLabels : struct, IEquatable<TLabels>
477+
where TLabels : struct, IEquatable<TLabels>
478478
#endif
479479
{
480480
if (metricFamily == null)
@@ -510,7 +510,7 @@ private static void ValidateLabelNames<TMetric, TLabels>(IMetricFamily<TMetric,
510510
#if HasITuple
511511
where TLabels : struct, ITuple, IEquatable<TLabels>
512512
#else
513-
where TLabels : struct, IEquatable<TLabels>
513+
where TLabels : struct, IEquatable<TLabels>
514514
#endif
515515
{
516516
if (LabelsHelper.GetHashCode(metric.LabelNames) != LabelsHelper.GetHashCode(actualNames))
@@ -541,7 +541,7 @@ internal MetricFamily<ICounter, Counter, TLabels, MetricConfiguration> CreateCou
541541
#if HasITuple
542542
where TLabels : struct, ITuple, IEquatable<TLabels>
543543
#else
544-
where TLabels : struct, IEquatable<TLabels>
544+
where TLabels : struct, IEquatable<TLabels>
545545
#endif
546546
{
547547
return _registry.GetOrAdd(configuration,
@@ -555,7 +555,7 @@ internal MetricFamily<ICounter<long>, CounterInt64, TLabels, MetricConfiguration
555555
#if HasITuple
556556
where TLabels : struct, ITuple, IEquatable<TLabels>
557557
#else
558-
where TLabels : struct, IEquatable<TLabels>
558+
where TLabels : struct, IEquatable<TLabels>
559559
#endif
560560
{
561561
return _registry.GetOrAdd(configuration,
@@ -569,7 +569,7 @@ internal MetricFamily<IGauge, Gauge, TLabels, MetricConfiguration> CreateGaugeIn
569569
#if HasITuple
570570
where TLabels : struct, ITuple, IEquatable<TLabels>
571571
#else
572-
where TLabels : struct, IEquatable<TLabels>
572+
where TLabels : struct, IEquatable<TLabels>
573573
#endif
574574
{
575575
return _registry.GetOrAdd(configuration,
@@ -583,7 +583,7 @@ internal MetricFamily<IGauge<long>, GaugeInt64, TLabels, MetricConfiguration> Cr
583583
#if HasITuple
584584
where TLabels : struct, ITuple, IEquatable<TLabels>
585585
#else
586-
where TLabels : struct, IEquatable<TLabels>
586+
where TLabels : struct, IEquatable<TLabels>
587587
#endif
588588
{
589589
return _registry.GetOrAdd(configuration,
@@ -597,7 +597,7 @@ internal MetricFamily<IHistogram, Histogram, TLabels, HistogramConfiguration> Cr
597597
#if HasITuple
598598
where TLabels : struct, ITuple, IEquatable<TLabels>
599599
#else
600-
where TLabels : struct, IEquatable<TLabels>
600+
where TLabels : struct, IEquatable<TLabels>
601601
#endif
602602
{
603603
return _registry.GetOrAdd(configuration,
@@ -611,7 +611,7 @@ internal MetricFamily<IUntyped, Untyped, TLabels, MetricConfiguration> CreateUnt
611611
#if HasITuple
612612
where TLabels : struct, ITuple, IEquatable<TLabels>
613613
#else
614-
where TLabels : struct, IEquatable<TLabels>
614+
where TLabels : struct, IEquatable<TLabels>
615615
#endif
616616
{
617617
return _registry.GetOrAdd(configuration,
@@ -625,7 +625,7 @@ internal MetricFamily<ISummary, Summary, TLabels, SummaryConfiguration> CreateSu
625625
#if HasITuple
626626
where TLabels : struct, ITuple, IEquatable<TLabels>
627627
#else
628-
where TLabels : struct, IEquatable<TLabels>
628+
where TLabels : struct, IEquatable<TLabels>
629629
#endif
630630
{
631631
return _registry.GetOrAdd(configuration,

0 commit comments

Comments
 (0)