Skip to content

[Analyzer] Make types declared in an executable internal #78388

Closed
dotnet/roslyn-analyzers
#6820

Description

@stephentoub

Various analyzers only pay attention to internal/private types and members, as changes to public API is visible. For example, analyzers/fixers that find and remove dead code, or that recommend types without derivations be sealed. Applications, rather than libraries, however, typically aren't referenced, and public types/members are likely mistakes, such that if the mistakes are corrected and the types/members have their visibility changed to internal/private, then other analyzers can start making recommendations for them.

The proposal is to add an analyzer/fixer that runs when a compilation's OutputKind is ConsoleApplication or WindowsApplication and that flags all public types, recommending they instead be made internal.

Activity

  1. added
    code-analyzerMarks an issue that suggests a Roslyn analyzer
    code-fixerMarks an issue that suggests a Roslyn code fixer
    on Nov 15, 2022
  2. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Nov 15, 2022
  3. added this to the 8.0.0 milestone on Nov 16, 2022
  4. ghost removed
    untriagedNew issue has not been triaged by the area owner
    on Nov 16, 2022
  5. added
    api-suggestionEarly API idea and discussion, it is NOT ready for implementation
    on Nov 21, 2022
  6. added
    api-ready-for-reviewAPI is ready for review, it is NOT ready for implementation
    and removed
    api-suggestionEarly API idea and discussion, it is NOT ready for implementation
    on Jan 24, 2023
  7. bartonjs commented on Mar 7, 2023

    @bartonjs
    Member

    Video

    Looks good as proposed.

    Given concerns with some of the templates (e.g. WinForms creating the skeleton for a new form type being default) we're recommending this analyzer be opt-in. But we're probably easily convinced that it should be something else.

    Category: Maintainability (?)
    Visibility: None (off by default; might be nice if trimmer-style scenarios can flip it on by default)

  8. added
    api-approvedAPI was approved in API review, it can be implemented
    and removed
    api-ready-for-reviewAPI is ready for review, it is NOT ready for implementation
    on Mar 7, 2023
  9. marek-safar commented on Mar 8, 2023

    @marek-safar
    Contributor

    The proposal is to add an analyzer/fixer that runs when a compilation's OutputKind is ConsoleApplication or WindowsApplication and that flags all public types, recommending they instead be made internal.

    Could the analyzer run when the output binary contains runnable entry-point?

  10. added
    help wanted[up-for-grabs] Good issue for external contributors
    on May 4, 2023
  11. CollinAlpert commented on Jul 28, 2023

    @CollinAlpert
    Contributor

    Should this consider the OutputKind WindowsRuntimeApplication as well?

  12. removed
    help wanted[up-for-grabs] Good issue for external contributors
    on Jul 31, 2023
  13. modified the milestones: 8.0.0, 9.0.0 on Aug 11, 2023
  14. KennethHoff commented on Sep 14, 2023

    @KennethHoff

    I see a lot of the newly added analyzers are opt-in.

    How do I as a developer enable them, and more importantly, find which ones to enable? Basically, is there an easily digestible list somewhere?

    I remember seeing a few good ones being added, so I worry that I'll forget about them and not benefit from them!

  15. CollinAlpert commented on Sep 15, 2023

    @CollinAlpert
    Contributor

    You can add an .editorconfig file to your solution and then select the severity of the rules you would like. For example:
    dotnet_diagnostic.CA1018.severity = warning

    More information here

  16. cremor commented on Sep 15, 2023

    @cremor

    I assume it will also be enabled by setting <AnalysisLevel>latest-all</AnalysisLevel>?

  17. mavasani commented on Sep 26, 2023

    @mavasani

    I assume it will also be enabled by setting <AnalysisLevel>latest-all</AnalysisLevel>?

    Indeed, that is correct.

  18. ghost locked as resolved and limited conversation to collaborators on Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api-approvedAPI was approved in API review, it can be implementedarea-Metacode-analyzerMarks an issue that suggests a Roslyn analyzercode-fixerMarks an issue that suggests a Roslyn code fixer

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions