Started placeholders for analyzers
This commit is contained in:
55
src/Discord.Net.Analyzers/ConfigureAwaitAnalyzer.cs
Normal file
55
src/Discord.Net.Analyzers/ConfigureAwaitAnalyzer.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
|
||||
namespace RegexAnalyzer
|
||||
{
|
||||
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
||||
public class ConfigureAwaitAnalyzer : DiagnosticAnalyzer
|
||||
{
|
||||
public const string DiagnosticId = "ConfigureAwait";
|
||||
internal const string Title = "ConfigureAwait was not specified";
|
||||
internal const string MessageFormat = "ConfigureAwait error {0}";
|
||||
internal const string Description = "ConfigureAwait(false) should be used.";
|
||||
internal const string Category = "Usage";
|
||||
internal static DiagnosticDescriptor Rule =
|
||||
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat,
|
||||
Category, DiagnosticSeverity.Error, isEnabledByDefault: true, description: Description);
|
||||
|
||||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(Rule);
|
||||
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.InvocationExpression);
|
||||
}
|
||||
|
||||
private void AnalyzeNode(SyntaxNodeAnalysisContext context)
|
||||
{
|
||||
/*var invocationExpr = (InvocationExpressionSyntax)context.Node;
|
||||
var memberAccessExpr = invocationExpr.Expression as MemberAccessExpressionSyntax;
|
||||
if (memberAccessExpr?.Name.ToString() != "Match") return;
|
||||
var memberSymbol = context.SemanticModel.GetSymbolInfo(memberAccessExpr).Symbol as IMethodSymbol;
|
||||
if (!memberSymbol?.ToString().StartsWith("System.Text.RegularExpressions.Regex.Match") ?? true) return;
|
||||
var argumentList = invocationExpr.ArgumentList as ArgumentListSyntax;
|
||||
if ((argumentList?.Arguments.Count ?? 0) < 2) return;
|
||||
var regexLiteral = argumentList.Arguments[1].Expression as LiteralExpressionSyntax;
|
||||
if (regexLiteral == null) return;
|
||||
var regexOpt = context.SemanticModel.GetConstantValue(regexLiteral);
|
||||
if (!regexOpt.HasValue) return;
|
||||
var regex = regexOpt.Value as string;
|
||||
if (regex == null) return;
|
||||
try
|
||||
{
|
||||
System.Text.RegularExpressions.Regex.Match("", regex);
|
||||
}
|
||||
catch (ArgumentException e)
|
||||
{
|
||||
var diagnostic = Diagnostic.Create(Rule, regexLiteral.GetLocation(), e.Message);
|
||||
context.ReportDiagnostic(diagnostic);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
32
src/Discord.Net.Analyzers/Discord.Net.Analyzers.csproj
Normal file
32
src/Discord.Net.Analyzers/Discord.Net.Analyzers.csproj
Normal file
@@ -0,0 +1,32 @@
|
||||
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VersionPrefix>1.0.0</VersionPrefix>
|
||||
<VersionSuffix Condition="'$(BuildNumber)' == ''">rc-dev</VersionSuffix>
|
||||
<VersionSuffix Condition="'$(BuildNumber)' != ''">rc-$(BuildNumber)</VersionSuffix>
|
||||
<TargetFrameworks>netstandard1.3</TargetFrameworks>
|
||||
<AssemblyName>Discord.Net.Analyzers</AssemblyName>
|
||||
<Authors>RogueException</Authors>
|
||||
<Description>A Discord.Net extension adding compile-time analysis.</Description>
|
||||
<PackageTags>discord;discordapp</PackageTags>
|
||||
<PackageProjectUrl>https://github.com/RogueException/Discord.Net</PackageProjectUrl>
|
||||
<PackageLicenseUrl>http://opensource.org/licenses/MIT</PackageLicenseUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<RepositoryUrl>git://github.com/RogueException/Discord.Net</RepositoryUrl>
|
||||
<RootNamespace>Discord.Analyzers</RootNamespace>
|
||||
<PackageTargetFallback>portable-net45+win81</PackageTargetFallback>
|
||||
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Discord.Net.Core\Discord.Net.Core.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.0.0-rc2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<NoWarn>$(NoWarn);CS1573;CS1591</NoWarn>
|
||||
<WarningsAsErrors>true</WarningsAsErrors>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user