Skip to content

Commit 510de3f

Browse files
committed
Fix warnings
1 parent 5430bb5 commit 510de3f

File tree

19 files changed

+133
-23
lines changed

19 files changed

+133
-23
lines changed

Benchmarks/Boxed.Mapping.Benchmark/MapArrayBenchmark.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace Boxed.Mapping.Benchmark;
1515
[HtmlExporter]
1616
[CsvMeasurementsExporter]
1717
[RPlotExporter]
18+
[SimpleJob(RuntimeMoniker.Net70)]
1819
[SimpleJob(RuntimeMoniker.Net60)]
1920
[SimpleJob(RuntimeMoniker.Net50)]
2021
[SimpleJob(RuntimeMoniker.NetCoreApp30)]
@@ -38,6 +39,7 @@ public void GlobalSetup()
3839
this.mapFrom = new MapFrom[100];
3940
for (var i = 0; i < this.mapFrom.Length; ++i)
4041
{
42+
#pragma warning disable CA5394 // Do not use insecure randomness
4143
this.mapFrom[i] = new MapFrom()
4244
{
4345
BooleanFrom = this.random.NextDouble() > 0.5D,
@@ -46,6 +48,7 @@ public void GlobalSetup()
4648
LongFrom = this.random.Next(),
4749
StringFrom = this.random.Next().ToString(CultureInfo.InvariantCulture),
4850
};
51+
#pragma warning restore CA5394 // Do not use insecure randomness
4952
}
5053
}
5154

Benchmarks/Boxed.Mapping.Benchmark/MapListBenchmark.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace Boxed.Mapping.Benchmark;
1616
[HtmlExporter]
1717
[CsvMeasurementsExporter]
1818
[RPlotExporter]
19+
[SimpleJob(RuntimeMoniker.Net70)]
1920
[SimpleJob(RuntimeMoniker.Net60)]
2021
[SimpleJob(RuntimeMoniker.Net50)]
2122
[SimpleJob(RuntimeMoniker.NetCoreApp30)]
@@ -39,6 +40,7 @@ public void GlobalSetup()
3940
this.mapFrom = new List<MapFrom>();
4041
for (var i = 0; i < 100; ++i)
4142
{
43+
#pragma warning disable CA5394 // Do not use insecure randomness
4244
this.mapFrom.Add(
4345
new MapFrom()
4446
{
@@ -48,9 +50,11 @@ public void GlobalSetup()
4850
LongFrom = this.random.Next(),
4951
StringFrom = this.random.Next().ToString(CultureInfo.InvariantCulture),
5052
});
53+
#pragma warning restore CA5394 // Do not use insecure randomness
5154
}
5255
}
5356

57+
#pragma warning disable CA1002 // Do not expose generic lists
5458
[Benchmark(Baseline = true)]
5559
public List<MapTo> Baseline()
5660
{
@@ -75,4 +79,5 @@ public List<MapTo> Baseline()
7579

7680
[Benchmark]
7781
public List<MapTo> Automapper() => this.automapper.Map<List<MapTo>>(this.mapFrom);
82+
#pragma warning restore CA1002 // Do not expose generic lists
7883
}

Benchmarks/Boxed.Mapping.Benchmark/MapObjectBenchmark.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace Boxed.Mapping.Benchmark;
1515
[HtmlExporter]
1616
[CsvMeasurementsExporter]
1717
[RPlotExporter]
18+
[SimpleJob(RuntimeMoniker.Net70)]
1819
[SimpleJob(RuntimeMoniker.Net60)]
1920
[SimpleJob(RuntimeMoniker.Net50)]
2021
[SimpleJob(RuntimeMoniker.NetCoreApp30)]
@@ -34,6 +35,7 @@ public MapObjectBenchmark()
3435

3536
[GlobalSetup]
3637
public void GlobalSetup() =>
38+
#pragma warning disable CA5394 // Do not use insecure randomness
3739
this.mapFrom = new MapFrom()
3840
{
3941
BooleanFrom = this.random.NextDouble() > 0.5D,
@@ -42,6 +44,7 @@ public void GlobalSetup() =>
4244
LongFrom = this.random.Next(),
4345
StringFrom = this.random.Next().ToString(CultureInfo.InvariantCulture),
4446
};
47+
#pragma warning restore CA5394 // Do not use insecure randomness
4548

