Skip to content

Commit

Permalink
Merge pull request #108 from Vannevelj/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Vannevelj committed Jun 26, 2015
2 parents cf3fd8c + ff17533 commit bbd11a9
Show file tree
Hide file tree
Showing 63 changed files with 687 additions and 1,735 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ A collection of code-quality analyzers based on the new Roslyn platform. This pr

[Get it from NuGet!](https://www.nuget.org/packages/VSDiagnostics/)

[![Build status](https://ci.appveyor.com/api/projects/status/c5f15ckfb5wv91ma?svg=true)](https://ci.appveyor.com/project/Vannevelj/vsdiagnostics)
[![Test status](http://teststatusbadge.azurewebsites.net/api/status/Vannevelj/vsdiagnostics)](https://ci.appveyor.com/project/Vannevelj/vsdiagnostics)

Keep in mind that this project is under active development. If you encounter bugs, let us know!

## What is an analyzer exactly?

> With the release of Visual Studio 2015 RC, we also received the pretty much final implementation of the Diagnostics implementation. This SDK allows us to create our own diagnostics to help us write proper code that’s being verified against those rules in real-time: you don’t have to perform the verification at a separate build-step. What’s more is that we can combine that with a code fix: a shortcut integrated in Visual Studio that provides us a solution to what we determine to be a problem.
Expand Down Expand Up @@ -57,8 +62,4 @@ Definitely! Take a look at the open issues and see if there's anything that inte

If you think you're going to make larger changes than a single implementation then we would ask you to get in contact with us first so we can discuss it and prevent unneeded work.

You'll need the [Visual Studio 2015 Release Candidate](https://www.visualstudio.com/en-us/downloads/visual-studio-2015-downloads-vs.aspx) and [the SDK](https://www.microsoft.com/en-us/download/details.aspx?id=46850) to get started.

In order to build the project, make sure you add the Roslyn Nightly builds as a NuGet package source or it won't be able to pull the RC3 versions of packages we use.

https://www.myget.org/gallery/roslyn-nightly
You'll need the [Visual Studio 2015 Release Candidate](https://www.visualstudio.com/en-us/downloads/visual-studio-2015-downloads-vs.aspx) and [the SDK](https://www.microsoft.com/en-us/download/details.aspx?id=46850) to get started.
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RoslynTester.DiagnosticResults;
using RoslynTester.Helpers.CSharp;
using VSDiagnostics.Diagnostics.Async.AsyncMethodWithoutAsyncSuffix;
using VSDiagnostics.Diagnostics.Exceptions.EmptyArgumentException;

namespace VSDiagnostics.Test.Tests.Async
{
[TestClass]
public class AsyncMethodWithoutAsyncSuffixAnalyzerTests : CSharpCodeFixVerifier
{
protected override CodeFixProvider CodeFixProvider => new AsyncMethodWithoutAsyncSuffixCodeFix();

protected override DiagnosticAnalyzer DiagnosticAnalyzer => new AsyncMethodWithoutAsyncSuffixAnalyzer();

[TestMethod]
Expand Down Expand Up @@ -49,19 +48,7 @@ async Task MethodAsync()
}
}";

var expectedDiagnostic = new DiagnosticResult
{
Id = AsyncMethodWithoutAsyncSuffixAnalyzer.DiagnosticId,
Message = string.Format(AsyncMethodWithoutAsyncSuffixAnalyzer.Message, "Method"),
Severity = EmptyArgumentExceptionAnalyzer.Severity,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 10, 24)
}
};

VerifyDiagnostic(original, expectedDiagnostic);
VerifyDiagnostic(original, string.Format(AsyncMethodWithoutAsyncSuffixAnalyzer.Rule.MessageFormat.ToString(), "Method"));
VerifyFix(original, result);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RoslynTester.DiagnosticResults;
using RoslynTester.Helpers.CSharp;
using VSDiagnostics.Diagnostics.Exceptions.ArgumentExceptionWithNameofOperator;
using VSDiagnostics.Diagnostics.Exceptions.ArgumentExceptionWithoutNameofOperator;

namespace VSDiagnostics.Test.Tests.Exceptions
{
[TestClass]
public class ArgumentExceptionWithNameofOperatorAnalyzerTests : CSharpCodeFixVerifier
public class ArgumentExceptionWithoutNameofOperatorAnalyzerTests : CSharpCodeFixVerifier
{
protected override DiagnosticAnalyzer DiagnosticAnalyzer => new ArgumentExceptionWithNameofOperatorAnalyzer();
protected override CodeFixProvider CodeFixProvider => new ArgumentExceptionWithNameofOperatorCodeFix();
protected override DiagnosticAnalyzer DiagnosticAnalyzer => new ArgumentExceptionWithoutNameofOperatorAnalyzer();

protected override CodeFixProvider CodeFixProvider => new ArgumentExceptionWithoutNameofOperatorCodeFix();

[TestMethod]
public void ArgumentExceptionWithNameofOperatorAnalyzer_WithArgumentException_WithoutCorrespondingParameter_InvokesWarning()
public void ArgumentExceptionWithoutNameofOperatorAnalyzer_WithArgumentException_WithoutCorrespondingParameter_InvokesWarning()
{
var original = @"
using System;
Expand Down Expand Up @@ -46,24 +46,12 @@ void Method(string input)
}
}";

var expectedDiagnostic = new DiagnosticResult
{
Id = ArgumentExceptionWithNameofOperatorAnalyzer.DiagnosticId,
Message = string.Format(ArgumentExceptionWithNameofOperatorAnalyzer.Message, "input"),
Severity = ArgumentExceptionWithNameofOperatorAnalyzer.Severity,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 11, 45)
}
};

VerifyDiagnostic(original, expectedDiagnostic);
VerifyDiagnostic(original, string.Format(ArgumentExceptionWithoutNameofOperatorAnalyzer.Rule.MessageFormat.ToString(), "input"));
VerifyFix(original, result);
}

[TestMethod]
public void ArgumentExceptionWithNameofOperatorAnalyzer_WithArgumentException_WithoutCorrespondingParameterInDifferentCase_InvokesWarning()
public void ArgumentExceptionWithoutNameofOperatorAnalyzer_WithArgumentException_WithoutCorrespondingParameterInDifferentCase_InvokesWarning()
{
var original = @"
using System;
Expand Down Expand Up @@ -95,24 +83,12 @@ void Method(string input)
}
}";

var expectedDiagnostic = new DiagnosticResult
{
Id = ArgumentExceptionWithNameofOperatorAnalyzer.DiagnosticId,
Message = string.Format(ArgumentExceptionWithNameofOperatorAnalyzer.Message, "input"),
Severity = ArgumentExceptionWithNameofOperatorAnalyzer.Severity,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 11, 45)
}
};

VerifyDiagnostic(original, expectedDiagnostic);
VerifyDiagnostic(original, string.Format(ArgumentExceptionWithoutNameofOperatorAnalyzer.Rule.MessageFormat.ToString(), "input"));
VerifyFix(original, result);
}

[TestMethod]
public void ArgumentExceptionWithNameofOperatorAnalyzer_WithArgumentException_WithMultipleArguments_InvokesWarning()
public void ArgumentExceptionWithoutNameofOperatorAnalyzer_WithArgumentException_WithMultipleArguments_InvokesWarning()
{
var original = @"
using System;
Expand Down Expand Up @@ -144,24 +120,12 @@ void Method(string input)
}
}";

var expectedDiagnostic = new DiagnosticResult
{
Id = ArgumentExceptionWithNameofOperatorAnalyzer.DiagnosticId,
Message = string.Format(ArgumentExceptionWithNameofOperatorAnalyzer.Message, "input"),
Severity = ArgumentExceptionWithNameofOperatorAnalyzer.Severity,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 11, 45)
}
};

VerifyDiagnostic(original, expectedDiagnostic);
VerifyDiagnostic(original, string.Format(ArgumentExceptionWithoutNameofOperatorAnalyzer.Rule.MessageFormat.ToString(), "input"));
VerifyFix(original, result);
}

