Skip to content

Commit

Permalink
Misc project cleanup - props, editorconfig, refactorings, docs (#661)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinothamar authored May 30, 2024
1 parent c36fc35 commit f1ed934
Show file tree
Hide file tree
Showing 482 changed files with 23,949 additions and 24,873 deletions.
97 changes: 60 additions & 37 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,73 +10,89 @@ indent_style = space
indent_size = 4
max_line_length = 120

# XML project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
indent_size = 2

# XML config files
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
indent_size = 2

[*.{cs,vb}]
dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = false

#### Naming styles ####
end_of_line = crlf

# Naming rules
#### Naming styles ####

dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
# Interfaces start with 'I'
dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case
dotnet_naming_rule.interface_should_be_begins_with_i.severity = warning
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
# Types should be PascalCase
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum, namespace, delegate
dotnet_naming_rule.types_should_be_pascal_case.severity = warning
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

# Symbol specifications

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case
# Non-private members should be PascalCase
dotnet_naming_symbols.non_private_members.applicable_kinds = property, event, field
dotnet_naming_symbols.non_private_members.applicable_accessibilities = public, internal, protected, protected_internal
dotnet_naming_rule.non_private_members_should_be_pascal_case.severity = warning
dotnet_naming_rule.non_private_members_should_be_pascal_case.symbols = non_private_members
dotnet_naming_rule.non_private_members_should_be_pascal_case.style = pascal_case

# All methods should be PascalCase
dotnet_naming_symbols.methods.applicable_kinds = method, local_function
dotnet_naming_rule.methods_should_be_pascal_case.severity = warning
dotnet_naming_rule.methods_should_be_pascal_case.symbols = methods
dotnet_naming_rule.methods_should_be_pascal_case.style = pascal_case

# Private member should be '_' prefixed and camelCase
dotnet_naming_symbols.private_members.applicable_kinds = property, event, field
dotnet_naming_symbols.private_members.applicable_accessibilities = private, private_protected
dotnet_naming_style.__prefixed_camel_case.required_prefix = _
dotnet_naming_style.__prefixed_camel_case.required_suffix =
dotnet_naming_style.__prefixed_camel_case.word_separator =
dotnet_naming_style.__prefixed_camel_case.capitalization = camel_case
dotnet_naming_rule.private_members_should_be___prefixed_camel_case.severity = warning
dotnet_naming_rule.private_members_should_be___prefixed_camel_case.symbols = private_members
dotnet_naming_rule.private_members_should_be___prefixed_camel_case.style = __prefixed_camel_case

# Const fields should be PascalCase
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = warning
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.required_modifiers = const


# General naming styles

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
indent_size = 4
max_line_length = 160
end_of_line = crlf
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion

csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent
csharp_style_namespace_declarations= file_scoped:suggestion
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_expression_bodied_methods = false:silent
Expand All @@ -89,6 +105,13 @@ csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_indent_labels = one_less_than_current
csharp_style_prefer_primary_constructors = false:suggestion
csharp_style_namespace_declarations = file_scoped:error

# Naming rule violation
dotnet_diagnostic.IDE1006.severity = error

# Unused usings
dotnet_diagnostic.IDE0005.severity = suggestion

# CA1848: Use the LoggerMessage delegates
dotnet_diagnostic.CA1848.severity = none
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ jobs:
dotnet build --configuration Release --no-restore -p:Deterministic=true -p:BuildNumber=${{ github.run_number }}
- name: Pack
run: |
dotnet pack AppLibDotnet.sln --configuration Release --no-restore --no-build -p:BuildNumber=${{ github.run_number }} -p:Deterministic=true
dotnet pack AppLibDotnet.sln --configuration Release --no-restore --no-build -p:Deterministic=true -p:BuildNumber=${{ github.run_number }}
- name: Versions
run: |
dotnet --version
- name: Publish
run: |
dotnet nuget push src/**/bin/Release/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
90 changes: 90 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# How to contribute

Developer documentation for Altinn.App .NET libraries.

Here are some important resources:

* [Team Apps Github board](https://github.com/orgs/Altinn/projects/39/views/2)
* [Altinn Studio docs](https://docs.altinn.studio/)

## Reporting Issues

Open [our Github issue tracker](https://github.com/Altinn/app-lib-dotnet/issues/new/choose)
and choose an appropriate issue template.

Feel free to query existing issues before creating a new one.

## Contributing Changes

* Fork and/or create branch
* Push changes
* Test your changes, see the testing changes below
* Create PR - fill in the required sections
* Try to provide reasoning/rationale for the changes if it hasn't already been discussed
* Attach appropriate tags according to the change (`feature`, `kind/feature-request`, `bugfix`, `kind/bug`, `kind/chore`)
* If you work on team Apps, attach the `Team Apps` project, add it to a sprint and input an estimate (if an issue isn't already added)
* Make sure coding style is consistent
* Csharpier for formatting (`editor.formatOnSave` is on by default, there should be an extension for your editor/IDE)
* EditorConfig is configured, you should use an editor or IDE that supports it (that should cover other conventions)
* We require 1 approval to merge changes
* Make sure Sonar / CodeQL and other static analysis issues are resolved
* We don't need 100% code coverage, effort and risk must be weighed
* Use squash merge
* Use a descriptive PR title, as it is used for release notes generation

### Versioning

We use semantic versioning. So we avoid breaking changes for anything that might break builds or change behavior.

### Telemetry

The Altinn app libraries are instrumented with `System.Diagnostics`, and telemetry is shipped via OpenTelemetry.
When developing new features and code, failure modes should be considered carefully, and telemetry should be added
such that we can observe that the code works correctly when running locally and in test and production environments.
See existing code for tips and clues.

Parts of the telemetry is considered public contract.
Consumers may build alerting and dashboards based on this telemetry, so if we change names and tags
that may break things downstream. Names and tags are in the `Telemetry` class.

### Testing

We have automated tests in the `test/` folder using mainly xUnit, FluentAssertions, Moq and Verify.
Some tests invoke classes directly (while mocking dependencies as needed),
while some construct adhoc DI containers or use ASP.NET Core `WebApplicationFactory<>`.
The following resources are currently snapshot tested (some with Verify)

* OpenAPI doc
* Telemetry output (activities/spans and metrics)

In addition to automated testing, we should do manual tests for any non-trivial change as well.

#### Manual testing

To manually test changes, simply make your app reference the libraries directly. See the diff below,
and make sure the relative directory paths work for your setup.

```csproj
<!-- <PackageReference Include="Altinn.App.Api" Version="8.2.*">
<CopyToOutputDirectory>lib\$(TargetFramework)\*.xml</CopyToOutputDirectory>
</PackageReference>
<PackageReference Include="Altinn.App.Core" Version="8.2.*" /> -->
<ProjectReference Include="../../../app-lib-dotnet/src/Altinn.App.Api/Altinn.App.Api.csproj">
<CopyToOutputDirectory>lib\$(TargetFramework)\*.xml</CopyToOutputDirectory>
</ProjectReference>
<ProjectReference Include="../../../app-lib-dotnet/src/Altinn.App.Core/Altinn.App.Core.csproj" />
```

Make sure [localtest](https://github.com/Altinn/app-localtest) is running
Run your app

```shell
dotnet run --project App/
```

To debug changes in the libraries, you can

* Add the `altinn-lib-donet/src` projects to your apps `App.sln` file
* Create a `code-workspace` file in the case of VSCode

Debug breakpoints should then work as normal
34 changes: 17 additions & 17 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<Project>
<PropertyGroup Condition="'$(DOTNET_TREATWARNINGSASERRORS)' == 'true' OR '$(CI)' == 'true'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(DOTNET_TREATWARNINGSASERRORS)' == 'true' OR '$(CI)' == 'true'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup>
<LangVersion>latest</LangVersion>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisMode>Minimum</AnalysisMode>
<Features>strict</Features>
<!-- <CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors> -->
</PropertyGroup>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisMode>Minimum</AnalysisMode>
<Features>strict</Features>
<!-- <CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors> -->
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CSharpier.MsBuild" Version="0.28.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
<ItemGroup>
<PackageReference Include="CSharpier.MsBuild" Version="0.28.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
27 changes: 27 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) 2017, Altinn
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of Altinn nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
# app-template-dotnet
Altinn application template using .NET 6
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/Altinn/app-lib-dotnet/dotnet-test.yml?branch=main)](https://github.com/Altinn/app-lib-dotnet/actions)
[![GitHub](https://img.shields.io/github/license/Altinn/app-lib-dotnet?style=flat-square)](https://github.com/Altinn/app-lib-dotnet/blob/main/LICENSE)<br/>

[![NuGet / Altinn.App.Core](https://img.shields.io/nuget/v/Altinn.App.Core?label=Altinn.App.Core)](https://www.nuget.org/packages/Altinn.App.Core)
[![NuGet / Altinn.App.Api](https://img.shields.io/nuget/v/Altinn.App.Api?label=Altinn.App.Api)](https://www.nuget.org/packages/Altinn.App.Api)

## Goal for template
# Altinn.App .NET libraries

The goal for this template is to give application owners using Altinn Studio a application template that covers common functional and technical needs.
Altinn.App .NET libraries for apps running on Altinn 3, part of the [Altinn Studio product](https://docs.altinn.studio/altinn-studio/about/).

- BPMN Process Support
- Api for app-frontend and end user system
These libraries support the runtime of Altinn apps by

* Exposing APIs used by service owners and the [frontend (app-frontend-react)](https://github.com/Altinn/app-frontend-react) of an Altinn app
* Exposing abstractions to interact with features of Altinn Studio and Altinn 3 Platform services

## Contributing

See [/CONTRIBUTING.md](/CONTRIBUTING.md).

## Architecture

This template is built using .NET

The below diagram shows the different layers.
The below diagram shows the different layers.


![Template](https://raw.githubusercontent.com/Altinn/app-template-dotnet/main/apptemplate.drawio.svg)
8 changes: 1 addition & 7 deletions src/Altinn.App.Api/Altinn.App.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@
<Description>
This class library holds all the API controllers used by a standard Altinn 3 App.
</Description>
<PackageReleaseNotes>https://github.com/Altinn/app-lib-dotnet/releases</PackageReleaseNotes>
<Authors>Altinn Platform Contributors</Authors>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/Altinn/app-lib-dotnet</RepositoryUrl>
<IsPackable>true</IsPackable>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<!-- SonarCloud requires a ProjectGuid to separate projects. -->
<ProjectGuid>{E8F29FE8-6B62-41F1-A08C-2A318DD08BB4}</ProjectGuid>
Expand All @@ -39,4 +33,4 @@
<InternalsVisibleTo Include="$(AssemblyName).Tests" />
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
</ItemGroup>
</Project>
</Project>
Loading

0 comments on commit f1ed934

Please sign in to comment.