Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vipwan committed Sep 6, 2024
1 parent 1ca7496 commit 9e01965
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
9 changes: 2 additions & 7 deletions AutoClassGenTest/AddFileHeaderCodeFixProviderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,18 @@ public async Task Test()
{
var @code = "namespace Biwen { public interface IRequest {} }";

var fixedCode = """
var fixedCode = $"""
// Licensed to the TestProject under one or more agreements.
// The TestProject licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace Biwen { public interface IRequest {} }
{@code}
""";

Diagnostic(FileHeaderAnalyzer.DiagnosticId)
.WithSpan(1, 1, 1, 1)
.WithLocation(1, 1);
;

//设置修复器的路径:




await VerifyAnalyzerAsync(@code);
await VerifyCodeFixAsync(@code, fixedCode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ private static async Task<Document> FixDocumentAsync(Document document, TextSpan

//当Assembly为Microsoft.CodeAnalysis.TypedConstant时不做处理

if (!compilation?.AssemblyName?.StartsWith("Microsoft.CodeAnalysis", StringComparison.Ordinal) is true)
if (compilation?.AssemblyName?.StartsWith("Microsoft", StringComparison.Ordinal) is not true)
{
var constants = new List<AssemblyConstant>();

var assemblyAttributes = compilation?.Assembly.GetAttributes();

if (assemblyAttributes is not null)
{
foreach (var attribute in assemblyAttributes)
Expand Down Expand Up @@ -218,6 +218,7 @@ private static async Task<Document> FixDocumentAsync(Document document, TextSpan
}
}
}

#endregion

//使用正则表达式替换
Expand All @@ -238,7 +239,7 @@ private static async Task<Document> FixDocumentAsync(Document document, TextSpan
"TargetFramework" => targetFramework,
_ => m.Value,
};
});
}, RegexOptions.Singleline);

var headerComment = SyntaxFactory.Comment(comment + Environment.NewLine);
var newRoot = root?.WithLeadingTrivia(headerComment);
Expand Down

0 comments on commit 9e01965

Please sign in to comment.