-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into release/4.1
- Loading branch information
Showing
88 changed files
with
867 additions
and
131 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
src/Analyzers/Analyzers.Tests/ApiUsage/UnsupportedCallSiteAttributeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System.Threading.Tasks; | ||
using DotVVM.Analyzers.ApiUsage; | ||
using Xunit; | ||
using VerifyCS = DotVVM.Analyzers.Tests.CSharpAnalyzerVerifier< | ||
DotVVM.Analyzers.ApiUsage.UnsupportedCallSiteAttributeAnalyzer>; | ||
|
||
namespace DotVVM.Analyzers.Tests.ApiUsage | ||
{ | ||
public class UnsupportedCallSiteAttributeTests | ||
{ | ||
[Fact] | ||
public async Task Test_NoDiagnostics_InvokeMethod_WithoutUnsupportedCallSiteAttribute() | ||
{ | ||
var test = @" | ||
using System; | ||
using System.IO; | ||
namespace ConsoleApplication1 | ||
{ | ||
public class RegularClass | ||
{ | ||
public void Target() | ||
{ | ||
} | ||
public void CallSite() | ||
{ | ||
Target(); | ||
} | ||
} | ||
}"; | ||
|
||
await VerifyCS.VerifyAnalyzerAsync(test); | ||
} | ||
|
||
[Fact] | ||
public async Task Test_Warning_InvokeMethod_WithUnsupportedCallSiteAttribute() | ||
{ | ||
await VerifyCS.VerifyAnalyzerAsync(@" | ||
using System; | ||
using System.IO; | ||
using DotVVM.Framework.CodeAnalysis; | ||
namespace ConsoleApplication1 | ||
{ | ||
public class RegularClass | ||
{ | ||
[UnsupportedCallSite(CallSiteType.ServerSide)] | ||
public void Target() | ||
{ | ||
} | ||
public void CallSite() | ||
{ | ||
{|#0:Target()|}; | ||
} | ||
} | ||
}", | ||
|
||
VerifyCS.Diagnostic(UnsupportedCallSiteAttributeAnalyzer.DoNotInvokeMethodFromUnsupportedCallSite) | ||
.WithLocation(0).WithArguments("Target", string.Empty)); | ||
} | ||
|
||
[Fact] | ||
public async Task Test_Warning_InvokeMethod_WithUnsupportedCallSiteAttribute_WithReason() | ||
{ | ||
await VerifyCS.VerifyAnalyzerAsync(@" | ||
using System; | ||
using System.IO; | ||
using DotVVM.Framework.CodeAnalysis; | ||
namespace ConsoleApplication1 | ||
{ | ||
public class RegularClass | ||
{ | ||
[UnsupportedCallSite(CallSiteType.ServerSide, ""REASON"")] | ||
public void Target() | ||
{ | ||
} | ||
public void CallSite() | ||
{ | ||
{|#0:Target()|}; | ||
} | ||
} | ||
}", | ||
|
||
VerifyCS.Diagnostic(UnsupportedCallSiteAttributeAnalyzer.DoNotInvokeMethodFromUnsupportedCallSite) | ||
.WithLocation(0).WithArguments("Target", "due to: \"REASON\"")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/Analyzers/Analyzers/ApiUsage/UnsupportedCallSiteAttributeAnalyzer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.Diagnostics; | ||
using Microsoft.CodeAnalysis.Operations; | ||
|
||
namespace DotVVM.Analyzers.ApiUsage | ||
{ | ||
[DiagnosticAnalyzer(LanguageNames.CSharp)] | ||
public sealed class UnsupportedCallSiteAttributeAnalyzer : DiagnosticAnalyzer | ||
{ | ||
private static readonly LocalizableResourceString unsupportedCallSiteTitle = new(nameof(Resources.ApiUsage_UnsupportedCallSite_Title), Resources.ResourceManager, typeof(Resources)); | ||
private static readonly LocalizableResourceString unsupportedCallSiteMessage = new(nameof(Resources.ApiUsage_UnsupportedCallSite_Message), Resources.ResourceManager, typeof(Resources)); | ||
private static readonly LocalizableResourceString unsupportedCallSiteDescription = new(nameof(Resources.ApiUsage_UnsupportedCallSite_Description), Resources.ResourceManager, typeof(Resources)); | ||
private const string unsupportedCallSiteAttributeMetadataName = "DotVVM.Framework.CodeAnalysis.UnsupportedCallSiteAttribute"; | ||
private const int callSiteTypeServerUnderlyingValue = 0; | ||
|
||
public static DiagnosticDescriptor DoNotInvokeMethodFromUnsupportedCallSite = new DiagnosticDescriptor( | ||
DotvvmDiagnosticIds.DoNotInvokeMethodFromUnsupportedCallSiteRuleId, | ||
unsupportedCallSiteTitle, | ||
unsupportedCallSiteMessage, | ||
DiagnosticCategory.ApiUsage, | ||
DiagnosticSeverity.Warning, | ||
isEnabledByDefault: true, | ||
unsupportedCallSiteDescription); | ||
|
||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics | ||
=> ImmutableArray.Create(DoNotInvokeMethodFromUnsupportedCallSite); | ||
|
||
public override void Initialize(AnalysisContext context) | ||
{ | ||
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics); | ||
context.EnableConcurrentExecution(); | ||
|
||
context.RegisterOperationAction(context => | ||
{ | ||
var unsupportedCallSiteAttribute = context.Compilation.GetTypeByMetadataName(unsupportedCallSiteAttributeMetadataName); | ||
if (unsupportedCallSiteAttribute is null) | ||
return; | ||
if (context.Operation is IInvocationOperation invocation) | ||
{ | ||
var method = invocation.TargetMethod; | ||
var attribute = method.GetAttributes().FirstOrDefault(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, unsupportedCallSiteAttribute)); | ||
if (attribute is null || !attribute.ConstructorArguments.Any()) | ||
return; | ||
if (attribute.ConstructorArguments.First().Value is not int callSiteType || callSiteTypeServerUnderlyingValue != callSiteType) | ||
return; | ||
var reason = (string?)attribute.ConstructorArguments.Skip(1).First().Value; | ||
context.ReportDiagnostic( | ||
Diagnostic.Create( | ||
DoNotInvokeMethodFromUnsupportedCallSite, | ||
invocation.Syntax.GetLocation(), | ||
invocation.TargetMethod.Name, | ||
(reason != null) ? $"due to: \"{reason}\"" : string.Empty)); | ||
} | ||
}, OperationKind.Invocation); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Annotations for DotVVM Auto UI | ||
|
||
This package only contains annotations and some interfaces used to annotate classes for which [DotVVM.AutoUI](https://www.nuget.org/packages/DotVVM.AutoUI) can create forms and tables. | ||
|
||
DotVVM.AutoUI.Annotations only depends on DotVVM.Core, and is intended to be included in non-web projects. | ||
|
||
Attributes included: | ||
* `VisibleAttribute`, `EnabledAttribute` | ||
* `ComboBoxSettingsAttribute` | ||
* `StyleAttribute` for hardcoding css classes | ||
* `SelectionAttribute` for declaring selectable fields using components like RadioButton | ||
|
||
Base classes included: | ||
* `Selection` for selectable items |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.