Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanLarsson committed Apr 5, 2023
1 parent b3ed621 commit 055bb10
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Gu.Roslyn.Asserts.Tests/RoslynAssertTests/Valid.Success.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ public class C
[TestCase("m_")]
public static void AnalyzerWithConfiguration(string? prefix)
{
string? analyzerConfig = prefix is null ? null :
var analyzerConfig = prefix is null ? null :
$"dotnet_diagnostic.SA1309.field_name_prefix = {prefix}";
string prefixToUse = prefix ?? "_";
var prefixToUse = prefix ?? "_";

var code = @$"
namespace N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ internal static async Task<Solution> RenameSymbolAsync(Document document, Syntax
{
var annotatedRoot = root.ReplaceToken(declarationToken, declarationToken.WithAdditionalAnnotations(RenameAnnotation.Create()));
var annotatedSolution = document.Project.Solution.WithDocumentSyntaxRoot(document.Id, annotatedRoot);
var annotatedDocument = annotatedSolution.GetDocument(document.Id);
if (annotatedDocument is null)
{
throw new InvalidOperationException($"Did not find a document matching {document.Name}");
}

var annotatedDocument = annotatedSolution.GetDocument(document.Id) ?? throw new InvalidOperationException($"Did not find a document matching {document.Name}");
annotatedRoot = await annotatedDocument.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var annotatedToken = annotatedRoot.FindToken(declarationToken.SpanStart);

Expand Down
7 changes: 1 addition & 6 deletions Gu.Roslyn.Asserts/Ast/SyntaxFactoryWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,7 @@ private SyntaxFactoryWriter Write(SyntaxNode node)
var parameters = method.GetParameters();
foreach (var parameter in parameters)
{
var writer = ArgumentWriters[parameter];
if (writer is null)
{
throw new NotSupportedException($"Could not write {parameter}");
}

var writer = ArgumentWriters[parameter] ?? throw new NotSupportedException($"Could not write {parameter}");
writer.Invoke(this, node, parameter.Position == parameters.Length - 1);
}

Expand Down
21 changes: 3 additions & 18 deletions Gu.Roslyn.Asserts/ProjectFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ public static bool TryFind(string projectFile, [NotNullWhen(true)] out FileInfo?
public static FileInfo Find(string projectFile)
{
var sln = SolutionFile.Find(Assembly.GetCallingAssembly());
var result = sln.Directory!.EnumerateFiles(projectFile, SearchOption.AllDirectories).FirstOrDefault();
if (result is null)
{
throw new InvalidOperationException("Did not find a file named: " + projectFile);
}

var result = sln.Directory!.EnumerateFiles(projectFile, SearchOption.AllDirectories).FirstOrDefault() ?? throw new InvalidOperationException("Did not find a file named: " + projectFile);
return result;
}

Expand Down Expand Up @@ -178,12 +173,7 @@ IEnumerable<DocumentInfo> GetDocuments()

foreach (var compile in compiles)
{
var include = compile.Attribute("Include")?.Value;
if (include is null)
{
throw new InvalidOperationException("Parsing failed, no Include found.");
}

var include = compile.Attribute("Include")?.Value ?? throw new InvalidOperationException("Parsing failed, no Include found.");
var csFile = Path.Combine(csproj.Directory!.FullName, include);
yield return CreateDocumentInfo(new FileInfo(csFile));
}
Expand Down Expand Up @@ -219,12 +209,7 @@ IEnumerable<MetadataReference> GetMetadataReferences()

foreach (var compile in compiles)
{
var include = compile.Attribute("Include")?.Value;
if (include is null)
{
throw new InvalidOperationException("Parsing failed, no Include found.");
}

var include = compile.Attribute("Include")?.Value ?? throw new InvalidOperationException("Parsing failed, no Include found.");
if (include.Contains("\\") &&
Path.Combine(csproj.Directory.FullName, include) is { } fileName &&
File.Exists(fileName))
Expand Down
2 changes: 1 addition & 1 deletion Gu.Roslyn.Asserts/RoslynAssert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private static void VerifyDiagnostics(

var missedDiagnostics = expectedDiagnostics.Where(e => !allDiagnostics.Any(a => e.Matches(a))).ToList();
var unexpectedDiagnostics = allDiagnostics.Where(a => !expectedDiagnostics.Any(e => e.Matches(a))).ToList();
int matchedDiagnostics = expectedDiagnostics.Count - missedDiagnostics.Count;
var matchedDiagnostics = expectedDiagnostics.Count - missedDiagnostics.Count;

var error = StringBuilderPool.Borrow();
error.AppendLine("Expected and actual diagnostics do not match.");
Expand Down

0 comments on commit 055bb10

Please sign in to comment.