diff --git a/perf/.editorconfig b/perf/.editorconfig new file mode 100644 index 0000000000..8fc105f852 --- /dev/null +++ b/perf/.editorconfig @@ -0,0 +1,4 @@ +# Code files +[*.{cs,csx,vb,vbx}] +# CA1822: Make member static +dotnet_diagnostic.CA1822.severity = none \ No newline at end of file diff --git a/src/Analyzers/AnalyzerReferenceInformationProvider.cs b/src/Analyzers/AnalyzerReferenceInformationProvider.cs index 476e13c4ff..6b688878b4 100644 --- a/src/Analyzers/AnalyzerReferenceInformationProvider.cs +++ b/src/Analyzers/AnalyzerReferenceInformationProvider.cs @@ -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)) @@ -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") @@ -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); } diff --git a/src/Logging/SimpleConsoleLogger.cs b/src/Logging/SimpleConsoleLogger.cs index 79c87c2e46..c361f84a04 100644 --- a/src/Logging/SimpleConsoleLogger.cs +++ b/src/Logging/SimpleConsoleLogger.cs @@ -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) { diff --git a/tests/.editorconfig b/tests/.editorconfig new file mode 100644 index 0000000000..6f3d1d667a --- /dev/null +++ b/tests/.editorconfig @@ -0,0 +1,4 @@ +# Code files +[*.{cs,csx,vb,vbx}] +# CA1822: Make member static +dotnet_diagnostic.CA1822.severity = silent \ No newline at end of file diff --git a/tests/ProgramTests.cs b/tests/ProgramTests.cs index 8183f82e7b..3ab3814178 100644 --- a/tests/ProgramTests.cs +++ b/tests/ProgramTests.cs @@ -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 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() {