[TestMethod]
public void ArgumentExceptionWithNameofOperatorAnalyzer_WithArgumentException_WithMultipleParameters_AndCorrespondingParameter_InvokesWarning()
public void ArgumentExceptionWithoutNameofOperatorAnalyzer_WithArgumentException_WithMultipleParameters_AndCorrespondingParameter_InvokesWarning()
{
var original = @"
using System;
Expand Down Expand Up @@ -193,24 +157,12 @@ void Method(string input, int anotherInput)
}
}";

var expectedDiagnostic = new DiagnosticResult
{
Id = ArgumentExceptionWithNameofOperatorAnalyzer.DiagnosticId,
Message = string.Format(ArgumentExceptionWithNameofOperatorAnalyzer.Message, "input"),
Severity = ArgumentExceptionWithNameofOperatorAnalyzer.Severity,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 11, 45)
}
};

VerifyDiagnostic(original, expectedDiagnostic);
VerifyDiagnostic(original, string.Format(ArgumentExceptionWithoutNameofOperatorAnalyzer.Rule.MessageFormat.ToString(), "input"));
VerifyFix(original, result);
}

[TestMethod]
public void ArgumentExceptionWithNameofOperatorAnalyzer_WithArgumentNullException_WithCorrespondingParameterAsString_InvokesWarning()
public void ArgumentExceptionWithoutNameofOperatorAnalyzer_WithArgumentNullException_WithCorrespondingParameterAsString_InvokesWarning()
{
var original = @"
using System;
Expand Down Expand Up @@ -242,24 +194,12 @@ void Method(string input)
}
}";

var expectedDiagnostic = new DiagnosticResult
{
Id = ArgumentExceptionWithNameofOperatorAnalyzer.DiagnosticId,
Message = string.Format(ArgumentExceptionWithNameofOperatorAnalyzer.Message, "input"),
Severity = ArgumentExceptionWithNameofOperatorAnalyzer.Severity,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 11, 49)
}
};

VerifyDiagnostic(original, expectedDiagnostic);
VerifyDiagnostic(original, string.Format(ArgumentExceptionWithoutNameofOperatorAnalyzer.Rule.MessageFormat.ToString(), "input"));
VerifyFix(original, result);
}

[TestMethod]
public void ArgumentExceptionWithNameofOperatorAnalyzer_WithArgumentNullException_WithCorrespondingParameterAsNameOf_DoesNotInvokeWarning()
public void ArgumentExceptionWithoutNameofOperatorAnalyzer_WithArgumentNullException_WithCorrespondingParameterAsNameOf_DoesNotInvokeWarning()
{
var original = @"
using System;
Expand All @@ -280,7 +220,7 @@ void Method(string input)
}

[TestMethod]
public void ArgumentExceptionWithNameofOperatorAnalyzer_WithArgumentNullException_WithoutCorrespondingParameter_DoesNotInvokeWarning()
public void ArgumentExceptionWithoutNameofOperatorAnalyzer_WithArgumentNullException_WithoutCorrespondingParameter_DoesNotInvokeWarning()
{
var original = @"
using System;
Expand All @@ -301,7 +241,7 @@ void Method(string input)
}

[TestMethod]
public void ArgumentExceptionWithNameofOperatorAnalyzer_WithArgumentNullException_WithoutCorrespondingParameter_ButDefinedOutsideMethodScope_DoesNotInvokeWarning()
public void ArgumentExceptionWithoutNameofOperatorAnalyzer_WithArgumentNullException_WithoutCorrespondingParameter_ButDefinedOutsideMethodScope_DoesNotInvokeWarning()
{
var original = @"
using System;
Expand All @@ -324,7 +264,7 @@ void Method(string input)
}

[TestMethod]
public void ArgumentExceptionWithNameofOperatorAnalyzer_WithTwoOccurrences_InvokesTwoWarnings()
public void ArgumentExceptionWithoutNameofOperatorAnalyzer_WithTwoOccurrences_InvokesTwoWarnings()
{
var original = @"
using System;
Expand Down Expand Up @@ -364,36 +304,14 @@ void Method(string input, int otherInput)
}
}";

