Skip to content

Commit

Permalink
fixing up analyzer warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarolf committed Aug 25, 2021
1 parent be1bce5 commit 47ed79d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 77 deletions.
4 changes: 4 additions & 0 deletions perf/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Code files
[*.{cs,csx,vb,vbx}]
# CA1822: Make member static
dotnet_diagnostic.CA1822.severity = none
15 changes: 13 additions & 2 deletions src/Analyzers/AnalyzerReferenceInformationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private AnalyzersAndFixers GetAnalyzersAndFixers(Project project)
return AnalyzerFinderHelpers.LoadAnalyzersAndFixers(analyzerAssemblies);
}

private Assembly? TryLoadAssemblyFrom(string? path)
private static Assembly? TryLoadAssemblyFrom(string? path)
{
// Since we are not deploying these assemblies we need to ensure the files exist.
if (path is null || !File.Exists(path))
Expand Down Expand Up @@ -77,7 +77,13 @@ internal sealed class AnalyzerLoadContext : AssemblyLoadContext

public AnalyzerLoadContext(string assemblyPath)
{
var analyzerDirectory = new DirectoryInfo(Path.GetDirectoryName(assemblyPath));
var assemblyDirectory = Path.GetDirectoryName(assemblyPath);
if (assemblyDirectory is null)
{
throw new InvalidOperationException($"Assembly path invalid '{assemblyPath}'");
}

var analyzerDirectory = new DirectoryInfo(assemblyDirectory);

// Analyzer packages will put language specific assemblies in subfolders.
if (analyzerDirectory.Name == "cs" || analyzerDirectory.Name == "vb")
Expand All @@ -86,6 +92,11 @@ public AnalyzerLoadContext(string assemblyPath)
analyzerDirectory = analyzerDirectory.Parent;
}

if (analyzerDirectory is null)
{
throw new InvalidOperationException($"Could not get parent directory for '{assemblyPath}'");
}

AssemblyFolderPath = analyzerDirectory.FullName;
DependencyResolver = new AssemblyDependencyResolver(assemblyPath);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Logging/SimpleConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void LogToTerminal(string message, LogLevel logLevel, bool logToErrorStr
_terminal.ResetColor();
}

private void LogToConsole(IConsole console, string message, bool logToErrorStream)
private static void LogToConsole(IConsole console, string message, bool logToErrorStream)
{
if (logToErrorStream)
{
Expand Down
4 changes: 4 additions & 0 deletions tests/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Code files
[*.{cs,csx,vb,vbx}]
# CA1822: Make member static
dotnet_diagnostic.CA1822.severity = silent
74 changes: 0 additions & 74 deletions tests/ProgramTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,80 +182,6 @@ public void CommandLine_AnalyzerOptions_CanSpecifyBothWithDefaults()
Assert.Equal(0, result.Errors.Count);
}

[Fact]
// If this test fails that means FormatCommand options have changed, ensure the FormatCommand.Handler has been updated to match.
public async Task CommandLine_AllArguments_Bind()
{
// Arrange
var uniqueExitCode = 143;

var sut = RootFormatCommand.GetCommand();

Task<int> TestRun(
string workspace,
bool noRestore,
bool folder,
bool fixWhitespace,
string fixStyle,
string fixAnalyzers,
string[] diagnostics,
string verbosity,
bool check,
string[] include,
string[] exclude,
string report,
bool includeGenerated,
string binaryLogPath,
IConsole console = null)
{
Assert.Equal("./src", workspace);
Assert.True(noRestore);
Assert.False(folder);
Assert.True(fixWhitespace);
Assert.Equal("warn", fixStyle);
Assert.Equal("info", fixAnalyzers);
Assert.Equal(new[] { "IDE0005", "IDE0073" }, diagnostics);
Assert.Equal("diag", verbosity);
Assert.True(check);
Assert.Equal(new[] { "*.cs" }, include);
Assert.Equal(new[] { "*.vb" }, exclude);
Assert.Equal("report.json", report);
Assert.True(includeGenerated);

return Task.FromResult(uniqueExitCode);
}

var args = @"
./src
--no-restore
--fix-whitespace
--fix-style
warn
--fix-analyzers
info
--diagnostics
IDE0005
IDE0073
--verbosity
diag
--check
--include
*.cs
--exclude
*.vb
--report
report.json
--include-generated".Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);

// Act
var parseResult = sut.Parse(args);
var result = await sut.InvokeAsync(args);

// Assert
Assert.Equal(0, parseResult.Errors.Count);
Assert.Equal(uniqueExitCode, result);
}

[Fact]
public void CommandLine_BinaryLog_DoesNotFailIfPathNotSpecified()
{
Expand Down

0 comments on commit 47ed79d

Please sign in to comment.