Skip to content

Commit

Permalink
Add pipeline job to verify clean dotnet format (#455)
Browse files Browse the repository at this point in the history
* Try to make git checkout cs files with crlf endings

* Fix non async .Result in tests

* Add pipeline job for dotnet-format

* Actually run dotnet format
  • Loading branch information
ivarne authored Mar 1, 2024
1 parent 01e857c commit 7f562dd
Show file tree
Hide file tree
Showing 186 changed files with 653 additions and 618 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
###############################################################################
* text=auto

*.cs text eol=crlf

###############################################################################
# Set default behavior for command prompt diff.
#
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/dotnet-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Verify dotnet format

on:
pull_request:
branches: [ "main", "v8" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Verify dotnet format
run: dotnet format --verify-no-changes
2 changes: 1 addition & 1 deletion src/Altinn.App.Api/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Microsoft.Extensions.Options;

namespace Altinn.App.Api.Controllers
{
{
/// <summary>
/// To handle authentication related operations
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Altinn.App.Api/Controllers/DataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public async Task<ActionResult<DataPatchResponse>> PatchFormData(
{
await UpdateDataValuesOnInstance(instance, dataType.Id, res.Ok.NewDataModel);
await UpdatePresentationTextsOnInstance(instance, dataType.Id, res.Ok.NewDataModel);

return Ok(new DataPatchResponse
{
NewDataModel = res.Ok.NewDataModel,
Expand Down
2 changes: 1 addition & 1 deletion src/Altinn.App.Api/Controllers/DataListsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Altinn.App.Api.Controllers
/// Represents the DataLists API.
/// </summary>
[ApiController]
public class DataListsController: ControllerBase
public class DataListsController : ControllerBase
{
private readonly IDataListsService _dataListsService;

Expand Down
2 changes: 1 addition & 1 deletion src/Altinn.App.Api/Controllers/DataTagsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public async Task<ActionResult<TagsList>> Add(
}

DataElement? dataElement = instance.Data.FirstOrDefault(m => m.Id.Equals(dataGuid.ToString()));

if (dataElement == null)
{
return NotFound("Unable to find data element based on the given parameters.");
Expand Down
4 changes: 2 additions & 2 deletions src/Altinn.App.Api/Controllers/EventsReceiverController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class EventsReceiverController : ControllerBase
/// Initializes a new instance of the <see cref="EventsReceiverController"/> class.
/// </summary>
public EventsReceiverController(
IEventHandlerResolver eventHandlerResolver,
ILogger<EventsReceiverController> logger,
IEventHandlerResolver eventHandlerResolver,
ILogger<EventsReceiverController> logger,
IOptions<PlatformSettings> options,
IEventSecretCodeProvider secretCodeProvider)
{
Expand Down
12 changes: 6 additions & 6 deletions src/Altinn.App.Api/Controllers/InstancesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public InstancesController(
IEventsClient eventsClient,
IOptions<AppSettings> appSettings,
IPrefill prefillService,
IProfileClient profileClient,
IProcessEngine processEngine,
IProfileClient profileClient,
IProcessEngine processEngine,
IOrganizationClient orgClient)
{
_logger = logger;
Expand Down Expand Up @@ -274,7 +274,7 @@ public async Task<ActionResult<Instance>> Post(
Instance instance;
instanceTemplate.Process = null;
ProcessStateChange? change = null;

try
{
// start process and goto next task
Expand All @@ -289,7 +289,7 @@ public async Task<ActionResult<Instance>> Post(
{
return Conflict(result.ErrorMessage);
}

change = result.ProcessStateChange;

// create the instance
Expand Down Expand Up @@ -440,7 +440,7 @@ public async Task<ActionResult<Instance>> PostSimplified(
Dryrun = true,
Prefill = instansiationInstance.Prefill
};

processResult = await _processEngine.StartProcess(request);

Instance? source = null;
Expand Down Expand Up @@ -569,7 +569,7 @@ public async Task<ActionResult> CopyInstance(
{
return StatusCode((int)HttpStatusCode.Forbidden, validationResult);
}

ProcessStartRequest processStartRequest = new()
{
Instance = targetInstance,
Expand Down
4 changes: 2 additions & 2 deletions src/Altinn.App.Api/Controllers/PdfController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Altinn.App.Api.Controllers
public class PdfController : ControllerBase
{
private readonly IInstanceClient _instanceClient;
#pragma warning disable CS0618 // Type or member is obsolete
#pragma warning disable CS0618 // Type or member is obsolete
private readonly IPdfFormatter _pdfFormatter;
private readonly IAppResources _resources;
private readonly IAppModel _appModel;
Expand All @@ -40,7 +40,7 @@ public class PdfController : ControllerBase
/// <param name="pdfService">The PDF service</param>
public PdfController(
IInstanceClient instanceClient,
#pragma warning disable CS0618 // Type or member is obsolete
#pragma warning disable CS0618 // Type or member is obsolete
IPdfFormatter pdfFormatter,
IAppResources resources,
IAppModel appModel,
Expand Down
20 changes: 10 additions & 10 deletions src/Altinn.App.Api/Controllers/ProcessController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public async Task<ActionResult<AppProcessState>> StartProcess(
{
return Conflict(result.ErrorMessage);
}

AppProcessState appProcessState = await ConvertAndAuthorizeActions(instance, result.ProcessStateChange?.NewProcessState);
return Ok(appProcessState);
}
Expand Down Expand Up @@ -236,7 +236,7 @@ public async Task<ActionResult<AppProcessState>> NextElement(
{
processNext = await DeserializeFromStream<ProcessNext>(Request.Body);
}

Instance instance = await _instanceClient.GetInstance(app, org, instanceOwnerPartyId, instanceGuid);

if (instance?.Process == null)
Expand Down Expand Up @@ -264,7 +264,7 @@ public async Task<ActionResult<AppProcessState>> NextElement(
{
return Forbid();
}

_logger.LogDebug("User is authorized to perform action {Action}", checkedAction);

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
var request = new ProcessNextRequest()
{
Expand Down Expand Up @@ -439,7 +439,7 @@ public async Task<ActionResult> GetProcessHistory(
return ExceptionResponse(processException, $"Unable to find retrieve process history for instance {instanceOwnerPartyId}/{instanceGuid}. Exception: {processException}");
}
}

private async Task<AppProcessState> ConvertAndAuthorizeActions(Instance instance, ProcessState? processState)
{
AppProcessState appProcessState = new AppProcessState(processState);
Expand All @@ -458,15 +458,15 @@ private async Task<AppProcessState> ConvertAndAuthorizeActions(Instance instance
appProcessState.CurrentTask.UserActions = authDecisions;
}
}

var processTasks = new List<AppProcessTaskTypeInfo>();
foreach (var processElement in _processReader.GetAllFlowElements().OfType<ProcessTask>())
{
processTasks.Add(new AppProcessTaskTypeInfo
{
ElementId = processElement.Id,
AltinnTaskType = processElement.ExtensionElements?.TaskExtension?.TaskType
});
{
ElementId = processElement.Id,
AltinnTaskType = processElement.ExtensionElements?.TaskExtension?.TaskType
});
}

appProcessState.ProcessTasks = processTasks;
Expand Down Expand Up @@ -534,7 +534,7 @@ private ActionResult HandlePlatformHttpException(PlatformHttpException e, string

return ExceptionResponse(e, defaultMessage);
}

private static async Task<T?> DeserializeFromStream<T>(Stream stream)
{
using StreamReader reader = new StreamReader(stream);
Expand Down
2 changes: 1 addition & 1 deletion src/Altinn.App.Api/Controllers/ProfileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task<ActionResult> GetUser()
}
catch (Exception e)
{
return StatusCode(500, e.Message);
return StatusCode(500, e.Message);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Altinn.App.Api/Controllers/StatelessDataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private async Task ProcessAllDataRead(Instance virtualInstance, object appModel,
foreach (var dataProcessor in _dataProcessors)
{
_logger.LogInformation(
"ProcessDataRead for {modelType} using {dataProcesor}",
"ProcessDataRead for {modelType} using {dataProcesor}",
appModel.GetType().Name,
dataProcessor.GetType().Name);
await dataProcessor.ProcessDataRead(virtualInstance, null, appModel, language);
Expand Down
4 changes: 2 additions & 2 deletions src/Altinn.App.Api/Controllers/StatelessPagesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class StatelessPagesController : ControllerBase
/// <param name="resources">The app resource service</param>
/// <param name="pageOrder">The page order service</param>
public StatelessPagesController(
IAppModel appModel,
IAppResources resources,
IAppModel appModel,
IAppResources resources,
IPageOrder pageOrder)
{
_appModel = appModel;
Expand Down
8 changes: 4 additions & 4 deletions src/Altinn.App.Api/Controllers/ValidateController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ public async Task<IActionResult> ValidateInstance(
throw new ValidationException("Unable to validate instance without a started process.");
}

try
try
{
List<ValidationIssue> messages = await _validationService.ValidateInstanceAtTask(instance, taskId, language);
return Ok(messages);
}
catch (PlatformHttpException exception)
}
catch (PlatformHttpException exception)
{
if (exception.Response.StatusCode == System.Net.HttpStatusCode.Forbidden)
if (exception.Response.StatusCode == System.Net.HttpStatusCode.Forbidden)
{
return StatusCode(403);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static IApplicationBuilder UseAltinnAppCommonConfiguration(this IApplicat
app.UseDeveloperExceptionPage();
webApp.UseAltinnPrometheus(appId);
}

app.UseHttpMetrics();
app.UseMetricServer();
app.UseDefaultSecurityHeaders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static (bool Success, List<ValidationIssue> Errors) CompliesWithDataRestr
Severity = ValidationIssueSeverity.Error,
Description = $"{errorBaseMessage} The request must include a Content-Disposition header"
});

return (false, errors);
}

Expand Down Expand Up @@ -131,7 +131,7 @@ public static (bool Success, List<ValidationIssue> Errors) CompliesWithDataRestr
{
ContentDispositionHeaderValue contentDisposition = ContentDispositionHeaderValue.Parse(headerValues);
string? filename = contentDisposition.FileNameStar ?? contentDisposition.FileName;

// We actively remove quotes because we don't want them replaced with '_'.
// Quotes around filename in Content-Disposition is valid, but not as part of the filename.
filename = filename?.Trim('\"').AsFileName(false);
Expand Down
2 changes: 1 addition & 1 deletion src/Altinn.App.Api/Helpers/StartupHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class StartupHelper
/// Delegate for swagger funciton
/// </summary>
public delegate void SwaggerIncludeXmlComments(string filepath, bool a);

/// <summary>
/// Includes comments in swagger based on XML comment files
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public SecurityHeadersMiddleware(RequestDelegate next)
/// <returns></returns>
public Task Invoke(HttpContext context)
{
context.Response.Headers.Add("X-Frame-Options", "deny");
context.Response.Headers.Add("X-Content-Type-Options", "nosniff");
context.Response.Headers.Add("X-XSS-Protection", "0");
context.Response.Headers.Add("Referer-Policy", "no-referer");
context.Response.Headers.Append("X-Frame-Options", "deny");
context.Response.Headers.Append("X-Content-Type-Options", "nosniff");
context.Response.Headers.Append("X-XSS-Protection", "0");
context.Response.Headers.Append("Referer-Policy", "no-referer");

return _next(context);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Altinn.App.Api/Models/AppProcessState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Altinn.App.Api.Models;
/// Extended representation of a status object that holds the process state of an application instance.
/// The process is defined by the application's process specification BPMN file.
/// </summary>
public class AppProcessState: ProcessState
public class AppProcessState : ProcessState
{
/// <summary>
/// Actions that can be performed and if the user is allowed to perform them.
Expand Down
2 changes: 1 addition & 1 deletion src/Altinn.App.Api/Models/DataPatchRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class DataPatchRequest
/// </summary>
[JsonPropertyName("patch")]
public required JsonPatch Patch { get; init; }

/// <summary>
/// List of validators to ignore during the patch operation.
/// Issues from these validators will not be run during the save operation, but the validator will run on process/next
Expand Down
2 changes: 1 addition & 1 deletion src/Altinn.App.Api/Models/InstanceFileScanResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void AddFileScanResult(DataElementFileScanResult dataElementFileScanResul
_dataElements.Add(dataElementFileScanResult);

RecalculateAggregatedStatus();
}
}
}

private void RecalculateAggregatedStatus()
Expand Down
4 changes: 2 additions & 2 deletions src/Altinn.App.Api/Models/UserActionRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public class UserActionRequest
/// </summary>
[JsonPropertyName("action")]
public string? Action { get; set; }

/// <summary>
/// The id of the button that was clicked
/// </summary>
[JsonPropertyName("buttonId")]
public string? ButtonId { get; set; }

/// <summary>
/// Additional metadata for the action
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Altinn.App.Api/Models/UserActionResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public class UserActionResponse
/// </summary>
[JsonPropertyName("updatedValidationIssues")]
public Dictionary<string, Dictionary<string, List<ValidationIssue>>>? UpdatedValidationIssues { get; set; }

/// <summary>
/// Actions the client should perform after action has been performed backend
/// </summary>
[JsonPropertyName("clientActions")]
public List<ClientAction>? ClientActions { get; set; }

/// <summary>
/// Validation issues that occured when processing action
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public static class ServiceCollectionExtensions
/// <param name="services">The <see cref="IServiceCollection"/> being built.</param>
/// <param name="configuration">A reference to the current <see cref="IConfiguration"/> object.</param>
/// <typeparam name="TM">App specific implementation of <see cref="IEFormidlingMetadata"/></typeparam>
public static void AddEFormidlingServices<TM>(this IServiceCollection services, IConfiguration configuration) where TM: IEFormidlingMetadata
public static void AddEFormidlingServices<TM>(this IServiceCollection services, IConfiguration configuration) where TM : IEFormidlingMetadata
{
AddEFormidlingServices<TM, DefaultEFormidlingReceivers>(services, configuration);
}

/// <summary>
/// Add Eformidling services and app specific <see cref="IEFormidlingMetadata" /> and <see cref="IEFormidlingReceivers" /> implementation.
/// <see cref="DefaultEFormidlingReceivers" /> will not be registered.
Expand All @@ -32,7 +32,7 @@ public static void AddEFormidlingServices<TM>(this IServiceCollection services,
/// <param name="configuration">A reference to the current <see cref="IConfiguration"/> object.</param>
/// <typeparam name="TM">App specific implementation of <see cref="IEFormidlingMetadata"/></typeparam>
/// <typeparam name="TR">App specific implementation of <see cref="IEFormidlingReceivers"/></typeparam>
public static void AddEFormidlingServices<TM, TR>(this IServiceCollection services, IConfiguration configuration) where TM: IEFormidlingMetadata where TR: IEFormidlingReceivers
public static void AddEFormidlingServices<TM, TR>(this IServiceCollection services, IConfiguration configuration) where TM : IEFormidlingMetadata where TR : IEFormidlingReceivers
{
services.AddTransient(typeof(IEFormidlingReceivers), typeof(TR));
services.AddHttpClient<IEFormidlingClient, Common.EFormidlingClient.EFormidlingClient>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public DefaultEFormidlingReceivers(IAppMetadata appMetadata)
public async Task<List<Receiver>> GetEFormidlingReceivers(Instance instance)
{
await Task.CompletedTask;

Identifier identifier = new Identifier
{
// 0192 prefix for all Norwegian organisations.
Expand Down
Loading

0 comments on commit 7f562dd

Please sign in to comment.