Skip to content

Commit

Permalink
0.1.0-pre8
Browse files Browse the repository at this point in the history
  • Loading branch information
Happypig375 committed Aug 26, 2018
1 parent ab4da5b commit 427b061
Show file tree
Hide file tree
Showing 18 changed files with 87 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using TestHelper;
using CSharpMath.Analyzers;

namespace CSharpMath.Analyzers.Test {
[TestClass]
public class UnitTest : CodeFixVerifier {
public class CSM001InvariantToStringUnitTest : CodeFixVerifier {

//No diagnostics expected to show up
[TestMethod]
Expand All @@ -31,22 +30,18 @@ public void TestMethod2() {
namespace ConsoleApplication1
{
public static class Extensions {
public string ToStringInvariant(this int i) =>
i.ToString(null, System.Globalization.InvariantCulture);
}
class TypeName
{
public string Return() => 123.ToString();
}
}";
var expected = new DiagnosticResult {
Id = "CSM01",
Id = "CSM001",
Message = String.Format("A culture-invariant ToString() is available"),
Severity = DiagnosticSeverity.Warning,
Locations =
new[] {
new DiagnosticResultLocation("Test0.cs", 17, 39)
new DiagnosticResultLocation("Test0.cs", 13, 51)
}
};

Expand All @@ -62,24 +57,53 @@ class TypeName
namespace ConsoleApplication1
{
public static class Extensions {
public string ToStringInvariant(this int i) =>
i.ToString(null, System.Globalization.InvariantCulture);
class TypeName
{
public string Return() => 123.ToString(null, System.Globalization.CultureInfo.InvariantCulture);
}
}";
VerifyCSharpFix(test, fixtest);
}

[TestMethod]
public void TestMethod3() {
var test = @"
namespace ConsoleApplication1
{
class TypeName
{
public string Return() => int.Parse(""123"").ToString();
}
}";
var expected = new DiagnosticResult {
Id = "CSM001",
Message = String.Format("A culture-invariant ToString() is available"),
Severity = DiagnosticSeverity.Warning,
Locations =
new[] {
new DiagnosticResultLocation("Test0.cs", 6, 64)
}
};
VerifyCSharpDiagnostic(test, expected);


var fixtest = @"
namespace ConsoleApplication1
{
class TypeName
{
public string Return() => 123.ToStringInvariant();
public string Return() => int.Parse(""123"").ToString(null, System.Globalization.CultureInfo.InvariantCulture);
}
}";
VerifyCSharpFix(test, fixtest);
}

protected override CodeFixProvider GetCSharpCodeFixProvider() {
return new InvariantToStringCodeFixProvider();
return new CSM001InvariantToStringCodeFixProvider();
}

protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer() {
return new InvariantToStringAnalyzer();
return new CSM001InvariantToStringAnalyzer();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="2.6.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.9.0-beta4-63006-05" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

namespace CSharpMath.Analyzers {
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class InvariantToStringAnalyzer : DiagnosticAnalyzer {
public const string DiagnosticId = "CSM01";
public class CSM001InvariantToStringAnalyzer : DiagnosticAnalyzer {
public const string DiagnosticId = "CSM001";

// You can change these strings in the Resources.resx file. If you do not want your analyzer to be localize-able, you can use regular strings for Title and MessageFormat.
// See https://github.com/dotnet/roslyn/blob/master/docs/analyzers/Localizing%20Analyzers.md for more on localization
Expand All @@ -34,15 +34,15 @@ private static void AnalyzeSyntax(SyntaxNodeAnalysisContext context) {
var semanticModel = context.SemanticModel;
// TODO: Replace the following code with your own analysis, generating Diagnostic objects for any issues you find
var invocationSyntax = (InvocationExpressionSyntax)context.Node;
var accessSyntax = (MemberAccessExpressionSyntax)invocationSyntax.Expression;

var iformattable = context.Compilation.GetTypeByMetadataName(typeof(IFormattable).FullName);
// Find just those named type symbols with names containing lowercase letters.
if (accessSyntax.Name.Identifier.ValueText == nameof(IFormattable.ToString) &&
semanticModel.GetTypeInfo(accessSyntax.Expression).Type.Interfaces.Contains(iformattable) &&
invocationSyntax.ArgumentList.Arguments.Count == 0) {
if (invocationSyntax.Expression is MemberAccessExpressionSyntax accessSyntax &&
accessSyntax.Name.Identifier.ValueText == nameof(IFormattable.ToString) &&
semanticModel.GetTypeInfo(accessSyntax.Expression).Type.Interfaces.Contains(iformattable) &&
invocationSyntax.ArgumentList.Arguments.Count == 0) {
// For all such symbols, produce a diagnostic.
var diagnostic = Diagnostic.Create(Rule, invocationSyntax.GetLocation());
var diagnostic = Diagnostic.Create(Rule, invocationSyntax.ArgumentList.GetLocation());

context.ReportDiagnostic(diagnostic);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
using Microsoft.CodeAnalysis.Text;

namespace CSharpMath.Analyzers {
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(InvariantToStringCodeFixProvider)), Shared]
public class InvariantToStringCodeFixProvider : CodeFixProvider {
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(CSM001InvariantToStringCodeFixProvider)), Shared]
public class CSM001InvariantToStringCodeFixProvider : CodeFixProvider {
private const string title = "Replace culture-sensitive ToString() with an culture-invariant one";

public sealed override ImmutableArray<string> FixableDiagnosticIds {
get { return ImmutableArray.Create(InvariantToStringAnalyzer.DiagnosticId); }
get { return ImmutableArray.Create(CSM001InvariantToStringAnalyzer.DiagnosticId); }
}

public sealed override FixAllProvider GetFixAllProvider() {
Expand All @@ -35,7 +35,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
var diagnosticSpan = diagnostic.Location.SourceSpan;

// Find the type declaration identified by the diagnostic.
var declaration = root.FindToken(diagnosticSpan.Start).Parent.AncestorsAndSelf().OfType<InvocationExpressionSyntax>().First();
var declaration = root.FindToken(diagnosticSpan.Start).Parent.AncestorsAndSelf().OfType<ArgumentListSyntax>().First();

// Register a code action that will invoke the fix.
context.RegisterCodeFix(
Expand All @@ -46,17 +46,14 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
diagnostic);
}

private async Task<Solution> ReplaceMethodCallAsync(Document document, InvocationExpressionSyntax invocation, CancellationToken cancellationToken) {
// Compute new uppercase name.
var memberAccess = (MemberAccessExpressionSyntax)invocation.Expression;

private async Task<Solution> ReplaceMethodCallAsync(Document document, ArgumentListSyntax invocation, CancellationToken cancellationToken) {
// Get the symbol representing the type to be renamed.
var semanticModel = await document.GetSemanticModelAsync(cancellationToken);

// Produce a new solution that has all references to that type renamed, including the declaration.
var originalSolution = document.Project.Solution;
var optionSet = originalSolution.Workspace.Options;
document = document.WithSyntaxRoot(new Rewriter(memberAccess).Visit(await document.GetSyntaxRootAsync()));
document = document.WithSyntaxRoot(new Rewriter(invocation).Visit(await document.GetSyntaxRootAsync()));
var newSolution = document.Project.Solution;
//var newSolution = await Renamer.RenameSymbolAsync(document.Project.Solution, null, newName, optionSet, cancellationToken).ConfigureAwait(false);

Expand All @@ -65,11 +62,13 @@ private async Task<Solution> ReplaceMethodCallAsync(Document document, Invocatio
}

class Rewriter : CSharpSyntaxRewriter {
public Rewriter(MemberAccessExpressionSyntax replaceNode) =>
public Rewriter(ArgumentListSyntax replaceNode) =>
_replaceNode = replaceNode;
MemberAccessExpressionSyntax _replaceNode;
public override SyntaxNode VisitMemberAccessExpression(MemberAccessExpressionSyntax node) {
return node == _replaceNode ? node.WithName(node.Name.WithIdentifier(SyntaxFactory.Identifier("ToStringInvariant"))) : node;
readonly ArgumentListSyntax _replaceNode;
public override SyntaxNode VisitArgumentList(ArgumentListSyntax node) {
return node.IsEquivalentTo(_replaceNode) ?
SyntaxFactory.ParseArgumentList("(null, System.Globalization.CultureInfo.InvariantCulture)")
: node;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="2.6.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.9.0-beta4-63006-05" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.9.0" PrivateAssets="all" />
<PackageReference Update="NETStandard.Library" PrivateAssets="all" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="3.1.0.637273" />
<PackageReference Include="Xamarin.Forms" Version="3.1.0.697729" />
<PackageReference Include="Xamarin.Android.Support.Design" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="27.0.2.1" />
<PackageReference Include="Xamarin.Android.Support.v4" Version="27.0.2.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
</Page>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="3.1.0.637273" />
<PackageReference Include="Xamarin.Forms" Version="3.1.0.697729" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.1.5</Version>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
<Reference Include="Xamarin.iOS" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="3.1.0.637273" />
<PackageReference Include="Xamarin.Forms" Version="3.1.0.697729" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="3.1.0.637273" />
<PackageReference Include="Xamarin.Forms" Version="3.1.0.697729" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions CSharpMath.Forms/CSharpMath.Forms.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild>
<PackageVersion>0.1.0-pre7</PackageVersion>
<PackageVersion>0.1.0-pre8</PackageVersion>
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie, FoggyFinder)</Authors>
<PackageReleaseNotes>The 0.1.0 SkiaSharp Update brings the SkiaSharp and Xamarin.Forms front ends to CSharpMath.</PackageReleaseNotes>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/verybadcat/CSharpMath.git</RepositoryUrl>
<RepositoryBranch>master</RepositoryBranch>
<RepositoryCommit>e4d0b8d5b7c2ac29cde1bcc0438b5bf2298691c8</RepositoryCommit>
<RepositoryCommit>ab4da5b730a4cbd5667a66f6af33ccd3ce136fae</RepositoryCommit>
<PackageProjectUrl>https://github.com/verybadcat/CSharpMath</PackageProjectUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageLicenseUrl>https://github.com/verybadcat/CSharpMath/blob/master/LICENSE</PackageLicenseUrl>
Expand All @@ -25,8 +25,8 @@
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SkiaSharp.Views.Forms" Version="1.60.2" />
<PackageReference Include="Xamarin.Forms" Version="3.1.0.637273" />
<PackageReference Include="SkiaSharp.Views.Forms" Version="1.60.3" />
<PackageReference Include="Xamarin.Forms" Version="3.1.0.697729" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CSharpMath.SkiaSharp\CSharpMath.SkiaSharp.csproj" />
Expand Down
4 changes: 2 additions & 2 deletions CSharpMath.Ios/CSharpMath.Ios.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<NuGetPackageImportStamp></NuGetPackageImportStamp>
<PackOnBuild>true</PackOnBuild>
<PackageId>CSharpMath.Ios</PackageId>
<PackageVersion>0.1.0-pre7</PackageVersion>
<PackageVersion>0.1.0-pre8</PackageVersion>
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie, FoggyFinder)</Authors>
<NeutralLanguage>en</NeutralLanguage>
<PackageLicenseUrl>https://github.com/verybadcat/CSharpMath/blob/master/LICENSE</PackageLicenseUrl>
Expand All @@ -28,7 +28,7 @@
<RepositoryUrl>https://github.com/verybadcat/CSharpMath.git</RepositoryUrl>
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild>
<RepositoryBranch>master</RepositoryBranch>
<RepositoryCommit>e4d0b8d5b7c2ac29cde1bcc0438b5bf2298691c8</RepositoryCommit>
<RepositoryCommit>ab4da5b730a4cbd5667a66f6af33ccd3ce136fae</RepositoryCommit>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageIconUrl>https://raw.githubusercontent.com/verybadcat/CSharpMath/master/Icon.png</PackageIconUrl>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
</Page>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="3.1.0.637273" />
<PackageReference Include="Xamarin.Forms" Version="3.1.0.697729" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.1.5" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CSharpMath.Forms" Version="0.1.0-pre2" />
<PackageReference Include="CSharpMath.Rendering" Version="0.1.0-pre2" />
<PackageReference Include="CSharpMath.SkiaSharp" Version="0.1.0-pre2" />
<PackageReference Include="Xamarin.Forms" Version="3.1.0.637273" />
<PackageReference Include="CSharpMath.Forms" Version="0.1.0-pre7" />
<PackageReference Include="Xamarin.Forms" Version="3.1.0.697729" />
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions CSharpMath.Rendering/CSharpMath.Rendering.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.3</TargetFramework>
<LangVersion>latest</LangVersion>
Expand All @@ -11,7 +11,7 @@
<!--NuGet Properties-->
<PackOnBuild>true</PackOnBuild>
<PackageId>CSharpMath.Rendering</PackageId>
<PackageVersion>0.1.0-pre7</PackageVersion>
<PackageVersion>0.1.0-pre8</PackageVersion>
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie, FoggyFinder)</Authors>
<PackageLicenseUrl>https://github.com/verybadcat/CSharpMath/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/verybadcat/CSharpMath</PackageProjectUrl>
Expand All @@ -24,7 +24,7 @@
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild>
<RepositoryUrl>https://github.com/verybadcat/CSharpMath.git</RepositoryUrl>
<RepositoryBranch>master</RepositoryBranch>
<RepositoryCommit>e4d0b8d5b7c2ac29cde1bcc0438b5bf2298691c8</RepositoryCommit>
<RepositoryCommit>ab4da5b730a4cbd5667a66f6af33ccd3ce136fae</RepositoryCommit>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageIconUrl>https://raw.githubusercontent.com/verybadcat/CSharpMath/master/Icon.png</PackageIconUrl>
</PropertyGroup>
Expand Down
8 changes: 4 additions & 4 deletions CSharpMath.SkiaSharp/CSharpMath.SkiaSharp.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.3</TargetFramework>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild>
<PackageVersion>0.1.0-pre7</PackageVersion>
<PackageVersion>0.1.0-pre8</PackageVersion>
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie, FoggyFinder)</Authors>
<PackageReleaseNotes>The 0.1.0 SkiaSharp Update brings the SkiaSharp and Xamarin.Forms front ends to CSharpMath.</PackageReleaseNotes>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/verybadcat/CSharpMath.git</RepositoryUrl>
<RepositoryBranch>master</RepositoryBranch>
<RepositoryCommit>e4d0b8d5b7c2ac29cde1bcc0438b5bf2298691c8</RepositoryCommit>
<RepositoryCommit>ab4da5b730a4cbd5667a66f6af33ccd3ce136fae</RepositoryCommit>
<PackageProjectUrl>https://github.com/verybadcat/CSharpMath</PackageProjectUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageLicenseUrl>https://github.com/verybadcat/CSharpMath/blob/master/LICENSE</PackageLicenseUrl>
Expand All @@ -30,7 +30,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SkiaSharp" Version="1.60.2" />
<PackageReference Include="SkiaSharp" Version="1.60.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CSharpMath.Rendering\CSharpMath.Rendering.csproj" />
Expand Down
4 changes: 2 additions & 2 deletions CSharpMath.Utils.NuGet/ReleaseData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<ReleaseData>
<_Global->
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild>
<PackageVersion>0.1.0-pre7</PackageVersion>
<PackageVersion>0.1.0-pre8</PackageVersion>
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie, FoggyFinder)</Authors>
<PackageReleaseNotes>The 0.1.0 SkiaSharp Update brings the SkiaSharp and Xamarin.Forms front ends to CSharpMath.</PackageReleaseNotes>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/verybadcat/CSharpMath.git</RepositoryUrl>
<RepositoryBranch>master</RepositoryBranch>
<RepositoryCommit>e4d0b8d5b7c2ac29cde1bcc0438b5bf2298691c8</RepositoryCommit>
<RepositoryCommit>ab4da5b730a4cbd5667a66f6af33ccd3ce136fae</RepositoryCommit>
<PackageProjectUrl>https://github.com/verybadcat/CSharpMath</PackageProjectUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageLicenseUrl>https://github.com/verybadcat/CSharpMath/blob/master/LICENSE</PackageLicenseUrl>
Expand Down
Loading

0 comments on commit 427b061

Please sign in to comment.