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

Do not run 'remove unnecessary imports' on generated code #74762

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,22 +186,9 @@ public async Task TestGeneratedCode()
var source = """
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a [WorkItem] to the test to clarify, why no diagnostics there are expected

// <auto-generated/>

[|{|IDE0005_gen:using System;|}
using System.Collections.Generic;
{|IDE0005_gen:using System.Linq;|}|]

class Program
{
static void Main(string[] args)
{
List<int> d;
}
}
""";
var fixedSource = """
// <auto-generated/>

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
Expand All @@ -212,18 +199,9 @@ static void Main(string[] args)
}
""";

// Fix All operations in generated code do not apply changes
var batchFixedSource = source;

await new VerifyCS.Test
{
TestCode = source,
FixedCode = fixedSource,
BatchFixedState =
{
Sources = { batchFixedSource },
MarkupHandling = MarkupMode.Allow,
},
}.RunAsync();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ private static ImmutableArray<DiagnosticDescriptor> GetDescriptors(LocalizableSt
protected abstract bool IsRegularCommentOrDocComment(SyntaxTrivia trivia);
protected abstract IUnnecessaryImportsProvider<TSyntaxNode> UnnecessaryImportsProvider { get; }

protected override GeneratedCodeAnalysisFlags GeneratedCodeAnalysisFlags => GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics;
Copy link
Member

@Youssef1313 Youssef1313 Aug 15, 2024

Choose a reason for hiding this comment

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

That way I think -generatedCodeClassificationIdDescriptor can be removed along with the check that selects the descriptor based on whether this is generated code or not


protected abstract SyntaxToken? TryGetLastToken(SyntaxNode node);

protected override void InitializeWorker(AnalysisContext context)
Expand Down
Loading
Loading