Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions StyleCop.Analyzers/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,14 @@
<PackageReference Include="AsyncUsageAnalyzers" Version="1.0.0-alpha003" PrivateAssets="all" />
<PackageReference Include="DotNetAnalyzers.DocumentationAnalyzers" Version="1.0.0-beta.46" PrivateAssets="all" />
<PackageReference Include="NewStyleCop.Analyzers" Version="1.2.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="5.3.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="4.0.1" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.ResxSourceGenerator" Version="$(SharedMicrosoftCodeAnalysisAnalyzersVersion)" PrivateAssets="all" />
</ItemGroup>

<!-- C# Compiler -->
<ItemGroup>
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="4.0.1" PrivateAssets="all" />
</ItemGroup>

<!-- Public API -->
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="$(SharedMicrosoftCodeAnalysisAnalyzersVersion)" PrivateAssets="all" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

<ItemGroup>
<PackageReference Include="LibGit2Sharp" Version="0.31.0" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.10.2" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="5.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="5.0.0" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.11.2" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="5.3.0" />
<!-- See https://github.com/microsoft/MSBuildLocator/issues/368 for the custom attributes on the next reference -->
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="5.3.0" ExcludeAssets="runtime" PrivateAssets="runtime" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace StyleCop.Analyzers.Test
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;
using Xunit;

public class AnalyzerConfigurationUnitTests
Expand Down Expand Up @@ -62,7 +61,7 @@ public void TestHelpLink(Type analyzerType)
}
}

private class CSharpTest : CodeFixTest<XUnitVerifier>
private class CSharpTest : CodeFixTest<DefaultVerifier>
{
private readonly Type analyzerType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="1.3.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="1.1.2-beta1.23509.1" />
<PackageReference Include="Microsoft.VisualStudio.Composition" Version="16.1.8" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" Version="1.1.3" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Xunit.Combinatorial" Version="1.6.24" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ namespace StyleCop.Analyzers.Test.Verifiers
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;

internal static class CustomDiagnosticVerifier<TAnalyzer>
where TAnalyzer : DiagnosticAnalyzer, new()
{
internal static DiagnosticResult Diagnostic()
=> CSharpCodeFixVerifier<TAnalyzer, EmptyCodeFixProvider, XUnitVerifier>.Diagnostic();
=> CSharpCodeFixVerifier<TAnalyzer, EmptyCodeFixProvider, DefaultVerifier>.Diagnostic();

internal static DiagnosticResult Diagnostic(string diagnosticId)
=> CSharpCodeFixVerifier<TAnalyzer, EmptyCodeFixProvider, XUnitVerifier>.Diagnostic(diagnosticId);
=> CSharpCodeFixVerifier<TAnalyzer, EmptyCodeFixProvider, DefaultVerifier>.Diagnostic(diagnosticId);

internal static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor)
=> new DiagnosticResult(descriptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ namespace StyleCop.Analyzers.Test.Verifiers
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;
using StyleCop.Analyzers.SpacingRules;
using Xunit;
using Xunit.Sdk;
using static StyleCopDiagnosticVerifier<StyleCop.Analyzers.SpacingRules.SA1002SemicolonsMustBeSpacedCorrectly>;

/// <summary>
Expand All @@ -38,7 +36,7 @@ void MethodName()
";

var expected = Diagnostic();
var ex = await Assert.ThrowsAnyAsync<XunitException>(
var ex = await Assert.ThrowsAsync<InvalidOperationException>(
async () =>
{
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
Expand Down Expand Up @@ -101,7 +99,7 @@ int PropertyName
// By failing to include a location, the verified thinks we're only trying to verify a project diagnostic.
DiagnosticResult expected = Diagnostic().WithArguments(string.Empty, "followed");

var ex = await Assert.ThrowsAnyAsync<XunitException>(
var ex = await Assert.ThrowsAsync<InvalidOperationException>(
async () =>
{
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
Expand All @@ -117,13 +115,9 @@ int PropertyName
+ $"Actual diagnostic:{Environment.NewLine}"
+ $" // /0/Test0.cs(7,33): warning SA1002: Semicolons should be followed by a space{Environment.NewLine}"
+ $"VerifyCS.Diagnostic().WithSpan(7, 33, 7, 34).WithArguments(\"\", \"followed\"),{Environment.NewLine}"
+ $"{Environment.NewLine}"
+ $"{Environment.NewLine}"
+ $"Assert.Equal() Failure{Environment.NewLine}"
+ $"Expected: None{Environment.NewLine}"
+ $"Actual: SourceFile(/0/Test0.cs[102..103))";
+ $"{Environment.NewLine}";

new XUnitVerifier().EqualOrDiff(expectedMessage, ex.Message);
new DefaultVerifier().EqualOrDiff(expectedMessage, ex.Message);
}

[Fact]
Expand All @@ -140,7 +134,7 @@ int PropertyName
}
";

var ex = await Assert.ThrowsAnyAsync<XunitException>(
var ex = await Assert.ThrowsAsync<InvalidOperationException>(
async () =>
{
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
Expand All @@ -162,10 +156,10 @@ void MethodName()
}
";

var ex = await Assert.ThrowsAnyAsync<XunitException>(
var ex = await Assert.ThrowsAsync<InvalidOperationException>(
async () =>
{
await CSharpCodeFixVerifier<ErrorThrowingAnalyzer, EmptyCodeFixProvider, XUnitVerifier>.VerifyAnalyzerAsync(testCode, DiagnosticResult.EmptyDiagnosticResults).ConfigureAwait(false);
await CSharpCodeFixVerifier<ErrorThrowingAnalyzer, EmptyCodeFixProvider, DefaultVerifier>.VerifyAnalyzerAsync(testCode, DiagnosticResult.EmptyDiagnosticResults).ConfigureAwait(false);
}).ConfigureAwait(false);
Assert.StartsWith($"Context: Diagnostics of test state{Environment.NewLine}Mismatch between number of diagnostics returned, expected \"0\" actual \"1\"", ex.Message);
Assert.Contains("error AD0001", ex.Message);
Expand All @@ -187,7 +181,7 @@ Int32 PropertyName

DiagnosticResult expected = Diagnostic().WithArguments(string.Empty, "followed").WithLocation(7, 33);

var ex = await Assert.ThrowsAnyAsync<XunitException>(
var ex = await Assert.ThrowsAsync<InvalidOperationException>(
async () =>
{
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
Expand All @@ -213,7 +207,7 @@ Int32 PropertyName

DiagnosticResult expected = Diagnostic().WithArguments(string.Empty, "followed").WithLocation(8, 33);

var ex = await Assert.ThrowsAnyAsync<XunitException>(
var ex = await Assert.ThrowsAsync<InvalidOperationException>(
async () =>
{
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
Expand All @@ -239,7 +233,7 @@ int PropertyName
var descriptor = new DiagnosticDescriptor("SA9999", "Title", "Message", "Category", DiagnosticSeverity.Warning, isEnabledByDefault: true);
DiagnosticResult expected = Diagnostic(descriptor).WithLocation(7, 33);

var ex = await Assert.ThrowsAnyAsync<XunitException>(
var ex = await Assert.ThrowsAsync<InvalidOperationException>(
async () =>
{
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
Expand All @@ -263,7 +257,7 @@ int PropertyName

DiagnosticResult expected = Diagnostic().WithLocation(7, 33).WithSeverity(DiagnosticSeverity.Error);

var ex = await Assert.ThrowsAnyAsync<XunitException>(
var ex = await Assert.ThrowsAsync<InvalidOperationException>(
async () =>
{
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
Expand All @@ -287,7 +281,7 @@ int PropertyName

DiagnosticResult expected = Diagnostic().WithArguments(string.Empty, "followed").WithLocation(8, 33);

var ex = await Assert.ThrowsAnyAsync<XunitException>(
var ex = await Assert.ThrowsAsync<InvalidOperationException>(
async () =>
{
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
Expand Down Expand Up @@ -316,7 +310,7 @@ int PropertyName
Diagnostic().WithArguments(string.Empty, "followed").WithLocation(7, 34),
};

var ex = await Assert.ThrowsAnyAsync<XunitException>(
var ex = await Assert.ThrowsAsync<InvalidOperationException>(
async () =>
{
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
Expand All @@ -340,7 +334,7 @@ int PropertyName

DiagnosticResult expected = Diagnostic().WithArguments(string.Empty, "followed").WithLocation(7, 34);

var ex = await Assert.ThrowsAnyAsync<XunitException>(
var ex = await Assert.ThrowsAsync<InvalidOperationException>(
async () =>
{
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
Expand All @@ -364,7 +358,7 @@ int PropertyName

DiagnosticResult expected = Diagnostic().WithArguments(string.Empty, "followed").WithSpan(7, 33, 7, 35);

var ex = await Assert.ThrowsAnyAsync<XunitException>(
var ex = await Assert.ThrowsAsync<InvalidOperationException>(
async () =>
{
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
Expand All @@ -388,7 +382,7 @@ int PropertyName

DiagnosticResult expected = Diagnostic().WithArguments(string.Empty, "bogus argument").WithLocation(7, 33);

var ex = await Assert.ThrowsAnyAsync<XunitException>(
var ex = await Assert.ThrowsAsync<InvalidOperationException>(
async () =>
{
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
Expand All @@ -412,7 +406,7 @@ int PropertyName

DiagnosticResult expected = Diagnostic().WithArguments(string.Empty, "bogus argument").WithLocation(7, 33).WithLocation(8, 34);

var ex = await Assert.ThrowsAnyAsync<XunitException>(
var ex = await Assert.ThrowsAsync<InvalidOperationException>(
async () =>
{
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ namespace StyleCop.Analyzers.Test.Verifiers
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;
using Microsoft.CodeAnalysis.Text;
using StyleCop.Analyzers.Lightup;
using StyleCop.Analyzers.Settings.ObjectModel;
Expand All @@ -33,10 +32,10 @@ internal static class StyleCopCodeFixVerifier<TAnalyzer, TCodeFix>
where TCodeFix : CodeFixProvider, new()
{
internal static DiagnosticResult Diagnostic()
=> CSharpCodeFixVerifier<TAnalyzer, TCodeFix, XUnitVerifier>.Diagnostic();
=> CSharpCodeFixVerifier<TAnalyzer, TCodeFix, DefaultVerifier>.Diagnostic();

internal static DiagnosticResult Diagnostic(string diagnosticId)
=> CSharpCodeFixVerifier<TAnalyzer, TCodeFix, XUnitVerifier>.Diagnostic(diagnosticId);
=> CSharpCodeFixVerifier<TAnalyzer, TCodeFix, DefaultVerifier>.Diagnostic(diagnosticId);

internal static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor)
=> new DiagnosticResult(descriptor);
Expand Down Expand Up @@ -96,7 +95,7 @@ internal static Task VerifyCSharpFixAsync(LanguageVersion? languageVersion, stri
return test.RunAsync(cancellationToken);
}

internal class CSharpTest : CSharpCodeFixTest<TAnalyzer, TCodeFix, XUnitVerifier>
internal class CSharpTest : CSharpCodeFixTest<TAnalyzer, TCodeFix, DefaultVerifier>
{
private const int DefaultIndentationSize = 4;
private const int DefaultTabSize = 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ namespace StyleCop.Analyzers.Test.Verifiers
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;
using StyleCop.Analyzers.Lightup;

internal static class StyleCopDiagnosticVerifier<TAnalyzer>
where TAnalyzer : DiagnosticAnalyzer, new()
{
internal static DiagnosticResult Diagnostic()
=> CSharpCodeFixVerifier<TAnalyzer, EmptyCodeFixProvider, XUnitVerifier>.Diagnostic();
=> CSharpCodeFixVerifier<TAnalyzer, EmptyCodeFixProvider, DefaultVerifier>.Diagnostic();

internal static DiagnosticResult Diagnostic(string diagnosticId)
=> CSharpCodeFixVerifier<TAnalyzer, EmptyCodeFixProvider, XUnitVerifier>.Diagnostic(diagnosticId);
=> CSharpCodeFixVerifier<TAnalyzer, EmptyCodeFixProvider, DefaultVerifier>.Diagnostic(diagnosticId);

internal static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor)
=> new DiagnosticResult(descriptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ private IAddressOfOperationWrapper(IOperation operation)
public IOperation WrappedOperation => this.operation;
public ITypeSymbol Type => this.WrappedOperation.Type;
public IOperation Reference => ReferenceAccessor(this.WrappedOperation);

public static explicit operator IAddressOfOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(IAddressOfOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static IAddressOfOperationWrapper FromOperation(IOperation operation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ private IAnonymousFunctionOperationWrapper(IOperation operation)
public ITypeSymbol Type => this.WrappedOperation.Type;
public IMethodSymbol Symbol => SymbolAccessor(this.WrappedOperation);
public IBlockOperationWrapper Body => IBlockOperationWrapper.FromOperation(BodyAccessor(this.WrappedOperation));

public static explicit operator IAnonymousFunctionOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(IAnonymousFunctionOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static IAnonymousFunctionOperationWrapper FromOperation(IOperation operation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ private IAnonymousObjectCreationOperationWrapper(IOperation operation)
public IOperation WrappedOperation => this.operation;
public ITypeSymbol Type => this.WrappedOperation.Type;
public ImmutableArray<IOperation> Initializers => InitializersAccessor(this.WrappedOperation);

public static explicit operator IAnonymousObjectCreationOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(IAnonymousObjectCreationOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static IAnonymousObjectCreationOperationWrapper FromOperation(IOperation operation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private IArgumentOperationWrapper(IOperation operation)
public IOperation Value => ValueAccessor(this.WrappedOperation);
public object InConversion => throw new NotImplementedException("Property 'IArgumentOperation.InConversion' has unsupported type 'CommonConversion'");
public object OutConversion => throw new NotImplementedException("Property 'IArgumentOperation.OutConversion' has unsupported type 'CommonConversion'");

public static explicit operator IArgumentOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(IArgumentOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static IArgumentOperationWrapper FromOperation(IOperation operation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ private IArrayCreationOperationWrapper(IOperation operation)
public ITypeSymbol Type => this.WrappedOperation.Type;
public ImmutableArray<IOperation> DimensionSizes => DimensionSizesAccessor(this.WrappedOperation);
public IArrayInitializerOperationWrapper Initializer => IArrayInitializerOperationWrapper.FromOperation(InitializerAccessor(this.WrappedOperation));

public static explicit operator IArrayCreationOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(IArrayCreationOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static IArrayCreationOperationWrapper FromOperation(IOperation operation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ private IArrayElementReferenceOperationWrapper(IOperation operation)
public ITypeSymbol Type => this.WrappedOperation.Type;
public IOperation ArrayReference => ArrayReferenceAccessor(this.WrappedOperation);
public ImmutableArray<IOperation> Indices => IndicesAccessor(this.WrappedOperation);

public static explicit operator IArrayElementReferenceOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(IArrayElementReferenceOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static IArrayElementReferenceOperationWrapper FromOperation(IOperation operation)
Expand Down
Loading