diff --git a/.editorconfig b/.editorconfig index 89fc10043..939fe68d5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -39,6 +39,7 @@ indent_size = 2 insert_final_newline = true [*.cs] +dotnet_diagnostic.RS1041.severity = none dotnet_diagnostic.RS2008.severity = none dotnet_diagnostic.CA1508.severity = none diff --git a/Directory.Build.targets b/Directory.Build.targets index 365d1502f..3b75ee2d1 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -78,10 +78,10 @@ - - - - + + + + $(DefineConstants);ROSLYN4_8;ROSLYN_4_2_OR_GREATER;ROSLYN_4_4_OR_GREATER;ROSLYN_4_5_OR_GREATER;ROSLYN_4_6_OR_GREATER;ROSLYN_4_8_OR_GREATER diff --git a/src/Meziantou.Analyzer/Rules/DoNotUseBlockingCallInAsyncContextAnalyzer.cs b/src/Meziantou.Analyzer/Rules/DoNotUseBlockingCallInAsyncContextAnalyzer.cs index 4e02c2b43..f3373d2a8 100644 --- a/src/Meziantou.Analyzer/Rules/DoNotUseBlockingCallInAsyncContextAnalyzer.cs +++ b/src/Meziantou.Analyzer/Rules/DoNotUseBlockingCallInAsyncContextAnalyzer.cs @@ -72,7 +72,7 @@ public Context(Compilation compilation) var consoleSymbol = compilation.GetBestTypeByMetadataName("System.Console"); if (consoleSymbol is not null) { - ConsoleErrorAndOutSymbols = [.. consoleSymbol.GetMembers(nameof(Console.Out)), .. consoleSymbol.GetMembers(nameof(Console.Error))]; + ConsoleErrorAndOutSymbols = [.. consoleSymbol.GetMembers("Out"), .. consoleSymbol.GetMembers("Error")]; } else { diff --git a/src/Meziantou.Analyzer/Rules/DoNotUseUnknownParameterForRazorComponentAnalyzer.cs b/src/Meziantou.Analyzer/Rules/DoNotUseUnknownParameterForRazorComponentAnalyzer.cs index 8ae33b450..f1b2b6648 100644 --- a/src/Meziantou.Analyzer/Rules/DoNotUseUnknownParameterForRazorComponentAnalyzer.cs +++ b/src/Meziantou.Analyzer/Rules/DoNotUseUnknownParameterForRazorComponentAnalyzer.cs @@ -74,7 +74,7 @@ public void AnalyzeBlockOptions(OperationAnalysisContext context) { currentComponent = null; } - else if (currentComponent is not null && targetMethod.Name == "AddAttribute") + else if (currentComponent is not null && targetMethod.Name is "AddAttribute" or "AddComponentParameter") { if (targetMethod.Parameters.Length >= 2 && targetMethod.Parameters[1].Type.IsString()) { diff --git a/tests/Meziantou.Analyzer.Test/Rules/DoNotUseUnknownParameterForRazorComponentAnalyzerTests.cs b/tests/Meziantou.Analyzer.Test/Rules/DoNotUseUnknownParameterForRazorComponentAnalyzerTests.cs index 40b5a6c71..32f3e4f56 100644 --- a/tests/Meziantou.Analyzer.Test/Rules/DoNotUseUnknownParameterForRazorComponentAnalyzerTests.cs +++ b/tests/Meziantou.Analyzer.Test/Rules/DoNotUseUnknownParameterForRazorComponentAnalyzerTests.cs @@ -71,7 +71,7 @@ private static ProjectBuilder CreateProjectBuilder() { return new ProjectBuilder() .WithAnalyzer() - .WithTargetFramework(TargetFramework.AspNetCore6_0); + .WithTargetFramework(TargetFramework.AspNetCore8_0); } [Theory] @@ -209,6 +209,26 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components. __builder.CloseComponent(); } } +"""; + await CreateProjectBuilder() + .WithSourceCode(Usings + sourceCode + ComponentWithChildContent) + .ValidateAsync(); + } + + [Fact] + public async Task InvalidParameterInAddComponentParameter_Net8() + { + var sourceCode = $$""" +class TypeName : ComponentBase +{ + protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + __builder.OpenComponent(1); + [||]__builder.AddComponentParameter(2, "Text", "DummyDisplayText"); + [||]__builder.AddComponentParameter(3, "OtherAttribute", "Test"); + __builder.CloseComponent(); + } +} """; await CreateProjectBuilder() .WithSourceCode(Usings + sourceCode + ComponentWithChildContent)