Skip to content

Commit

Permalink
Enhance solution formatting and cleanup post Rider 2023.2.3 upgrade (#…
Browse files Browse the repository at this point in the history
…214)

### Summary & Motivation

Perform a cleanup across the entire solution following the upgrade to
Rider 2023.2.3. Move JetBrains formatting rules from `.editorconfig` to
a `.DotSettings` file. This change enforces JetBrains formatting
out-of-the-box and offers more granular control.

Add a `.NET only` cleanup profile to `.DotSettings` to prevent ReSharper
and Rider from formatting frontend files. To maintain consistent
formatting in frontend files, "Format on Save" should be manually
configured to use Prettier. Additionally, file types such as `.html`,
`.css`, and `.json` need to be added to Prettier's configuration for
comprehensive coverage.

Furthermore, .NET tools, including the JetBrains inspectcode and
cleanupcode formatter, have been added to `dotnet-tools.json`. This
inclusion streamlines tool management and ensures consistency across
development environments. The GitHub workflow has been correspondingly
updated to reflect these tooling changes, enhancing the efficiency and
reliability of our continuous integration process.

Build will now fail if there are any formatting or code inspection
warnings.

### Checklist

- [x] I have added a Label to the pull-request
- [x] I have added tests, and done manual regression tests
- [x] I have updated the documentation, if necessary
  • Loading branch information
tjementum authored Nov 19, 2023
2 parents 3f4799d + 5cdbe04 commit 7a64a10
Show file tree
Hide file tree
Showing 28 changed files with 194 additions and 3,516 deletions.
38 changes: 24 additions & 14 deletions .github/workflows/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,21 @@ jobs:
working-directory: application/account-management/WebApp
run: bun install --frozen-lockfile

- name: Restore .NET tools
working-directory: application
run: dotnet tool restore

- name: Install dotCover
run: dotnet tool install --global JetBrains.dotCover.GlobalTool

- name: Setup-java
uses: actions/setup-java@v3
with:
distribution: "microsoft"
java-version: "17"

- name: Install SonarScanner
run: dotnet tool install --global dotnet-sonarscanner

- name: Run Test with dotCover and SonarScanner reporting
working-directory: application
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
dotnet sonarscanner begin /k:"${{ vars.SONAR_PROJECT_KEY }}" /o:"${{ vars.SONAR_ORGANIZATION }}" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.dotcover.reportsPaths="application/coverage/dotCover.html"
dotnet dotcover test application/PlatformPlatform.sln --dcOutput="application/coverage/dotCover.html" --dcReportType=HTML
dotnet tool restore &&
dotnet sonarscanner begin /k:"${{ vars.SONAR_PROJECT_KEY }}" /o:"${{ vars.SONAR_ORGANIZATION }}" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.dotcover.reportsPaths="coverage/dotCover.html" &&
dotnet dotcover test PlatformPlatform.sln --dcOutput="coverage/dotCover.html" --dcReportType=HTML &&
dotnet sonarscanner end /d:sonar.login="${SONAR_TOKEN}"
jetbrains-code-inspection:
Expand All @@ -128,8 +120,26 @@ jobs:
- name: Run code inspections
working-directory: application
run: |
dotnet tool restore
dotnet jb inspectcode PlatformPlatform.sln --build --output=result.xml --severity=WARNING
dotnet tool restore &&
dotnet jb inspectcode PlatformPlatform.sln --build --output=result.xml --severity=SUGGESTION --exclude="**/*.csproj" # Exclude .csproj. See https://youtrack.jetbrains.com/issue/RSRP-490866
# Check if there are any issues. <Issues /> indicates no issues found.
if ! grep -q '<Issues />' result.xml; then
cat result.xml
echo "Code inspection issues found."
exit 1
fi
- name: Check for code formatting issues
working-directory: application
run: |
dotnet jb cleanupcode PlatformPlatform.sln --profile=".NET only"
# Check for any changes made by the code formatter
git diff --exit-code || {
echo "Formatting issues detected. Please run 'dotnet jb cleanupcode PlatformPlatform.sln --profile=\".NET only\"' locally and commit the formatted code."
exit 1
}
account-management-publish:
name: Account Management Publish
Expand Down
3,422 changes: 0 additions & 3,422 deletions application/.editorconfig

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions application/PlatformPlatform.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=_002ENET_0020only/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name=".NET only"&gt;&lt;CppCodeStyleCleanupDescriptor /&gt;&lt;CSReorderTypeMembers&gt;True&lt;/CSReorderTypeMembers&gt;&lt;CSCodeStyleAttributes ArrangeVarStyle="True" ArrangeTypeAccessModifier="True" ArrangeTypeMemberAccessModifier="True" SortModifiers="True" ArrangeArgumentsStyle="True" RemoveRedundantParentheses="True" AddMissingParentheses="True" ArrangeBraces="True" ArrangeAttributes="True" ArrangeCodeBodyStyle="True" ArrangeTrailingCommas="True" ArrangeObjectCreation="True" ArrangeDefaultValue="True" ArrangeNamespaces="True" ArrangeNullCheckingPattern="True" /&gt;&lt;RemoveCodeRedundancies&gt;True&lt;/RemoveCodeRedundancies&gt;&lt;CSUseAutoProperty&gt;True&lt;/CSUseAutoProperty&gt;&lt;CSMakeFieldReadonly&gt;True&lt;/CSMakeFieldReadonly&gt;&lt;CSMakeAutoPropertyGetOnly&gt;True&lt;/CSMakeAutoPropertyGetOnly&gt;&lt;CSArrangeQualifiers&gt;True&lt;/CSArrangeQualifiers&gt;&lt;CSFixBuiltinTypeReferences&gt;True&lt;/CSFixBuiltinTypeReferences&gt;&lt;CSOptimizeUsings&gt;&lt;OptimizeUsings&gt;True&lt;/OptimizeUsings&gt;&lt;/CSOptimizeUsings&gt;&lt;CSShortenReferences&gt;True&lt;/CSShortenReferences&gt;&lt;CSReformatCode&gt;True&lt;/CSReformatCode&gt;&lt;CSharpFormatDocComments&gt;True&lt;/CSharpFormatDocComments&gt;&lt;IDEA_SETTINGS&gt;&amp;lt;profile version="1.0"&amp;gt;
&amp;lt;option name="profileName" value=".NET only" /&amp;gt;
&amp;lt;inspection_tool class="ES6ShorthandObjectProperty" enabled="false" level="WARNING" enabled_by_default="false" /&amp;gt;
&amp;lt;inspection_tool class="JSArrowFunctionBracesCanBeRemoved" enabled="false" level="WARNING" enabled_by_default="false" /&amp;gt;
&amp;lt;inspection_tool class="JSPrimitiveTypeWrapperUsage" enabled="false" level="WARNING" enabled_by_default="false" /&amp;gt;
&amp;lt;inspection_tool class="JSRemoveUnnecessaryParentheses" enabled="false" level="WARNING" enabled_by_default="false" /&amp;gt;
&amp;lt;inspection_tool class="JSUnnecessarySemicolon" enabled="false" level="WARNING" enabled_by_default="false" /&amp;gt;
&amp;lt;inspection_tool class="TypeScriptExplicitMemberType" enabled="false" level="WARNING" enabled_by_default="false" /&amp;gt;
&amp;lt;inspection_tool class="UnnecessaryContinueJS" enabled="false" level="WARNING" enabled_by_default="false" /&amp;gt;
&amp;lt;inspection_tool class="UnnecessaryLabelJS" enabled="false" level="WARNING" enabled_by_default="false" /&amp;gt;
&amp;lt;inspection_tool class="UnnecessaryLabelOnBreakStatementJS" enabled="false" level="WARNING" enabled_by_default="false" /&amp;gt;
&amp;lt;inspection_tool class="UnnecessaryLabelOnContinueStatementJS" enabled="false" level="WARNING" enabled_by_default="false" /&amp;gt;
&amp;lt;inspection_tool class="UnnecessaryReturnJS" enabled="false" level="WARNING" enabled_by_default="false" /&amp;gt;
&amp;lt;inspection_tool class="WrongPropertyKeyValueDelimiter" enabled="false" level="WEAK WARNING" enabled_by_default="false" /&amp;gt;
&amp;lt;/profile&amp;gt;&lt;/IDEA_SETTINGS&gt;&lt;RIDER_SETTINGS&gt;&amp;lt;profile&amp;gt;
&amp;lt;Language id="CSS"&amp;gt;
&amp;lt;Reformat&amp;gt;false&amp;lt;/Reformat&amp;gt;
&amp;lt;Rearrange&amp;gt;false&amp;lt;/Rearrange&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="EditorConfig"&amp;gt;
&amp;lt;Reformat&amp;gt;false&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="HTML"&amp;gt;
&amp;lt;Reformat&amp;gt;false&amp;lt;/Reformat&amp;gt;
&amp;lt;OptimizeImports&amp;gt;false&amp;lt;/OptimizeImports&amp;gt;
&amp;lt;Rearrange&amp;gt;false&amp;lt;/Rearrange&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="HTTP Request"&amp;gt;
&amp;lt;Reformat&amp;gt;false&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="Handlebars"&amp;gt;
&amp;lt;Reformat&amp;gt;false&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="Ini"&amp;gt;
&amp;lt;Reformat&amp;gt;false&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="JSON"&amp;gt;
&amp;lt;Reformat&amp;gt;false&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="Jade"&amp;gt;
&amp;lt;Reformat&amp;gt;false&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="JavaScript"&amp;gt;
&amp;lt;Reformat&amp;gt;false&amp;lt;/Reformat&amp;gt;
&amp;lt;OptimizeImports&amp;gt;false&amp;lt;/OptimizeImports&amp;gt;
&amp;lt;Rearrange&amp;gt;false&amp;lt;/Rearrange&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="Markdown"&amp;gt;
&amp;lt;Reformat&amp;gt;false&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="Properties"&amp;gt;
&amp;lt;Reformat&amp;gt;false&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="RELAX-NG"&amp;gt;
&amp;lt;Reformat&amp;gt;false&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="SQL"&amp;gt;
&amp;lt;Reformat&amp;gt;false&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="VueExpr"&amp;gt;
&amp;lt;Reformat&amp;gt;false&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="XML"&amp;gt;
&amp;lt;Reformat&amp;gt;false&amp;lt;/Reformat&amp;gt;
&amp;lt;OptimizeImports&amp;gt;false&amp;lt;/OptimizeImports&amp;gt;
&amp;lt;Rearrange&amp;gt;false&amp;lt;/Rearrange&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;Language id="yaml"&amp;gt;
&amp;lt;Reformat&amp;gt;false&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;/profile&amp;gt;&lt;/RIDER_SETTINGS&gt;&lt;XAMLCollapseEmptyTags&gt;False&lt;/XAMLCollapseEmptyTags&gt;&lt;/Profile&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_FOR/@EntryValue">Required</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_FOREACH/@EntryValue">Required</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_IFELSE/@EntryValue">RequiredForMultilineStatement</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_WHILE/@EntryValue">Required</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/MODIFIERS_ORDER/@EntryValue">public protected required private file new internal static override abstract sealed virtual extern unsafe volatile async readonly</s:String>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/BLANK_LINES_AROUND_SINGLE_LINE_AUTO_PROPERTY/@EntryValue">1</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/BLANK_LINES_AROUND_SINGLE_LINE_INVOCABLE/@EntryValue">1</s:Int64>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ACCESSORHOLDER_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
</wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void MapTenantEndpoints(this IEndpointRouteBuilder routes)
=> (await mediator.Send(command)).AddResourceUri(RoutesPrefix));

