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

Prefer const for literals that are assigned upon declaration and not re-assigned #7492

Open
Bartleby2718 opened this issue Aug 29, 2024 · 0 comments
Labels
Feature Request help wanted The issue is up-for-grabs, and can be claimed by commenting

Comments

@Bartleby2718
Copy link

Brief description: My team prefers using consts for literals that are assigned upon declaration and not re-assigned. I'm sure there are other teams that'd agree, but I'm curious if there's an analyzer for this. If not, can we add one?

Languages applicable:

Is your analyzer C# only? VB Only? Or Both? - Both

Code example that the analyzer should report:

// before
private void PrintHelpText()
{
    var helpText = "This is how you do it."; // flag this variable because it's assigned upon declaration, not re-assigned
    Console.Write(helpText);
}

could be updated to

// after
private void PrintHelpText()
{
    const string helpText = "This is how you do it.";
    Console.Write(helpText);
}

Documentation requirements:

When this analyzer is implemented, it must be documented by following the steps at Documentation for IDE CodeStyle analyzers.

@deepakrathore33 deepakrathore33 added help wanted The issue is up-for-grabs, and can be claimed by commenting and removed untriaged labels Oct 23, 2024
@CyrusNajmabadi CyrusNajmabadi transferred this issue from dotnet/roslyn Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request help wanted The issue is up-for-grabs, and can be claimed by commenting
Projects
None yet
Development

No branches or pull requests

2 participants