var expectedDiagnostic = new DiagnosticResult
{
Id = ArgumentExceptionWithNameofOperatorAnalyzer.DiagnosticId,
Message = string.Format(ArgumentExceptionWithNameofOperatorAnalyzer.Message, "input"),
Severity = ArgumentExceptionWithNameofOperatorAnalyzer.Severity,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 12, 45)
}
};

var secondExpectedDiagnostic = new DiagnosticResult
{
Id = ArgumentExceptionWithNameofOperatorAnalyzer.DiagnosticId,
Message = string.Format(ArgumentExceptionWithNameofOperatorAnalyzer.Message, "otherInput"),
Severity = ArgumentExceptionWithNameofOperatorAnalyzer.Severity,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 15, 45)
}
};

VerifyDiagnostic(original, expectedDiagnostic, secondExpectedDiagnostic);
VerifyDiagnostic(original,
string.Format(ArgumentExceptionWithoutNameofOperatorAnalyzer.Rule.MessageFormat.ToString(), "input"),
string.Format(ArgumentExceptionWithoutNameofOperatorAnalyzer.Rule.MessageFormat.ToString(), "otherInput"));
VerifyFix(original, result);
}

[TestMethod]
public void ArgumentExceptionWithNameofOperatorAnalyzer_WithArgumentException_WithIntType_InvokesWarning()
public void ArgumentExceptionWithoutNameofOperatorAnalyzer_WithArgumentException_WithIntType_InvokesWarning()
{
var original = @"
using System;
Expand Down Expand Up @@ -425,24 +343,12 @@ void Method(int input)
}
}";

var expectedDiagnostic = new DiagnosticResult
{
Id = ArgumentExceptionWithNameofOperatorAnalyzer.DiagnosticId,
Message = string.Format(ArgumentExceptionWithNameofOperatorAnalyzer.Message, "input"),
Severity = ArgumentExceptionWithNameofOperatorAnalyzer.Severity,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 11, 45)
}
};

VerifyDiagnostic(original, expectedDiagnostic);
VerifyDiagnostic(original, string.Format(ArgumentExceptionWithoutNameofOperatorAnalyzer.Rule.MessageFormat.ToString(), "input"));
VerifyFix(original, result);
}

[TestMethod]
public void ArgumentExceptionWithNameofOperatorAnalyzer_WithArgumentException_WithDefaultValue_InvokesWarning()
public void ArgumentExceptionWithoutNameofOperatorAnalyzer_WithArgumentException_WithDefaultValue_InvokesWarning()
{
var original = @"
using System;
Expand Down Expand Up @@ -474,19 +380,7 @@ void Method(double input = 5.7)
}
}";

var expectedDiagnostic = new DiagnosticResult
{
Id = ArgumentExceptionWithNameofOperatorAnalyzer.DiagnosticId,
Message = string.Format(ArgumentExceptionWithNameofOperatorAnalyzer.Message, "input"),
Severity = ArgumentExceptionWithNameofOperatorAnalyzer.Severity,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 11, 45)
}
};

VerifyDiagnostic(original, expectedDiagnostic);
VerifyDiagnostic(original, string.Format(ArgumentExceptionWithoutNameofOperatorAnalyzer.Rule.MessageFormat.ToString(), "input"));
VerifyFix(original, result);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RoslynTester.DiagnosticResults;
using RoslynTester.Helpers.CSharp;
using VSDiagnostics.Diagnostics.Exceptions.CatchNullReferenceException;

Expand Down Expand Up @@ -35,18 +34,7 @@ void Method(string input)
}
}";

var expectedDiagnostic = new DiagnosticResult
{
Id = CatchNullReferenceExceptionAnalyzer.DiagnosticId,
Message = CatchNullReferenceExceptionAnalyzer.Message,
Severity = CatchNullReferenceExceptionAnalyzer.Severity,
Locations = new[]
{
new DiagnosticResultLocation("Test0.cs", 14, 22)
}
};

VerifyDiagnostic(test, expectedDiagnostic);
VerifyDiagnostic(test, CatchNullReferenceExceptionAnalyzer.Rule.MessageFormat.ToString());
}

[TestMethod]
Expand Down
Loading

0 comments on commit bbd11a9

Please sign in to comment.