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

Code style errors can break building of user project #195

Open
atifaziz opened this issue Jun 7, 2024 · 0 comments
Open

Code style errors can break building of user project #195

atifaziz opened this issue Jun 7, 2024 · 0 comments
Assignees

Comments

@atifaziz
Copy link
Collaborator

atifaziz commented Jun 7, 2024

If a user project enforces code style during build via EnforceCodeStyleInBuild and warnings are treated as errors, then the following issues get flagged and can break the build:

  • IDE0010: Add missing cases to switch statement
  • IDE0055: Fix formatting
  • IDE0058: Remove unused expression value
  • IDE0065: using directive placement
  • IDE0240: Nullable directive is redundant

Steps to Reproduce

These instruction assume that the .NET SDK 8.0.300 is the latest installed.

Ensure the template is installed:

dotnet new install docopt.net.templates::0.1.0

Create a new project using the template:

mkdir demo
cd demo
dotnet new docopt-console -o . -n Demo

Build the project:

dotnet build

It should succeed without errors. Next, create an .editorconfig file with the following content in the same directory:

root = true

[*.cs]
dotnet_analyzer_diagnostic.category-Style.severity = warning

Update Demo.csproj by adding <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild> to the first property group section so that the file's content read as follows:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild> <!-- ADDED -->
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="docopt.net" Version="0.8.0" />
    <PackageReference Include="ThisAssembly.AssemblyInfo" Version="1.0.9" />
  </ItemGroup>

</Project>

Re-build the project:

dotnet build

While the build will succeed, it will issue over 300 warnings! If <TreatWarningsAsErrors>true</TreatWarningsAsErrors> is also added to the project file then the project will fail to build.

@atifaziz atifaziz self-assigned this Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant