Skip to content
Permalink
Browse files

Adopt latest roslyn analyzers (#40839)

  • Loading branch information
jcouv committed Jan 10, 2020
1 parent 31c2a01 commit e606428dbf4140e4d54fd3beca2d6a0b360a982d
Showing with 39 additions and 22 deletions.
  1. +3 −0 .editorconfig
  2. +1 −1 eng/Versions.props
  3. +1 −1 src/EditorFeatures/Core/Implementation/Classification/SemanticClassificationViewTaggerProvider.cs
  4. +1 −1 src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.cs
  5. +3 −2 src/EditorFeatures/TestUtilities/Threading/WpfFactDiscoverer.cs
  6. +1 −1 src/EditorFeatures/VisualBasicTest/KeywordHighlighting/AbstractVisualBasicKeywordHighlighterTests.vb
  7. +1 −1 src/Features/CSharp/Portable/ChangeSignature/CSharpChangeSignatureService.cs
  8. +2 −1 src/Features/VisualBasic/Portable/ChangeSignature/VisualBasicChangeSignatureService.vb
  9. +1 −1 ...ures/VisualBasic/Portable/Completion/KeywordRecommenders/Declarations/GetSetKeywordRecommender.vb
  10. +1 −1 ...asic/Portable/Completion/KeywordRecommenders/Declarations/ParameterModifiersKeywordRecommender.vb
  11. +2 −1 ...tures/VisualBasic/Portable/Completion/KeywordRecommenders/Expressions/LambdaKeywordRecommender.vb
  12. +2 −2 ...tures/VisualBasic/Portable/Completion/KeywordRecommenders/Expressions/NameOfKeywordRecommender.vb
  13. +2 −2 src/Features/VisualBasic/Portable/EditAndContinue/VisualBasicEditAndContinueAnalyzer.vb
  14. +4 −0 src/Test/Utilities/Portable/Diagnostics/CommonDiagnosticAnalyzers.cs
  15. +2 −0 src/Test/Utilities/Portable/Diagnostics/TestDiagnosticAnalyzer.cs
  16. +2 −1 src/VisualStudio/Core/SolutionExplorerShim/BaseItem.cs
  17. +3 −1 src/VisualStudio/Core/Test/AnalyzerSupport/AnalyzerDependencyCheckerTests.vb
  18. +2 −1 src/VisualStudio/LiveShare/Impl/Client/Debugging/CSharpLspPackage.cs
  19. +4 −3 src/VisualStudio/LiveShare/Impl/Client/Tagger/AbstractAsyncClassificationTaggerProvider.cs
  20. +1 −1 src/Workspaces/VisualBasic/Portable/LanguageServices/VisualBasicSemanticFactsService.vb
@@ -205,3 +205,6 @@ csharp_space_between_square_brackets = false
csharp_prefer_braces = true:silent
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true

# warning RS0037: PublicAPI.txt is missing '#nullable enable'
dotnet_diagnostic.RS0037.severity = none
@@ -27,7 +27,7 @@
</PropertyGroup>
<PropertyGroup>
<!-- Versions used by several individual references below -->
<RoslynDiagnosticsNugetPackageVersion>2.9.6</RoslynDiagnosticsNugetPackageVersion>
<RoslynDiagnosticsNugetPackageVersion>3.0.0-beta2.20059.3+77df2220</RoslynDiagnosticsNugetPackageVersion>
<CodeStyleLayerCodeAnalysisVersion>2.8.2</CodeStyleLayerCodeAnalysisVersion>
<MicrosoftCodeAnalysisTestingVersion>1.0.0-beta1-63310-01</MicrosoftCodeAnalysisTestingVersion>
<CodeStyleAnalyzerVersion>3.3.1-beta3-19454-05</CodeStyleAnalyzerVersion>
@@ -83,7 +83,7 @@ protected override IEnumerable<SnapshotSpan> GetSpansToTag(ITextView textView, I
return base.GetSpansToTag(textView, subjectBuffer);
}

return new[] { visibleSpanOpt.Value };
return SpecializedCollections.SingletonEnumerable(visibleSpanOpt.Value);
}

protected override Task ProduceTagsAsync(TaggerContext<IClassificationTag> context)
@@ -176,7 +176,7 @@ private void StoreTagSource(ITextView textViewOpt, ITextBuffer subjectBuffer, Ta
protected virtual IEnumerable<SnapshotSpan> GetSpansToTag(ITextView textViewOpt, ITextBuffer subjectBuffer)
{
// For a standard tagger, the spans to tag is the span of the entire snapshot.
return new[] { subjectBuffer.CurrentSnapshot.GetFullSpan() };
return SpecializedCollections.SingletonEnumerable(subjectBuffer.CurrentSnapshot.GetFullSpan());
}

/// <summary>
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using Roslyn.Utilities;
using Xunit.Abstractions;
using Xunit.Sdk;

@@ -31,13 +32,13 @@ public WpfTheoryDiscoverer(IMessageSink diagnosticMessageSink) : base(diagnostic
protected override IEnumerable<IXunitTestCase> CreateTestCasesForDataRow(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute, object[] dataRow)
{
var testCase = new WpfTestCase(_diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, dataRow);
return new[] { testCase };
return SpecializedCollections.SingletonEnumerable(testCase);
}

protected override IEnumerable<IXunitTestCase> CreateTestCasesForTheory(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute)
{
var testCase = new WpfTheoryTestCase(_diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod);
return new[] { testCase };
return SpecializedCollections.SingletonEnumerable(testCase);
}
}
}
@@ -10,7 +10,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.KeywordHighlightin
Inherits AbstractKeywordHighlighterTests

Protected Overrides Function GetOptions() As IEnumerable(Of ParseOptions)
Return {TestOptions.Regular}
Return SpecializedCollections.SingletonEnumerable(TestOptions.Regular)
End Function

Protected Overloads Function TestAsync(element As XElement) As Threading.Tasks.Task
@@ -674,7 +674,7 @@ private List<SyntaxTrivia> GetPermutedTrivia(CSharpSyntaxNode node, List<XmlElem

protected override IEnumerable<AbstractFormattingRule> GetFormattingRules(Document document)
{
return new[] { new ChangeSignatureFormattingRule() }.Concat(Formatter.GetDefaultFormattingRules(document));
return SpecializedCollections.SingletonEnumerable(new ChangeSignatureFormattingRule()).Concat(Formatter.GetDefaultFormattingRules(document));
}
}
}
@@ -604,7 +604,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ChangeSignature
End Function

Protected Overrides Function GetFormattingRules(document As Document) As IEnumerable(Of AbstractFormattingRule)
Return New AbstractFormattingRule() {New ChangeSignatureFormattingRule()}.Concat(Formatter.GetDefaultFormattingRules(document))
Return SpecializedCollections.SingletonEnumerable(Of AbstractFormattingRule)(New ChangeSignatureFormattingRule()).
Concat(Formatter.GetDefaultFormattingRules(document))
End Function
End Class
End Namespace
@@ -18,7 +18,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.KeywordRecommenders.Decl
' If we have modifiers which exclude it, then definitely not
Dim modifiers = context.ModifierCollectionFacts
If Not modifiers.CouldApplyToOneOf(PossibleDeclarationTypes.Accessor) Then
Return Enumerable.Empty(Of RecommendedKeyword)()
Return SpecializedCollections.EmptyEnumerable(Of RecommendedKeyword)()
End If

Dim targetToken = context.TargetToken
@@ -61,7 +61,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.KeywordRecommenders.Decl
' If a previous one had a ParamArray, then nothing is valid anymore, since the ParamArray must
' always be the last parameter
If parameter.Modifiers.Any(Function(modifier) modifier.Kind = SyntaxKind.ParamArrayKeyword) Then
Return Enumerable.Empty(Of RecommendedKeyword)()
Return SpecializedCollections.EmptyEnumerable(Of RecommendedKeyword)()
End If

' If a previous one had an Optional, then all following must be optional. Following Dev10 behavior,
@@ -22,7 +22,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.KeywordRecommenders.Expr
Dim targetToken = context.TargetToken
If context.SyntaxTree.IsExpressionContext(targetToken.SpanStart, cancellationToken, context.SemanticModel) Then
If targetToken.IsKindOrHasMatchingText(SyntaxKind.IteratorKeyword) Then
Return {New RecommendedKeyword("Function", VBFeaturesResources.Defines_a_lambda_expression_that_calculates_and_returns_a_single_value_Can_be_used_wherever_a_delegate_type_is_expected_Function_parameterList_expression)}
Return SpecializedCollections.SingletonEnumerable(
New RecommendedKeyword("Function", VBFeaturesResources.Defines_a_lambda_expression_that_calculates_and_returns_a_single_value_Can_be_used_wherever_a_delegate_type_is_expected_Function_parameterList_expression))
ElseIf targetToken.IsKindOrHasMatchingText(SyntaxKind.AsyncKeyword) Then
Return {New RecommendedKeyword("Function", VBFeaturesResources.Defines_a_lambda_expression_that_calculates_and_returns_a_single_value_Can_be_used_wherever_a_delegate_type_is_expected_Function_parameterList_expression),
New RecommendedKeyword("Sub", VBFeaturesResources.Defines_a_lambda_expression_that_can_execute_statements_and_does_not_return_a_value_Can_be_used_wherever_a_delegate_type_is_expected_Sub_parameterList_statement)}
@@ -11,13 +11,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.KeywordRecommenders.Expr

Protected Overrides Function RecommendKeywords(context As VisualBasicSyntaxContext, cancellationToken As CancellationToken) As IEnumerable(Of RecommendedKeyword)
If context.IsAnyExpressionContext Then
Return {CreateRecommendedKeywordForIntrinsicOperator(
Return SpecializedCollections.SingletonEnumerable(CreateRecommendedKeywordForIntrinsicOperator(
SyntaxKind.NameOfKeyword,
VBFeaturesResources.NameOf_function,
Glyph.MethodPublic,
New NameOfExpressionDocumentation(),
context.SemanticModel,
context.Position)}
context.Position))
End If

Return SpecializedCollections.EmptyEnumerable(Of RecommendedKeyword)()
@@ -271,12 +271,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.EditAndContinue
' Property: Attributes Modifiers [|Identifier$ Initializer|] ImplementsClause
Dim propertyStatement = DirectCast(node, PropertyStatementSyntax)
If propertyStatement.Initializer IsNot Nothing Then
Return {propertyStatement.Identifier}.Concat(If(propertyStatement.AsClause?.DescendantTokens(),
Return SpecializedCollections.SingletonEnumerable(propertyStatement.Identifier).Concat(If(propertyStatement.AsClause?.DescendantTokens(),
Array.Empty(Of SyntaxToken))).Concat(propertyStatement.Initializer.DescendantTokens())
End If

If HasAsNewClause(propertyStatement) Then
Return {propertyStatement.Identifier}.Concat(propertyStatement.AsClause.DescendantTokens())
Return SpecializedCollections.SingletonEnumerable(propertyStatement.Identifier).Concat(propertyStatement.AsClause.DescendantTokens())
End If

Return Nothing
@@ -572,7 +572,9 @@ public override void Initialize(AnalysisContext context)
public sealed class AnalyzerWithCSharpCompilerDiagnosticId : DiagnosticAnalyzer
{
public static readonly DiagnosticDescriptor Descriptor = new DiagnosticDescriptor(
#pragma warning disable RS1029 // Do not use reserved diagnostic IDs.
"CS101",
#pragma warning restore RS1029 // Do not use reserved diagnostic IDs.
"Title1",
"Message1",
"Category1",
@@ -591,7 +593,9 @@ public override void Initialize(AnalysisContext context)
public sealed class AnalyzerWithBasicCompilerDiagnosticId : DiagnosticAnalyzer
{
public static readonly DiagnosticDescriptor Descriptor = new DiagnosticDescriptor(
#pragma warning disable RS1029 // Do not use reserved diagnostic IDs.
"BC101",
#pragma warning restore RS1029 // Do not use reserved diagnostic IDs.
"Title1",
"Message1",
"Category1",
@@ -23,7 +23,9 @@ public abstract class TestDiagnosticAnalyzer<TLanguageKindEnum> : DiagnosticAnal
// protected static readonly ImmutableArray<string> AllAbstractMemberNames = ImmutableArray<string>.Empty.AddRange(GetAbstractMemberNames(typeof(CompilationStartAnalysisScope)).Distinct());

protected static readonly DiagnosticDescriptor DefaultDiagnostic =
#pragma warning disable RS1029 // Do not use reserved diagnostic IDs.
new DiagnosticDescriptor("CA7777", "CA7777_AnalyzerTestDiagnostic", "I'm here for test purposes", "Test", DiagnosticSeverity.Warning, isEnabledByDefault: true);
#pragma warning restore RS1029 // Do not use reserved diagnostic IDs.

private static ImmutableArray<T> GetAllEnumValues<T>()
{
@@ -9,6 +9,7 @@
using Microsoft.Internal.VisualStudio.PlatformUI;
using Microsoft.VisualStudio.Imaging.Interop;
using Microsoft.VisualStudio.Shell;
using Roslyn.Utilities;

namespace Microsoft.VisualStudio.LanguageServices.Implementation.SolutionExplorer
{
@@ -43,7 +44,7 @@ public IEnumerable<string> Children
{
get
{
return Enumerable.Empty<string>();
return SpecializedCollections.EmptyEnumerable<string>();
}
}

@@ -10,6 +10,7 @@ Imports Microsoft.CodeAnalysis.Test.Utilities
Imports Microsoft.VisualStudio.LanguageServices.Implementation
Imports Microsoft.Win32
Imports Roslyn.Test.Utilities
Imports Roslyn.Utilities

Namespace Microsoft.VisualStudio.LanguageServices.UnitTests
<[UseExportProvider]>
@@ -22,7 +23,8 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests
Dim mscorlib As AssemblyIdentity = Nothing
AssemblyIdentity.TryParseDisplayName(s_mscorlibDisplayName, mscorlib)

Return {New IgnorableAssemblyIdentityList({mscorlib})}
Return SpecializedCollections.SingletonEnumerable(
New IgnorableAssemblyIdentityList(SpecializedCollections.SingletonEnumerable(mscorlib)))
End Function

<Fact>
@@ -7,6 +7,7 @@
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Roslyn.Utilities;

namespace Microsoft.VisualStudio.LanguageServices.LiveShare.Client.Debugging
{
@@ -22,7 +23,7 @@ internal class CSharpLspPackage : AbstractPackage<CSharpLspPackage, CSharpLspLan

protected override IEnumerable<IVsEditorFactory> CreateEditorFactories()
{
return new IVsEditorFactory[] { };
return SpecializedCollections.EmptyEnumerable<IVsEditorFactory>();
}

protected override CSharpLspLanguageService CreateLanguageService() => new CSharpLspLanguageService(this);
@@ -11,6 +11,7 @@
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Tagging;
using Roslyn.Utilities;

namespace Microsoft.VisualStudio.LanguageServices.LiveShare.Client.Tagger
{
@@ -69,7 +70,7 @@ protected override IEnumerable<SnapshotSpan> GetSpansToTag(ITextView textView, I
if (textView == null)
{
var currentSnapshot = subjectBuffer.CurrentSnapshot;
return new[] { new SnapshotSpan(currentSnapshot, Span.FromBounds(0, currentSnapshot.Length)) };
return SpecializedCollections.SingletonEnumerable(new SnapshotSpan(currentSnapshot, Span.FromBounds(0, currentSnapshot.Length)));
}

// Determine the range of text that is visible in the view. Then map this down to our
@@ -86,7 +87,7 @@ protected override IEnumerable<SnapshotSpan> GetSpansToTag(ITextView textView, I
// are no visible spans in the buffer return the full snapshot.
// This can occur in an HTML file with script blocks when the user
// scrolls down and the script blocks are no longer visible in view.
return new[] { new SnapshotSpan(snapshot, 0, snapshot.Length) };
return SpecializedCollections.SingletonEnumerable(new SnapshotSpan(snapshot, 0, snapshot.Length));
}

var visibleStart = visibleSpansInBuffer.First().Start;
@@ -105,7 +106,7 @@ protected override IEnumerable<SnapshotSpan> GetSpansToTag(ITextView textView, I

var span = new SnapshotSpan(snapshot, Span.FromBounds(start, end));

return new[] { span };
return SpecializedCollections.SingletonEnumerable(span);
}
}
}
@@ -313,7 +313,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Select(Function(n) semanticModel.GetDeclaredSymbol(n, cancellationToken))
End If

Return {semanticModel.GetDeclaredSymbol(memberDeclaration, cancellationToken)}
Return SpecializedCollections.SingletonEnumerable(semanticModel.GetDeclaredSymbol(memberDeclaration, cancellationToken))
End Function

Public Function FindParameterForArgument(semanticModel As SemanticModel, argumentNode As SyntaxNode, cancellationToken As CancellationToken) As IParameterSymbol Implements ISemanticFactsService.FindParameterForArgument

0 comments on commit e606428

Please sign in to comment.
You can’t perform that action at this time.