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

Enforce IDE0005 during build by enabling GenerateDocumentationFile #5854

Closed
wants to merge 18 commits into from

Conversation

jgonz120
Copy link
Contributor

@jgonz120 jgonz120 commented Jun 14, 2024

Bug

Fixes: https://github.com/NuGet/Client.Engineering/issues/2845

Regression? Last working version:

Description

Updated two projects to include style rules enforcement during build, fixing the build errors for those two projects. Currently certain rules are not enforced unless XML documents are generated, dotnet/roslyn#41640.

PR Checklist

  • PR has a meaningful title

  • PR has a linked issue.

  • Described changes

  • Tests

    • Automated tests added
    • OR
    • Test exception
    • OR
    • N/A
  • Documentation

    • Documentation PR or issue filled
    • OR
    • N/A

@jgonz120 jgonz120 requested a review from a team as a code owner June 14, 2024 18:03
Copy link
Member

@zivkan zivkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR checklist is not filled out, and personally I find the PR title misleading, as it's just enabling XMLDoc generation for two projects, but it's not enabling style rules more broadly (style rules other than XMLDoc comments to the two projects, and it's not clear to me why just these two projects, rather than most src/NuGet.Core/* projects)

build/common.targets Outdated Show resolved Hide resolved
src/NuGet.Core/NuGet.Versioning/NuGet.Versioning.csproj Outdated Show resolved Hide resolved
src/NuGet.Core/NuGet.Versioning/VersionComparer.cs Outdated Show resolved Hide resolved
src/NuGet.Core/NuGet.Versioning/VersionRangeComparer.cs Outdated Show resolved Hide resolved
@jgonz120 jgonz120 changed the title Enforce style rules during build Enforce style rules during build by enabling GenerateDocumentationFile Jun 14, 2024
zivkan
zivkan previously approved these changes Jun 18, 2024
@jeffkl jeffkl added the Engineering Changes related to the build infrastructure of the repo and that do not change product code label Jun 20, 2024
@jgonz120 jgonz120 force-pushed the dev-jgonz120-BuildStyles branch from 249a398 to b3f9a76 Compare June 20, 2024 21:30
@jgonz120 jgonz120 requested review from nkolev92 and zivkan June 21, 2024 18:09
@@ -7,6 +7,7 @@
<PackProject>true</PackProject>
<Shipping>true</Shipping>
<IncludeInVSIX>true</IncludeInVSIX>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linked issue isn't clearly defined, making it sound like the intention is to enforce all style rules, not just documentation files, and also across all projects, not just one or two. The PR description also doesn't explain either why only XMLDoc, or why only 1 or 2 projects.

Most of the src/NuGet.Core/* projects are nupkgs published to nuget.org. Do the other project already generate XMLDoc, and NuGet.Versioning was the only one that wasn't?

Should the linked issue be changed to explicitly mention it's only about XMLDoc, and not other style issues?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Andy that we should clarify the scope of the PR/issue.

Copy link
Contributor Author

@jgonz120 jgonz120 Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I updated the issue. I don't really have a reason why I picked these two projects, I just needed to start somewhere.

One thing though, a know that is set to true for projects with set to true

<PropertyGroup Condition=" '$(PackProject)' == 'true' ">
<GenerateDocumentationFile Condition=" '$(GenerateDocumentationFile)' == '' ">true</GenerateDocumentationFile>
<DocumentationFile Condition=" '$(DocumentationFile)' == '' AND '$(GenerateDocumentationFile)' == 'true' AND '$(IsNetCoreProject)' != 'true' ">$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

Despite that I still don't get build errors for using statements until I specify GenerateDocumentationFile in the csproj.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you upload a binlog for the project in question?
You can do it in teams if that's easier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I moved this pack from the common.targets to common.project.props, and that worked. Is there a better location for it? Basically, we need to set it in a different location because it's getting set by another config.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind that the NuGet.Client repo has existed for years, before the .NET (Core) SDK was a thing, so while the SDK might now have defaults to make it work out of the box, perhaps in the past it didn't, or pre-SDK style projects might have worked differently as well.

I prefer a common config to apply to all projects, rather than opting individual projects into docs.

Copy link
Contributor Author

@jgonz120 jgonz120 Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the code to the common.project.props file doesn't work because when it goes to evaluate the condition is empty, so is set to false in Microsoft.NET.Sdk.BeforeCommon.targets.

Which condition is false?

This one, since PackProject is set later in the file it has no value when this is evaluated.

<PropertyGroup Condition=" '$(PackProject)' == 'true' ">

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer a common config to apply to all projects, rather than opting individual projects into docs.

Agreed but where that common config should live is difficult because of how <GenerateDocumentationFile> is set by Microsoft.NET.Sdk.BeforeCommon.targets.

Since we now know that without <GenerateDocumentationFile> we can't enforce all the style rules, is it worth just enabling it for everyone?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok to enable it for everyone.
We'd probably need to disable the IDE0005 in some projects where it fails,.
I can't think of anything else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zivkan to focus this conversation here because this has the most context. So, the latest change I pushed is what it looks like if we enable GenerateDocumentationFile for all projects all at once. I kept flipping back and forth between enabling it per project then once all projects have had it enabled moving it to the central build props project.

Currently we do not generate the documentation file for any of our projects because of the way the value is determined. So, I believe options for moving forward are:

  1. Enable GenerateDocumentationFile for all projects, using NoWarn to suppress build errors, then overtime remove the suppressions per project and fix the errors that come up. (current state)
  2. Enable GenerateDocumentationFile for all projects, using WarningsNotAsErrors to suppress build errors, then overtime remove the suppressions per project and fix the errors that come up.
  3. Enable GenerateDocumentationFile for individual projects, fixing the build errors as it is enabled. Once all projects have been updated to generate documentation files, we can move it to a central location.
  4. Force GenerateDocumentationFile to true for projects which have PackProject set to true. This will limit the scope of how many projects need to be fixed upfront, however it will still be a lot. We would need to selectively turn on GenerateDocumentationFile for all projects in order to get the style fixes like IDE0005 to show up as errors in the build.

@jgonz120 jgonz120 changed the title Enforce style rules during build by enabling GenerateDocumentationFile Enforce IDE0005 during build by enabling GenerateDocumentationFile Jul 1, 2024
@jgonz120 jgonz120 closed this Jul 2, 2024
@jgonz120 jgonz120 reopened this Jul 2, 2024
@jgonz120 jgonz120 marked this pull request as draft July 2, 2024 22:13
@dotnet-policy-service dotnet-policy-service bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Jul 9, 2024
@jgonz120 jgonz120 reopened this Jul 22, 2024
@dotnet-policy-service dotnet-policy-service bot removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Jul 22, 2024
@jgonz120 jgonz120 marked this pull request as ready for review July 22, 2024 22:37
@jgonz120 jgonz120 requested review from nkolev92 and zivkan July 23, 2024 17:24
nkolev92
nkolev92 previously approved these changes Jul 23, 2024
build/common.project.props Outdated Show resolved Hide resolved
@@ -24,7 +24,8 @@
<UsePublicApiAnalyzer>false</UsePublicApiAnalyzer>
<GetSigningInputsDependsOn>GetSigningInputsCustom</GetSigningInputsDependsOn>
<GetSymbolsToIndexDependsOn>GetSymbolsToIndexCustom</GetSymbolsToIndexDependsOn>
</PropertyGroup>
<NoWarn>$(NoWarn);CS1591;IDE0059;IDE1006;IDE0049</NoWarn>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CS1591 is related to XMLDoc, and therefore the title of this PR, but the other 3 codes are not.

We want to keep IDE1006, so disabling for the whole project feels wrong. I know we've got a bunch of noise on static properties, but we want to keep warnings (ideally enforce) public properties being Pascal Case, private members being _camelCase, methods being Pascal Case.

An in my opinion, IDE0059 seems like a good analyzer we should keep.

I think IDE0049 is very reasonable too, though we've got a lot of violations in our repo. But suppressing the code increases risk that future code changes will continue to add more violations, making it harder to enforce in the future.

@@ -44,4 +45,4 @@
ItemName="ReferencesCopiedInThisBuild" />
</Copy>
</Target>
</Project>
</Project>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep trailing new line. I thought our editorconfig actually specifies this

<!-- Write out .XML files for projects that will be packed. -->
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<DocumentationFile Condition=" '$(DocumentationFile)' == '' AND '$(GenerateDocumentationFile)' == 'true' AND '$(IsNetCoreProject)' != 'true' ">$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a great thing to enforce XMLDoc for the packages we publish to nuget.org. However,

  1. This issue is titled enforce IDE0005, but the docs say IDE0005 is about removing unnecessary usings, which has nothing to do with XMLDoc, and therefore the title "enforce IDE005 by enabling GenerateDocumentationFile" doesn't make sense
  2. I don't see anything in this PR that changes enforcement of IDE005. Our CI builds will continue to pass after this merges if people add new violations in future PRs.
  3. To be honest, I'm not a fan of adding NoWarn. I see NoWarn as tech debt, so now that I see the consequence of enabling GenerateDocumentationFile to all projects in the solution, I prefer the old implementation where it's only selectively enabled for projects that are packed.

@@ -9,6 +9,7 @@
<TargetFramework>$(NETFXTargetFramework)</TargetFramework>
<UseWpf>true</UseWpf>
<ExcludeFromSourceOnlyBuild>true</ExcludeFromSourceOnlyBuild>
<NoWarn>$(NoWarn);CS1572;CS1573;CS1591;IDE0005;IDE1006</NoWarn>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR title says it's enforcing IDE0005, but it's just being suppressed here, not enforced.

$(PkgMicrosoft_Test_Apex_VisualStudio)\lib\net46\Microsoft.Test.Apex.RemoteCodeInjector.dll;
$(PkgMicrosoft_Test_Apex_VisualStudio)\lib\net46\Microsoft.Test.Apex.RemoteCodeInjector.x64.dll"
Name="%(Filename)" />
<Reference Include="$(PkgMicrosoft_Test_Apex_VisualStudio)\lib\net46\*.dll" Exclude="$(PkgMicrosoft_Test_Apex_VisualStudio)\lib\net46\Microsoft.Test.Apex.PrismIntegration.dll;&#xD;&#xA; $(PkgMicrosoft_Test_Apex_VisualStudio)\lib\net46\Microsoft.Test.Apex.RemoteCodeInjector.dll;&#xD;&#xA; $(PkgMicrosoft_Test_Apex_VisualStudio)\lib\net46\Microsoft.Test.Apex.RemoteCodeInjector.x64.dll" Name="%(Filename)" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a bad change.

Copy link
Contributor

This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 7 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch.

@dotnet-policy-service dotnet-policy-service bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Engineering Changes related to the build infrastructure of the repo and that do not change product code Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants