Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run analyzers that sonar cloud runs #814

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ csharp_style_namespace_declarations = file_scoped:error
dotnet_diagnostic.IDE1006.severity = error

# Unused usings
dotnet_diagnostic.IDE0005.severity = suggestion
dotnet_diagnostic.IDE0005.severity = warning

# CA1848: Use the LoggerMessage delegates
dotnet_diagnostic.CA1848.severity = none
Expand All @@ -123,7 +123,10 @@ dotnet_diagnostic.CA1727.severity = suggestion
dotnet_diagnostic.CA2254.severity = none

# CA1822: Mark members as static
dotnet_diagnostic.CA1822.severity = suggestion
dotnet_diagnostic.CA1822.severity = warning

# IDE0052: Remove unread private members
dotnet_diagnostic.IDE0052.severity = warning

# IDE0080: Remove unnecessary suppression operator
dotnet_diagnostic.IDE0080.severity = error
Expand All @@ -146,6 +149,9 @@ dotnet_diagnostic.CA2201.severity = suggestion
# TODO: fixing this would be breaking
dotnet_diagnostic.CA1720.severity = suggestion

# CA1816: Call GC.SuppressFinalize correctly
dotnet_diagnostic.CA1816.severity = warning

[Program.cs]
dotnet_diagnostic.CA1050.severity = none
dotnet_diagnostic.S1118.severity = none
4 changes: 1 addition & 3 deletions src/Altinn.App.Api/Controllers/ProfileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ namespace Altinn.App.Api.Controllers;
public class ProfileController : Controller
{
private readonly IProfileClient _profileClient;
private readonly ILogger _logger;

/// <summary>
/// Initializes a new instance of the <see cref="ProfileController"/> class
/// </summary>
public ProfileController(IProfileClient profileClient, ILogger<ProfileController> logger)
public ProfileController(IProfileClient profileClient)
{
_profileClient = profileClient;
_logger = logger;
}

/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions src/Altinn.App.Api/Extensions/WebHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Altinn.App.Core.Extensions;
using Altinn.App.Core.Features.Maskinporten;
using Altinn.App.Core.Features.Maskinporten.Models;
using Microsoft.Extensions.FileProviders;

namespace Altinn.App.Api.Extensions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using Altinn.App.Core.Features.Maskinporten.Exceptions;
using Altinn.App.Core.Features.Maskinporten.Models;
using Microsoft.IdentityModel.Tokens;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Altinn.App.Core.Features;

partial class Telemetry
{
private void InitValidation(InitContext context) { }
private static void InitValidation(InitContext context) { }

internal Activity? StartValidateInstanceAtTaskActivity(Instance instance, string taskId)
{
Expand Down
9 changes: 7 additions & 2 deletions src/Altinn.App.Core/Helpers/DataModel/DataModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@
return null;
}

private object? GetModelDataRecursive(string[] keys, int index, object currentModel, ReadOnlySpan<int> indicies)
private static object? GetModelDataRecursive(
string[] keys,
int index,
object currentModel,
ReadOnlySpan<int> indicies
)
{
if (index == keys.Length)
{
Expand Down Expand Up @@ -136,7 +141,7 @@
return rowIndices.Length == 0 ? null : rowIndices;
}

private string[] GetResolvedKeysRecursive(

Check failure on line 144 in src/Altinn.App.Core/Helpers/DataModel/DataModel.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (macos-latest)

Member 'GetResolvedKeysRecursive' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check failure on line 144 in src/Altinn.App.Core/Helpers/DataModel/DataModel.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (macos-latest)

Member 'GetResolvedKeysRecursive' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check failure on line 144 in src/Altinn.App.Core/Helpers/DataModel/DataModel.cs

View workflow job for this annotation

GitHub Actions / Static code analysis

Member 'GetResolvedKeysRecursive' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check failure on line 144 in src/Altinn.App.Core/Helpers/DataModel/DataModel.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Member 'GetResolvedKeysRecursive' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check failure on line 144 in src/Altinn.App.Core/Helpers/DataModel/DataModel.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Member 'GetResolvedKeysRecursive' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check failure on line 144 in src/Altinn.App.Core/Helpers/DataModel/DataModel.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (ubuntu-latest)

Member 'GetResolvedKeysRecursive' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check failure on line 144 in src/Altinn.App.Core/Helpers/DataModel/DataModel.cs

View workflow job for this annotation

GitHub Actions / Run dotnet build and test (ubuntu-latest)

Member 'GetResolvedKeysRecursive' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)
string[] keyParts,
object currentModel,
int currentIndex = 0,
Expand Down Expand Up @@ -404,7 +409,7 @@
return VerifyKeyRecursive(key.Split('.'), 0, _serviceModel.GetType());
}

private bool VerifyKeyRecursive(string[] keys, int index, Type currentModel)
private static bool VerifyKeyRecursive(string[] keys, int index, Type currentModel)
{
if (index == keys.Length)
{
Expand Down
9 changes: 2 additions & 7 deletions src/Altinn.App.Core/Implementation/AppResourcesSI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Altinn.App.Core.Models.Layout;
using Altinn.App.Core.Models.Layout.Components;
using Altinn.Platform.Storage.Interface.Models;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
Expand All @@ -30,7 +29,6 @@ public class AppResourcesSI : IAppResources

private readonly AppSettings _settings;
private readonly IAppMetadata _appMetadata;
private readonly IWebHostEnvironment _hostingEnvironment;
private readonly ILogger _logger;
private readonly Telemetry? _telemetry;

Expand All @@ -39,20 +37,17 @@ public class AppResourcesSI : IAppResources
/// </summary>
/// <param name="settings">The app repository settings.</param>
/// <param name="appMetadata">App metadata service</param>
/// <param name="hostingEnvironment">The hosting environment</param>
/// <param name="logger">A logger from the built in logger factory.</param>
/// <param name="telemetry">Telemetry for traces and metrics.</param>
public AppResourcesSI(
IOptions<AppSettings> settings,
IAppMetadata appMetadata,
IWebHostEnvironment hostingEnvironment,
ILogger<AppResourcesSI> logger,
Telemetry? telemetry = null
)
{
_settings = settings.Value;
_appMetadata = appMetadata;
_hostingEnvironment = hostingEnvironment;
_logger = logger;
_telemetry = telemetry;
}
Expand Down Expand Up @@ -403,7 +398,7 @@ public byte[] GetRuleHandlerForSet(string id)
return ReadFileByte(filename);
}

private byte[] ReadFileByte(string fileName)
private static byte[] ReadFileByte(string fileName)
{
byte[]? filedata = null;
if (File.Exists(fileName))
Expand All @@ -416,7 +411,7 @@ private byte[] ReadFileByte(string fileName)
#nullable restore
}

private byte[] ReadFileContentsFromLegalPath(string legalPath, string filePath)
private static byte[] ReadFileContentsFromLegalPath(string legalPath, string filePath)
{
var fullFileName = legalPath + filePath;
if (!PathHelper.ValidateLegalFilePath(legalPath, fullFileName))
Expand Down
2 changes: 1 addition & 1 deletion src/Altinn.App.Core/Implementation/PrefillSI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ private void LoopThroughDictionaryAndAssignValuesToDataModel(
}
}

private Dictionary<string, string> SwapKeyValuesForPrefill(Dictionary<string, string> externalPrefil)
private static Dictionary<string, string> SwapKeyValuesForPrefill(Dictionary<string, string> externalPrefil)
{
return externalPrefil.ToDictionary(x => x.Value, x => x.Key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class EventsSubscriptionClient : IEventsSubscription
{
private static readonly JsonSerializerOptions _jsonSerializerOptions = new() { PropertyNameCaseInsensitive = true };

private readonly PlatformSettings _platformSettings;
private readonly GeneralSettings _generalSettings;
private readonly HttpClient _client;
private readonly IEventSecretCodeProvider _secretCodeProvider;
Expand All @@ -34,7 +33,6 @@ public EventsSubscriptionClient(
ILogger<EventsSubscriptionClient> logger
)
{
_platformSettings = platformSettings.Value;
_generalSettings = generalSettings.Value;
httpClient.BaseAddress = new Uri(platformSettings.Value.ApiEventsEndpoint);
httpClient.DefaultRequestHeaders.Add(General.SubscriptionKeyHeaderName, platformSettings.Value.SubscriptionKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private async Task AddAuthHeaders(HttpRequestMessage request)
request.Headers.Add("Authorization", "Bearer " + _userTokenProvider.GetUserToken());
}

private async Task<Person?> ReadResponse(HttpResponseMessage response, CancellationToken ct)
private static async Task<Person?> ReadResponse(HttpResponseMessage response, CancellationToken ct)
{
if (response.StatusCode == HttpStatusCode.OK)
{
Expand Down
11 changes: 1 addition & 10 deletions src/Altinn.App.Core/Internal/Language/ApplicationLanguage.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Text.Json;
using Altinn.App.Core.Configuration;
using Altinn.App.Core.Features;
using Altinn.App.Core.Implementation;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace Altinn.App.Core.Internal.Language;
Expand All @@ -16,23 +14,16 @@ public class ApplicationLanguage : IApplicationLanguage
new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };

private readonly AppSettings _settings;
private readonly ILogger _logger;
private readonly Telemetry? _telemetry;

/// <summary>
/// Initializes a new instance of the <see cref="ApplicationLanguage"/> class.
/// </summary>
/// <param name="settings">The app repository settings.</param>
/// <param name="logger">A logger from the built in logger factory.</param>
/// <param name="telemetry">Telemetry for traces and metrics.</param>
public ApplicationLanguage(
IOptions<AppSettings> settings,
ILogger<AppResourcesSI> logger,
Telemetry? telemetry = null
)
public ApplicationLanguage(IOptions<AppSettings> settings, Telemetry? telemetry = null)
{
_settings = settings.Value;
_logger = logger;
_telemetry = telemetry;
}

Expand Down
1 change: 0 additions & 1 deletion src/Altinn.App.Core/Internal/Patch/IPatchService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Text.Json.Nodes;
using Altinn.App.Core.Models.Result;
using Altinn.Platform.Storage.Interface.Models;
using Json.Patch;
Expand Down
15 changes: 8 additions & 7 deletions src/Altinn.App.Core/Models/Layout/PageComponentConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void SetAsyncLocalPageName(string pageName)
/// <summary>
/// Similar to read, but not nullable, and no pageName hack.
/// </summary>
public PageComponent ReadNotNull(ref Utf8JsonReader reader, string pageName, JsonSerializerOptions options)
public static PageComponent ReadNotNull(ref Utf8JsonReader reader, string pageName, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.StartObject)
{
Expand Down Expand Up @@ -87,7 +87,7 @@ public PageComponent ReadNotNull(ref Utf8JsonReader reader, string pageName, Jso
return page;
}

private PageComponent ReadData(ref Utf8JsonReader reader, string pageName, JsonSerializerOptions options)
private static PageComponent ReadData(ref Utf8JsonReader reader, string pageName, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.StartObject)
{
Expand Down Expand Up @@ -156,10 +156,11 @@ private PageComponent ReadData(ref Utf8JsonReader reader, string pageName, JsonS
return new PageComponent(pageName, layout, componentLookup, hidden, required, readOnly, additionalProperties);
}

private (List<BaseComponent>, Dictionary<string, BaseComponent>, Dictionary<string, GroupComponent>) ReadLayout(
ref Utf8JsonReader reader,
JsonSerializerOptions options
)
private static (
List<BaseComponent>,
Dictionary<string, BaseComponent>,
Dictionary<string, GroupComponent>
) ReadLayout(ref Utf8JsonReader reader, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.StartArray)
{
Expand Down Expand Up @@ -248,7 +249,7 @@ Dictionary<string, GroupComponent> childToGroupMapping
}
}

private BaseComponent ReadComponent(ref Utf8JsonReader reader, JsonSerializerOptions options)
private static BaseComponent ReadComponent(ref Utf8JsonReader reader, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.StartObject)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public async Task PostNewInstanceWithContent_EnsureDataIsPresent()
readDataElementResponseParsed.Melding!.Name.Should().Be(testName);
}

private async Task<Instance> CreateInstanceSimplified(
private static async Task<Instance> CreateInstanceSimplified(
string org,
string app,
int instanceOwnerPartyId,
Expand Down
2 changes: 1 addition & 1 deletion test/Altinn.App.Api.Tests/Helpers/StartupHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void IncludeXmlComments_calls_delegate_function_with_expected_values()
public void IncludeXmlComments_discards_exceptions()
{
var testDouble = new SwaggerIncludeXmlCommentsTestDouble();
StartupHelper.IncludeXmlComments(testDouble.IncludeXmlCommentsFailingTestDouble);
StartupHelper.IncludeXmlComments(SwaggerIncludeXmlCommentsTestDouble.IncludeXmlCommentsFailingTestDouble);
testDouble.GetStrings().Should().HaveCount(0);
testDouble.GetBools().Should().HaveCount(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public async Task OpenTelemetry_MetricReaderOptions_Override_Is_Possible_Through
Assert.Equal(timeoutToUse, options.ExportTimeoutMilliseconds);
}

private Sampler GetSampler(TracerProvider provider)
private static Sampler GetSampler(TracerProvider provider)
{
var property =
provider.GetType().GetProperty("Sampler", BindingFlags.Instance | BindingFlags.NonPublic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void IncludeXmlCommentsTestDouble(string s, bool b)
_bools.Add(b);
}

public void IncludeXmlCommentsFailingTestDouble(string s, bool b)
public static void IncludeXmlCommentsFailingTestDouble(string s, bool b)
{
throw new Exception("xUnit expected exception");
}
Expand Down
4 changes: 2 additions & 2 deletions test/Altinn.App.Common.Tests/TelemetrySink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ public sealed record TelemetrySink : IDisposable

public TelemetrySnapshot GetSnapshot() => new(CapturedActivities, CapturedMetrics);

public TelemetrySnapshot GetSnapshot(Activity activity) =>
public static TelemetrySnapshot GetSnapshot(Activity activity) =>
new([activity], new Dictionary<string, IReadOnlyList<MetricMeasurement>>());

public TelemetrySnapshot GetSnapshot(IEnumerable<Activity> activities) =>
public static TelemetrySnapshot GetSnapshot(IEnumerable<Activity> activities) =>
new(activities, new Dictionary<string, IReadOnlyList<MetricMeasurement>>());

public async Task Snapshot(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ private static (SigningUserAction SigningUserAction, Mock<ISignClient> SignClien
);
}

private bool AssertSigningContextAsExpected(SignatureContext s1, SignatureContext s2)
private static bool AssertSigningContextAsExpected(SignatureContext s1, SignatureContext s2)
{
s1.Should().BeEquivalentTo(s2);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Altinn.App.Core.Tests.Features.Action;

public class UniqueSignatureAuthorizerTests : IDisposable
public sealed class UniqueSignatureAuthorizerTests : IDisposable
{
private readonly Mock<IProcessReader> _processReaderMock;
private readonly Mock<IInstanceClient> _instanceClientMock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Altinn.App.Core.Tests.Features.Validators.Default;

public class DataAnnotationValidatorTests : IClassFixture<DataAnnotationsTestFixture>
public sealed class DataAnnotationValidatorTests : IClassFixture<DataAnnotationsTestFixture>
{
private readonly DataAnnotationValidator _validator;

Expand Down Expand Up @@ -168,7 +168,7 @@ public async Task ValidateFormData_RequiredProperty()
///
/// A full WebApplicationFactory seemed a little overkill, so we just use a WebApplicationBuilder.
/// </summary>
public class DataAnnotationsTestFixture : IAsyncDisposable
public sealed class DataAnnotationsTestFixture : IAsyncDisposable
{
public const string DataType = "test";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ExpressionValidatorTests()
private static readonly JsonSerializerOptions _jsonSerializerOptions =
new() { ReadCommentHandling = JsonCommentHandling.Skip, PropertyNamingPolicy = JsonNamingPolicy.CamelCase, };

public ExpressionValidationTestModel LoadData(string fileName, string folder)
public static ExpressionValidationTestModel LoadData(string fileName, string folder)
{
var data = File.ReadAllText(Path.Join(folder, fileName));
return JsonSerializer.Deserialize<ExpressionValidationTestModel>(data, _jsonSerializerOptions)!;
Expand Down
Loading
Loading