Skip to content

Commit

Permalink
fix: code analysis settings
Browse files Browse the repository at this point in the history
  • Loading branch information
nadirbad committed Jan 20, 2025
1 parent 5e56d24 commit b7080ff
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
3 changes: 1 addition & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
<AssemblyName>VerticalSliceArchitecture.$(MSBuildProjectName)</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace>

<AnalysisLevel>8-minimal</AnalysisLevel>
<AnalysisLevel>8-minimum</AnalysisLevel>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

Expand Down
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,23 @@ dotnet ef database update --project src/Application --startup-project src/Api

Developers should follow Microsoft's [C# Coding Conventions](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/inside-a-program/coding-conventions).

To enforce consistent coding styles and settings in the codebase, we use an EditorConfig file (**.editorconfig**) prepopulated with the default [.NET code style, formatting, and naming conventions](https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2019).
To enforce consistent coding styles and settings in the codebase, we use an EditorConfig file (**.editorconfig**) prepopulated with the default [.NET code style, formatting, and naming conventions](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/code-style-rule-options).

For [code analysis](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/overview?tabs=net-9)
we use the built in analyzers.

**IMPORTANT NOTES:**

- EditorConfig settings take precedence over global IDE text editor settings.
- New lines of code are formatted according to the EditorConfig settings
- The formatting of existing code is not changed unless you run one of the following commands (Visual Studio):
- Code Cleanup (**Ctrl+K, Ctrl+E**) which applies any white space setting, indent style, and other code style settings.
- Format Document (**Ctrl+K, Ctrl+D**)
- **The formatting of existing code is not changed unless you run**:
- `dotnet format` from the command line

For [code analysis](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/overview?tabs=net-8)
we use the built in analyzers.
There are a few arguments we can supply to the dotnet format command to control its usage. A useful one is the `--verify-no-changes argument`. This argument is useful when we want to understand when code breaks standards, but not automatically clean it up.

```shell
dotnet format --verify-no-changes
```

Both code formating and analysis can be performed from the cli by running:

Expand Down
2 changes: 2 additions & 0 deletions src/Api/ErrorController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc;

namespace VerticalSliceArchitecture.Api;

public class ErrorController : ControllerBase
{
[Route("/error-development")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Task Publish(DomainEvent domainEvent)
return _mediator.Publish(GetNotificationCorrespondingToDomainEvent(domainEvent));
}

private INotification GetNotificationCorrespondingToDomainEvent(DomainEvent domainEvent)
private static INotification GetNotificationCorrespondingToDomainEvent(DomainEvent domainEvent)
{
return (INotification)Activator.CreateInstance(
typeof(DomainEventNotification<>).MakeGenericType(domainEvent.GetType()), domainEvent)!;
Expand Down

0 comments on commit b7080ff

Please sign in to comment.