Browse Source
* Split analyzers and code fixes * Split C# and VB analyzers * Merge all analyzer packages * Add Analyzers.VisualBasic to .slnfpull/20428/head
committed by
GitHub
23 changed files with 233 additions and 73 deletions
@ -1,12 +1,20 @@ |
|||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<ItemGroup> |
<ItemGroup> |
||||
<ProjectReference Include="$(MSBuildThisFileDirectory)..\src\tools\DevAnalyzers\DevAnalyzers.csproj" |
<ProjectReference Include="$(MSBuildThisFileDirectory)../src/tools/DevAnalyzers/DevAnalyzers.csproj" |
||||
PrivateAssets="all" |
PrivateAssets="all" |
||||
ReferenceOutputAssembly="false" |
ReferenceOutputAssembly="false" |
||||
OutputItemType="Analyzer" /> |
OutputItemType="Analyzer" /> |
||||
<ProjectReference Include="$(MSBuildThisFileDirectory)..\src\tools\Avalonia.Analyzers\Avalonia.Analyzers.csproj" |
<ProjectReference Include="$(MSBuildThisFileDirectory)../src/tools/Avalonia.Analyzers.CSharp/Avalonia.Analyzers.CSharp.csproj" |
||||
PrivateAssets="all" |
PrivateAssets="all" |
||||
ReferenceOutputAssembly="false" |
ReferenceOutputAssembly="false" |
||||
OutputItemType="Analyzer" /> |
OutputItemType="Analyzer" /> |
||||
|
<ProjectReference Include="$(MSBuildThisFileDirectory)../src/tools/Avalonia.Analyzers.CodeFixes.CSharp/Avalonia.Analyzers.CodeFixes.CSharp.csproj" |
||||
|
PrivateAssets="all" |
||||
|
ReferenceOutputAssembly="false" |
||||
|
OutputItemType="Analyzer" /> |
||||
|
<ProjectReference Include="$(MSBuildThisFileDirectory)../src/tools/Avalonia.Analyzers.VisualBasic/Avalonia.Analyzers.VisualBasic.csproj" |
||||
|
ReferenceOutputAssembly="false" |
||||
|
PrivateAssets="all" |
||||
|
OutputItemType="Analyzer" /> |
||||
</ItemGroup> |
</ItemGroup> |
||||
</Project> |
</Project> |
||||
|
|||||
@ -1,17 +1,24 @@ |
|||||
<Project Sdk="Microsoft.NET.Sdk"> |
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
<PropertyGroup> |
<PropertyGroup> |
||||
<TargetFramework>netstandard2.0</TargetFramework> |
<TargetFramework>netstandard2.0</TargetFramework> |
||||
<IncludeBuildOutput>false</IncludeBuildOutput> |
<IncludeBuildOutput>false</IncludeBuildOutput> |
||||
<DebugType>embedded</DebugType> |
<DebugType>embedded</DebugType> |
||||
<IsPackable>true</IsPackable> |
<IsPackable>true</IsPackable> |
||||
<IncludeSymbols>false</IncludeSymbols> |
<IncludeSymbols>false</IncludeSymbols> |
||||
|
<RootNamespace>Avalonia.Analyzers</RootNamespace> |
||||
</PropertyGroup> |
</PropertyGroup> |
||||
|
|
||||
<ItemGroup> |
<ItemGroup> |
||||
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" /> |
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.5.0" PrivateAssets="all" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<None Include="$(OutputPath)/$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" /> |
||||
</ItemGroup> |
</ItemGroup> |
||||
|
|
||||
<Import Project="../../../build/TrimmingEnable.props" /> |
<Import Project="../../../build/TrimmingEnable.props" /> |
||||
<Import Project="../../../build/NullableEnable.props" /> |
<Import Project="../../../build/NullableEnable.props" /> |
||||
<Import Project="../../../build/AnalyzerProject.targets" /> |
<Import Project="../../../build/AnalyzerProject.targets" /> |
||||
|
|
||||
</Project> |
</Project> |
||||
@ -0,0 +1,16 @@ |
|||||
|
using System; |
||||
|
using System.Runtime.Serialization; |
||||
|
|
||||
|
namespace Avalonia.Analyzers; |
||||
|
|
||||
|
[Serializable] |
||||
|
public class AvaloniaAnalysisException : Exception |
||||
|
{ |
||||
|
public AvaloniaAnalysisException(string message, Exception? innerException = null) : base(message, innerException) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
protected AvaloniaAnalysisException(SerializationInfo info, StreamingContext context) : base(info, context) |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
using System.Linq; |
||||
|
using Microsoft.CodeAnalysis; |
||||
|
using Microsoft.CodeAnalysis.CSharp; |
||||
|
using Microsoft.CodeAnalysis.Diagnostics; |
||||
|
using Microsoft.CodeAnalysis.Operations; |
||||
|
|
||||
|
namespace Avalonia.Analyzers; |
||||
|
|
||||
|
[DiagnosticAnalyzer(LanguageNames.CSharp)] |
||||
|
public partial class AvaloniaPropertyAnalyzer |
||||
|
{ |
||||
|
private static partial TypeReference TypeReferenceFromInvocationTypeParameter(IInvocationOperation invocation, ITypeParameterSymbol typeParameter) |
||||
|
{ |
||||
|
var argument = invocation.TargetMethod.TypeArguments[typeParameter.Ordinal]; |
||||
|
var typeArgumentSyntax = invocation.Syntax; |
||||
|
|
||||
|
// type arguments do not appear in the invocation, so search the code for them
|
||||
|
try |
||||
|
{ |
||||
|
typeArgumentSyntax = invocation.Syntax.DescendantNodes() |
||||
|
.First(n => n.IsKind(SyntaxKind.TypeArgumentList)) |
||||
|
.DescendantNodes().ElementAt(typeParameter.Ordinal); |
||||
|
} |
||||
|
catch |
||||
|
{ |
||||
|
// ignore, this is just a nicety
|
||||
|
} |
||||
|
|
||||
|
return new TypeReference(argument, typeArgumentSyntax.GetLocation()); |
||||
|
} |
||||
|
|
||||
|
private static partial bool IsSimpleAssignmentNode(SyntaxNode node) |
||||
|
=> node.IsKind(SyntaxKind.SimpleAssignmentExpression); |
||||
|
|
||||
|
private static partial bool IsInvocationNode(SyntaxNode node) |
||||
|
=> node.IsKind(SyntaxKind.InvocationExpression); |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
namespace Avalonia.Analyzers; |
||||
|
|
||||
|
public static class DiagnosticIds |
||||
|
{ |
||||
|
public const string OnPropertyChangedOverride = "AVA2001"; |
||||
|
public const string Bitmap = "AVA2002"; |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netstandard2.0</TargetFramework> |
||||
|
<IncludeBuildOutput>false</IncludeBuildOutput> |
||||
|
<DebugType>embedded</DebugType> |
||||
|
<IsPackable>true</IsPackable> |
||||
|
<IncludeSymbols>false</IncludeSymbols> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.5.0" PrivateAssets="all" /> |
||||
|
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.5.0" PrivateAssets="all" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<None Include="$(OutputPath)/$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<Compile Include="../Avalonia.Analyzers.CSharp/DiagnosticIds.cs" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<Import Project="../../../build/TrimmingEnable.props" /> |
||||
|
<Import Project="../../../build/NullableEnable.props" /> |
||||
|
<Import Project="../../../build/AnalyzerProject.targets" /> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,30 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netstandard2.0</TargetFramework> |
||||
|
<IncludeBuildOutput>false</IncludeBuildOutput> |
||||
|
<DebugType>embedded</DebugType> |
||||
|
<IsPackable>true</IsPackable> |
||||
|
<IncludeSymbols>false</IncludeSymbols> |
||||
|
<RootNamespace>Avalonia.Analyzers</RootNamespace> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="4.5.0" PrivateAssets="all" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<None Include="$(OutputPath)/$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<Compile Include="../Avalonia.Analyzers.CSharp/AvaloniaAnalysisException.cs" /> |
||||
|
<Compile Include="../Avalonia.Analyzers.CSharp/AvaloniaPropertyAnalyzer.CompileAnalyzer.cs" /> |
||||
|
<Compile Include="../Avalonia.Analyzers.CSharp/AvaloniaPropertyAnalyzer.cs" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<Import Project="../../../build/TrimmingEnable.props" /> |
||||
|
<Import Project="../../../build/NullableEnable.props" /> |
||||
|
<Import Project="../../../build/AnalyzerProject.targets" /> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,24 @@ |
|||||
|
using Microsoft.CodeAnalysis; |
||||
|
using Microsoft.CodeAnalysis.Diagnostics; |
||||
|
using Microsoft.CodeAnalysis.Operations; |
||||
|
using Microsoft.CodeAnalysis.VisualBasic; |
||||
|
|
||||
|
namespace Avalonia.Analyzers; |
||||
|
|
||||
|
[DiagnosticAnalyzer(LanguageNames.VisualBasic)] |
||||
|
public partial class AvaloniaPropertyAnalyzer |
||||
|
{ |
||||
|
private static partial TypeReference TypeReferenceFromInvocationTypeParameter(IInvocationOperation invocation, ITypeParameterSymbol typeParameter) |
||||
|
{ |
||||
|
var argument = invocation.TargetMethod.TypeArguments[typeParameter.Ordinal]; |
||||
|
var typeArgumentSyntax = invocation.Syntax; |
||||
|
|
||||
|
return new TypeReference(argument, typeArgumentSyntax.GetLocation()); |
||||
|
} |
||||
|
|
||||
|
private static partial bool IsSimpleAssignmentNode(SyntaxNode node) |
||||
|
=> node.IsKind(SyntaxKind.SimpleAssignmentStatement); |
||||
|
|
||||
|
private static partial bool IsInvocationNode(SyntaxNode node) |
||||
|
=> node.IsKind(SyntaxKind.InvocationExpression); |
||||
|
} |
||||
@ -1,8 +0,0 @@ |
|||||
// This file is used by Code Analysis to maintain SuppressMessage
|
|
||||
// attributes that are applied to this project.
|
|
||||
// Project-level suppressions either have no target or are given
|
|
||||
// a specific target and scoped to a namespace, type, member, etc.
|
|
||||
|
|
||||
using System.Diagnostics.CodeAnalysis; |
|
||||
|
|
||||
[assembly: SuppressMessage("MicrosoftCodeAnalysisReleaseTracking", "RS2008:Enable analyzer release tracking")] |
|
||||
Loading…
Reference in new issue