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

Target files: enhance S1128 by enabling IDE0005 warnings in CLI build #1725

Open
cristian-ambrosini-sonarsource opened this issue Oct 23, 2023 · 0 comments

Comments

@cristian-ambrosini-sonarsource
Copy link
Contributor

cristian-ambrosini-sonarsource commented Oct 23, 2023

An enhancement for rule S1128 could involve intercepting CS8019 hidden diagnostics for unused 'usings'. The related issue on Roslyn's side can be found here, with the most effective workaround currently detailed in this comment.
We should add something like this to our target files:

    <Target Name="__TriggerUnnecessaryUsingsCheck" BeforeTargets="CoreCompile">
        <!-- Condition to let consuming projects enable documentation file generation themselves -->
        <ItemGroup Condition="'$(GenerateDocumentationFile)' != 'true'">
            <!-- Trigger compiler check for unnecessary usings -->
            <DocFileItem Include="$(IntermediateOutputPath)DummyDocForUnnecessaryUsings.xml" />
        </ItemGroup>
        <PropertyGroup Condition="'$(GenerateDocumentationFile)' != 'true'">
            <!-- we do not want the dummy file in the output folder -->
            <CopyDocumentationFileToOutputDirectory>false</CopyDocumentationFileToOutputDirectory>
            <!-- Disable warnings about missing XML doc comments -->
            <NoWarn>$(NoWarn);CS1591;CS1573;CS1712</NoWarn>
        </PropertyGroup>
    </Target>

This addition will activate IDE0005 warnings in the CLI build, enabling us to refine the S1128 implementation for more precise issue detection. The existing implementation can be retained as a fallback option in instances where the ParseOptions.DocumentationMode property is set to None.

WHY

  • minimize S1128 false positives and cover all false negatives.
  • improve S1128 performance.
@cristian-ambrosini-sonarsource cristian-ambrosini-sonarsource changed the title Add nuget package to enhance S1128 by enabling IDE0005 warnings in CLI build Target files: enhance S1128 by enabling IDE0005 warnings in CLI build Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant