Skip to content

Commit d9d76ac

Browse files
committed
Enable All analyzers on primary project
1 parent 13a316e commit d9d76ac

File tree

134 files changed

+421
-35
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+421
-35
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ insert_final_newline = true
1111
indent_size = 4
1212
dotnet_sort_system_directives_first = true
1313
csharp_style_namespace_declarations = file_scoped:warning
14+
dotnet_analyzer_diagnostic.category-Style.severity = warning
1415
dotnet_diagnostic.IDE0005.severity = warning
1516
resharper_redundant_empty_object_creation_argument_list_highlighting = none
1617

src/GovUk.Frontend.AspNetCore/AttributeDictionaryExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace GovUk.Frontend.AspNetCore;
77
/// </summary>
88
internal static class AttributeDictionaryExtensions
99
{
10+
private static readonly char[] _classSeparator = [' '];
11+
1012
/// <summary>
1113
/// Adds a CSS class to the list of CSS classes in the tag if it does not already specified.
1214
/// If there are already CSS classes on the tag then a space character and the new class will be appended to
@@ -25,7 +27,7 @@ public static void MergeCssClass(this AttributeDictionary attributeDictionary, s
2527

2628
if (attributeDictionary.TryGetValue("class", out var currentValue))
2729
{
28-
var classes = currentValue!.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
30+
var classes = currentValue!.Split(_classSeparator, StringSplitOptions.RemoveEmptyEntries);
2931

3032
if (!classes.Contains(value, StringComparer.OrdinalIgnoreCase))
3133
{

src/GovUk.Frontend.AspNetCore/ComponentGeneration/AttributeCollection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public AttributeCollection(IEnumerable<TagHelperAttribute> tagHelperAttributes)
6161
internal AttributeCollection(IEnumerable<Attribute> attributes)
6262
{
6363
ArgumentNullException.ThrowIfNull(attributes);
64+
6465
_attributes = attributes.ToDictionary(a => a.Name, a => a);
6566
}
6667

src/GovUk.Frontend.AspNetCore/ComponentGeneration/DefaultComponentGenerator.Functions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Globalization;
12
using System.Text;
23
using Fluid;
34
using Fluid.Values;
@@ -137,7 +138,7 @@ public static FluidValue GovukI18nAttributes(FunctionArguments args, TemplateCon
137138
var pluralRule = pluralRuleParts[0].ToStringValue();
138139
var message = pluralRuleParts[1].ToStringValue();
139140

140-
sb.Append($" data-i18n.{key}.{pluralRule}=\"{_encoder.Encode(message)}\"");
141+
sb.Append(CultureInfo.InvariantCulture, $" data-i18n.{key}.{pluralRule}=\"{_encoder.Encode(message)}\"");
141142
}
142143

143144
return new StringValue(sb.ToString(), encode: false);
@@ -172,7 +173,7 @@ public static FluidValue Not(FunctionArguments args, TemplateContext context)
172173
return FluidValue.Create(!args.At(0).ToBooleanValue(), context.Options);
173174
}
174175

175-
public static FluidValue String(FunctionArguments args, TemplateContext context)
176+
public static StringValue String(FunctionArguments args, TemplateContext context)
176177
{
177178
return StringValue.Create(args.At(0).ToStringValue());
178179
}

src/GovUk.Frontend.AspNetCore/ComponentGeneration/DefaultComponentGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public DefaultComponentGenerator(IRazorViewEngine viewEngine, IHttpContextAccess
6666
}
6767

6868
// If the object is an Options class, convert its property names to camel case
69-
if (v.GetType().Namespace?.StartsWith(GetType().Namespace!) == true && !v.GetType().IsArray)
69+
if (v.GetType().Namespace?.StartsWith(GetType().Namespace!, StringComparison.Ordinal) == true && !v.GetType().IsArray)
7070
{
7171
return new ConvertNamesFromJsonTypeInfoObjectValue(v, optionsJsonSerializerOptions);
7272
}

src/GovUk.Frontend.AspNetCore/ComponentGeneration/TemplateString.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,19 @@ internal FluidValue ToFluidValue(HtmlEncoder encoder)
8888
/// <param name="value">The unencoded <see cref="String"/>.</param>
8989
/// <returns></returns>
9090
[return: NotNullIfNotNull(nameof(value))]
91+
#pragma warning disable CA2225
9192
public static implicit operator TemplateString?(string? value) => value is null ? null : new(value);
93+
#pragma warning restore CA2225
9294

9395
/// <summary>
9496
/// Creates a <see cref="TemplateString"/> from <see cref="HtmlString"/>.
9597
/// </summary>
9698
/// <param name="content">The <see cref="IHtmlContent"/> to create the <see cref="TemplateString"/> from.</param>
9799
/// <returns>A new <see cref="TemplateString"/> wrapping the specified <see cref="HtmlString"/>.</returns>
98100
[return: NotNullIfNotNull(nameof(content))]
101+
#pragma warning disable CA2225
99102
public static implicit operator TemplateString?(HtmlString? content) => content is null ? null : new(content);
103+
#pragma warning restore CA2225
100104

101105
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
102106
public static bool operator ==(TemplateString? first, TemplateString? second) =>
@@ -164,6 +168,7 @@ public static class TemplateStringExtensions
164168
public static TemplateString AppendCssClasses(this TemplateString? templateString, HtmlEncoder encoder, params TemplateString[] classNames)
165169
{
166170
ArgumentNullException.ThrowIfNull(encoder);
171+
ArgumentNullException.ThrowIfNull(classNames);
167172

168173
var original = templateString?.ToHtmlString(encoder).Trim() ?? "";
169174

src/GovUk.Frontend.AspNetCore/ComponentGeneration/Templates/GovUkComponentView.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public abstract class GovUkComponentView<TModel> : RazorPage<TModel>
99
{
1010
protected IHtmlContent? Classes(params object?[] classNames)
1111
{
12+
ArgumentNullException.ThrowIfNull(classNames);
13+
1214
if (classNames.Length == 0)
1315
{
1416
return null;

src/GovUk.Frontend.AspNetCore/ComponentGeneration/Templates/TagHelpers/AttributesTagHelper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ public class AttributesTagHelper : TagHelper
1212

1313
public override void Process(TagHelperContext context, TagHelperOutput output)
1414
{
15+
ArgumentNullException.ThrowIfNull(context);
16+
ArgumentNullException.ThrowIfNull(output);
17+
1518
if (Attributes is null)
1619
{
1720
return;

src/GovUk.Frontend.AspNetCore/ComponentGeneration/Templates/TagHelpers/TrimContentTagHelper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ public class TrimContentTagHelper : TagHelper
99
{
1010
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
1111
{
12+
ArgumentNullException.ThrowIfNull(context);
13+
ArgumentNullException.ThrowIfNull(output);
14+
1215
var content = (await output.GetChildContentAsync()).GetContent();
1316
output.Content.SetHtmlContent(content.Trim());
1417
output.Attributes.RemoveAll("_gfa-trim-content");

src/GovUk.Frontend.AspNetCore/DefaultModelHelper.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,11 @@ internal class DefaultModelHelper : IModelHelper
88
{
99
private delegate string GetFullHtmlFieldNameDelegate(ViewContext viewContext, string expression);
1010

11-
private static readonly GetFullHtmlFieldNameDelegate s_getFullHtmlFieldNameDelegate;
12-
13-
static DefaultModelHelper()
14-
{
15-
s_getFullHtmlFieldNameDelegate =
16-
(GetFullHtmlFieldNameDelegate)typeof(IHtmlGenerator).Assembly
17-
.GetType("Microsoft.AspNetCore.Mvc.ViewFeatures.NameAndIdProvider", throwOnError: true)!
18-
.GetMethod("GetFullHtmlFieldName", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static)!
19-
.CreateDelegate(typeof(GetFullHtmlFieldNameDelegate));
20-
}
11+
private static readonly GetFullHtmlFieldNameDelegate _getFullHtmlFieldNameDelegate =
12+
(GetFullHtmlFieldNameDelegate)typeof(IHtmlGenerator).Assembly
13+
.GetType("Microsoft.AspNetCore.Mvc.ViewFeatures.NameAndIdProvider", throwOnError: true)!
14+
.GetMethod("GetFullHtmlFieldName", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static)!
15+
.CreateDelegate(typeof(GetFullHtmlFieldNameDelegate));
2116

2217
public virtual string? GetDescription(ModelExplorer modelExplorer) => modelExplorer.Metadata.Description;
2318

@@ -42,7 +37,7 @@ public virtual string GetFullHtmlFieldName(ViewContext viewContext, string expre
4237
ArgumentNullException.ThrowIfNull(viewContext);
4338
ArgumentNullException.ThrowIfNull(expression);
4439

45-
return s_getFullHtmlFieldNameDelegate(viewContext, expression);
40+
return _getFullHtmlFieldNameDelegate(viewContext, expression);
4641
}
4742

4843
public virtual string? GetModelValue(ViewContext viewContext, ModelExplorer modelExplorer, string expression)

0 commit comments

Comments
 (0)