4649
[Benchmark(Baseline = true)]
4750
public MapTo Baseline() =>

Source/Boxed.AspNetCore.TagHelpers/OpenGraph/ObjectTypes/OpenGraphMetadata.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ public abstract class OpenGraphMetadata : TagHelper
160160
/// Gets or sets the images, videos or audio which should represent your object within the graph.
161161
/// </summary>
162162
[HtmlAttributeName(MediaAttributeName)]
163+
#pragma warning disable CA2227 // Collection properties should be read only
163164
public ICollection<OpenGraphMedia>? Media { get; set; }
165+
#pragma warning restore CA2227 // Collection properties should be read only
164166

165167
/// <summary>
166168
/// Gets the namespace of this open graph type.
@@ -372,12 +374,9 @@ private static IUrlHelper GetUrlHelper(HttpContext httpContext)
372374
var services = httpContext.RequestServices;
373375
var actionContext = services
374376
.GetRequiredService<IActionContextAccessor>()
375-
.ActionContext;
376-
if (actionContext is null)
377-
{
377+
.ActionContext ??
378378
throw new InvalidOperationException(
379379
"ActionContext is null. Attempted to retrieve the ActionContext outside of a request.");
380-
}
381380

382381
var urlHelper = services
383382
.GetRequiredService<IUrlHelperFactory>()

Source/Boxed.AspNetCore.TagHelpers/SubresourceIntegrityTagHelper.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,9 @@ protected SubresourceIntegrityTagHelper(
6161
this.webHostEnvironment = webHostEnvironment;
6262
this.htmlEncoder = htmlEncoder;
6363

64-
var actionContext = actionContextAccessor.ActionContext;
65-
if (actionContext is null)
66-
{
64+
var actionContext = actionContextAccessor.ActionContext ??
6765
throw new InvalidOperationException(
6866
"ActionContext is null. Attempted to retrieve the ActionContext outside of a request.");
69-
}
7067

7168
this.urlHelper = urlHelperFactory.GetUrlHelper(actionContext);
7269
}
@@ -92,7 +89,9 @@ protected SubresourceIntegrityTagHelper(
9289
/// <value>
9390
/// The name of the attribute containing the URL to the resource.
9491
/// </value>
92+
#pragma warning disable CA1056 // URI-like properties should not be strings
9593
protected abstract string UrlAttributeName { get; }
94+
#pragma warning restore CA1056 // URI-like properties should not be strings
9695

9796
/// <summary>
9897
/// Asynchronously executes the <see cref="TagHelper" /> with the given context and output.
@@ -126,7 +125,9 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
126125
/// </summary>
127126
/// <param name="url">The URL to the resource.</param>
128127
/// <returns>A key value for the URL.</returns>
128+
#pragma warning disable CA1054 // URI-like parameters should not be strings
129129
protected virtual string GetSriKey(string url) => "SRI:" + url;
130+
#pragma warning restore CA1054 // URI-like parameters should not be strings
130131

131132
/// <summary>
132133
/// Reads all bytes from the file with the specified path.

Source/Boxed.AspNetCore.TagHelpers/Twitter/Cards/TwitterCardApp.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ public class TwitterCardApp : TwitterCard
5252
/// scheme name).
5353
/// </summary>
5454
[HtmlAttributeName(GooglePlayCustomUrlSchemeAttributeName)]
55+
#pragma warning disable CA1056 // URI-like properties should not be strings
5556
public string? GooglePlayCustomUrlScheme { get; set; }
57+
#pragma warning restore CA1056 // URI-like properties should not be strings
5658

5759
/// <summary>
5860
/// Gets or sets numeric representation of your iPad app ID in the App Store (.i.e. "307234931").
@@ -64,7 +66,9 @@ public class TwitterCardApp : TwitterCard
6466
/// Gets or sets your iPad app’s custom URL scheme (you must include "://" after your scheme name).
6567
/// </summary>
6668
[HtmlAttributeName(IPadCustomUrlSchemeAttributeName)]
69+
#pragma warning disable CA1056 // URI-like properties should not be strings
6770
public string? IPadCustomUrlScheme { get; set; }
71+
#pragma warning restore CA1056 // URI-like properties should not be strings
6872

6973
/// <summary>
7074
/// Gets or sets numeric representation of your iPhone app ID in the App Store (.i.e. “307234931”).
@@ -77,7 +81,9 @@ public class TwitterCardApp : TwitterCard
7781
/// scheme name).
7882
/// </summary>
7983
[HtmlAttributeName(IPhoneCustomUrlSchemeAttributeName)]
84+
#pragma warning disable CA1056 // URI-like properties should not be strings
8085
public string? IPhoneCustomUrlScheme { get; set; }
86+
#pragma warning restore CA1056 // URI-like properties should not be strings
8187

8288
/// <summary>
8389
/// Gets the type of the Twitter card.

Source/Boxed.AspNetCore/Cursor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@ public static (string? FirstCursor, string? LastCursor) GetFirstAndLastCursor<TI
6464
{
6565
ArgumentNullException.ThrowIfNull(getCursorProperty);
6666

67+
#pragma warning disable CA1851 // Possible multiple enumerations of 'IEnumerable' collection
6768
if (enumerable is null || !enumerable.Any())
6869
{
6970
return (null, null);
7071
}
7172

7273
var firstCursor = ToCursor(getCursorProperty(enumerable.First()));
7374
var lastCursor = ToCursor(getCursorProperty(enumerable.Last()));
75+
#pragma warning restore CA1851 // Possible multiple enumerations of 'IEnumerable' collection
7476

7577
return (firstCursor, lastCursor);
7678
}

Source/Boxed.AspNetCore/FriendlyUrlHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ public static string GetFriendlyTitle(string title, bool remapToAscii = false, i
136136
/// <returns>The remapped character.</returns>
137137
private static string RemapInternationalCharToAscii(char character)
138138
{
139+
#pragma warning disable CA1308 // Normalize strings to uppercase
139140
var s = new string(character, 1).ToLowerInvariant();
141+
#pragma warning restore CA1308 // Normalize strings to uppercase
140142
if ("àåáâäãåąā".Contains(s, StringComparison.Ordinal))
141143
{
142144
return "a";

Source/Boxed.AspNetCore/HttpException.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ namespace Boxed.AspNetCore;
77
/// Describes an exception that occurred during the processing of HTTP requests.
88
/// </summary>
99
/// <seealso cref="Exception" />
10+
#pragma warning disable CA1032 // Implement standard exception constructors
1011
public class HttpException : Exception
12+
#pragma warning restore CA1032 // Implement standard exception constructors
1113
{
1214
/// <summary>
1315
/// Initializes a new instance of the <see cref="HttpException" /> class.

Source/Boxed.AspNetCore/RedirectToCanonicalUrlRule.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ protected virtual bool TryGetCanonicalUrl(RewriteContext context, [NotNullWhen(f
127127
{
128128
if (char.IsUpper(character))
129129
{
130+
#pragma warning disable CA1308 // Normalize strings to uppercase
130131
request.Path = new PathString(request.Path.Value.ToLowerInvariant());
132+
#pragma warning restore CA1308 // Normalize strings to uppercase
131133
isCanonical = false;
132134
break;
133135
}
@@ -139,7 +141,9 @@ protected virtual bool TryGetCanonicalUrl(RewriteContext context, [NotNullWhen(f
139141
{
140142
if (char.IsUpper(character))
141143
{
144+
#pragma warning disable CA1308 // Normalize strings to uppercase
142145
request.QueryString = new QueryString(request.QueryString.Value.ToLowerInvariant());
146+
#pragma warning restore CA1308 // Normalize strings to uppercase
143147
isCanonical = false;
144148
break;
145149
}

0 commit comments

Comments
 (0)