group.MapPut("/{id}", async Task<ApiResult> (TenantId id, UpdateTenantCommand command, ISender mediator)
=> await mediator.Send(command with {Id = id}));
=> await mediator.Send(command with { Id = id }));

group.MapDelete("/{id}", async Task<ApiResult> (TenantId id, ISender mediator)
=> await mediator.Send(new DeleteTenantCommand(id)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override string ToString()
[UsedImplicitly]
public static bool TryParse(string? value, out TenantId? result)
{
if (value is {Length: >= 3 and <= 30} && value.All(c => char.IsLower(c) || char.IsDigit(c)))
if (value is { Length: >= 3 and <= 30 } && value.All(c => char.IsLower(c) || char.IsDigit(c)))
{
result = new TenantId(value);
return true;
Expand Down
8 changes: 4 additions & 4 deletions application/account-management/Tests/Api/BaseApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ protected async Task EnsureErrorStatusCode(HttpResponseMessage response, HttpSta
var problemDetails = await DeserializeProblemDetails(response);

problemDetails.Should().NotBeNull();
problemDetails!.Status.Should().Be((int) statusCode);
problemDetails.Type.Should().Be($"https://httpstatuses.com/{(int) statusCode}");
problemDetails!.Status.Should().Be((int)statusCode);
problemDetails.Type.Should().Be($"https://httpstatuses.com/{(int)statusCode}");
problemDetails.Title.Should().Be(SplitCamelCaseTitle(statusCode.ToString()));

if (expectedDetail is not null)
Expand All @@ -102,8 +102,8 @@ protected async Task EnsureErrorStatusCode(HttpResponseMessage response, HttpSta

if (expectedErrors is not null)
{
var actualErrorsJson = (JsonElement) problemDetails.Extensions["Errors"]!;
var options = new JsonSerializerOptions {PropertyNamingPolicy = JsonNamingPolicy.CamelCase};
var actualErrorsJson = (JsonElement)problemDetails.Extensions["Errors"]!;
var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
var actualErrors = JsonSerializer.Deserialize<ErrorDetail[]>(actualErrorsJson.GetRawText(), options);

actualErrors.Should().BeEquivalentTo(expectedErrors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public static long ExecuteScalar(this SqliteConnection connection, string sql, p
}
}

return (long) command.ExecuteScalar()!;
return (long)command.ExecuteScalar()!;
}

public static bool RowExists(this SqliteConnection connection, string tableName, string id)
{
return connection.ExecuteScalar($"SELECT COUNT(*) FROM {tableName} WHERE Id = @id", new {id}) == 1;
return connection.ExecuteScalar($"SELECT COUNT(*) FROM {tableName} WHERE Id = @id", new { id }) == 1;
}
}
File renamed without changes.
1 change: 1 addition & 0 deletions application/account-management/WebApp/src/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
* {
@apply border-border;
}

body {
@apply bg-background text-foreground;
}
Expand Down
18 changes: 11 additions & 7 deletions application/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
"version": 1,
"isRoot": true,
"tools": {
"dotnet-sonarscanner": {
"version": "5.14.0",
"commands": ["dotnet-sonarscanner"]
},
"jetbrains.dotcover.globaltool": {
"version": "2023.2.3",
"commands": ["dotnet-dotcover"]
},
"jetbrains.resharper.globaltools": {
"version": "2023.2.3",
"commands": [
"jb"
]
"commands": ["jb"]
},
"swashbuckle.aspnetcore.cli": {
"version": "6.5.0",
"commands": [
"swagger"
]
"commands": ["swagger"]
}
}
}
}
2 changes: 1 addition & 1 deletion application/shared-kernel/ApiCore/ApiCoreConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static IServiceCollection AddApiCoreServices(this IServiceCollection serv

services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo {Title = "PlatformPlatform API", Version = "v1"});
c.SwaggerDoc("v1", new OpenApiInfo { Title = "PlatformPlatform API", Version = "v1" });

// This is needed because commands are nested so CreateTenant.Command becomes CreateTenant+Command
c.CustomSchemaIds(type => type.FullName?.Split(".").Last().Replace("+", ""));
Expand Down
6 changes: 3 additions & 3 deletions application/shared-kernel/ApiCore/ApiResults/ApiResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected virtual IResult ConvertResult(string? routePrefix = null)

protected IResult GetProblemDetailsAsJson()
{
return Results.Json(CreateProblemDetails(), statusCode: (int) _result.StatusCode,
return Results.Json(CreateProblemDetails(), statusCode: (int)_result.StatusCode,
contentType: "application/problem+json");
}

Expand All @@ -44,9 +44,9 @@ private ProblemDetails CreateProblemDetails()
var statusCode = _result.StatusCode;
var problemDetails = new ProblemDetails
{
Type = $"https://httpstatuses.com/{(int) _result.StatusCode}",
Type = $"https://httpstatuses.com/{(int)_result.StatusCode}",
Title = SplitCamelCaseTitle(statusCode.ToString()),
Status = (int) _result.StatusCode
Status = (int)_result.StatusCode
};

if (_result.ErrorMessage is not null) problemDetails.Detail = _result.ErrorMessage.Message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
_logger.LogError(ex, "An error occurred while processing the request");

context.Response.StatusCode = (int) HttpStatusCode.InternalServerError;
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
context.Response.ContentType = "application/problem+json";

var problemDetails = new ProblemDetails
{
Type = $"https://httpstatuses.com/{(int) HttpStatusCode.InternalServerError}",
Type = $"https://httpstatuses.com/{(int)HttpStatusCode.InternalServerError}",
Title = "Internal Server Error",
Status = (int) HttpStatusCode.InternalServerError,
Status = (int)HttpStatusCode.InternalServerError,
Detail = "An error occurred while processing the request."
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next)
}
catch (BadHttpRequestException ex)
{
context.Response.StatusCode = (int) HttpStatusCode.BadRequest;
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
context.Response.ContentType = "application/problem+json";

var problemDetails = new ProblemDetails
{
Type = $"https://httpstatuses.com/{(int) HttpStatusCode.BadRequest}",
Type = $"https://httpstatuses.com/{(int)HttpStatusCode.BadRequest}",
Title = "Bad Request",
Status = (int) HttpStatusCode.BadRequest,
Status = (int)HttpStatusCode.BadRequest,
Detail = ex.Message
};

Expand Down
Loading

0 comments on commit 7a64a10

Please sign in to comment.