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

CA1845: Adds unnecessary using statement when implicit usings exist #5652

Closed
timheuer opened this issue Oct 18, 2021 · 4 comments · Fixed by #6358
Closed

CA1845: Adds unnecessary using statement when implicit usings exist #5652

timheuer opened this issue Oct 18, 2021 · 4 comments · Fixed by #6358
Assignees
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzers Bug The product is not behaving according to its current intended design

Comments

@timheuer
Copy link
Member

Version Used:
Microsoft Visual Studio Enterprise 2022 Int Preview (64-bit)
Version 17.0.0 Preview 5.0 [31808.319.d17.0]

Steps to Reproduce:

  1. Create a new console app in .NET6 - default implicit usings
  2. Add some code that triggers CA1845
  3. Executing the code fix

Expected Behavior:
using System; is not added

Actual Behavior:
It is added

Not sure if this is expected with the ImplicitUsings feature, but I just always hate when tools add something immediately grayed out.
implicit

@Youssef1313
Copy link
Member

Can someone move to dotnet/roslyn-analyzers?

Also tagging @NewellClark

@CyrusNajmabadi
Copy link
Member

This is likely still in Roslyn. We have a mechanism to allow actions to add usings if missing. That likely needs to be updated to account for global usings.

@Youssef1313
Copy link
Member

@CyrusNajmabadi Might need tweaks in both repos then? This is what the fixer in roslyn-analyzer does.

private protected override bool IsSystemNamespaceImported(Project project, IReadOnlyList<SyntaxNode> namespaceImports)
{
foreach (var import in namespaceImports)
{
if (import is UsingDirectiveSyntax { Name: IdentifierNameSyntax { Identifier: { ValueText: nameof(System) } } })
return true;
}
return false;
}

@CyrusNajmabadi
Copy link
Member

Ah, in that cse, this is def on them. Moving. Thanks!

@CyrusNajmabadi CyrusNajmabadi transferred this issue from dotnet/roslyn Oct 18, 2021
@Youssef1313 Youssef1313 self-assigned this Dec 12, 2022
@Youssef1313 Youssef1313 added Bug The product is not behaving according to its current intended design Area-Microsoft.CodeAnalysis.NetAnalyzers labels Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzers Bug The product is not behaving according to its current intended design
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants