Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c2bcedc
Add test
Jul 2, 2020
8ab723a
Fix VB case correction for named tuple identifiers
Jul 2, 2020
fe474f1
fix namespace
Jul 2, 2020
bcfd23f
fix tests
Jul 2, 2020
78b6af1
replace GetAncestor by TryCast of Parent
Jul 3, 2020
ed639d3
Merge pull request #1 from dotnet/master
hartmair Jul 7, 2020
ae7036e
Merge pull request #2 from dotnet/roslyn/master
hartmair Jul 7, 2020
d38fafd
Merge pull request #3 from dotnet/roslyn/master
hartmair Jul 8, 2020
7edd0b6
Extend code style enforcement for existing rules in EditorFeatures layer
mavasani Jul 8, 2020
d626be1
Fix CA1822 (Make static) violations with iterative FixAll application
mavasani Jul 8, 2020
466cb11
Enforce few more rules
mavasani Jul 8, 2020
18e452b
Fix IDE0036 and IDE0040 violations with FixAll applications
mavasani Jul 8, 2020
5afba04
Enable few more rules
mavasani Jul 8, 2020
e1a6e33
Fix IDE0044 (Make Field Readonly) violations with FixAll operation
mavasani Jul 8, 2020
9564352
Enable and fix IDE0051 (unused private members) and IDE0052 (unread p…
mavasani Jul 8, 2020
c54743b
Enable and fix IDE0059 violations (Unnecessary assignment to a value)
mavasani Jul 9, 2020
883ffdb
Enable and fix IDE0007 violations (Prefer "var")
mavasani Jul 9, 2020
6e0b677
Enable and fix IDE0060 (Remove unused parameters)
mavasani Jul 9, 2020
514bb2e
Merge editorconfig sections for EditorFeatures layer
mavasani Jul 9, 2020
c44e351
Fixes
mavasani Jul 9, 2020
ad5582a
Test fixes
mavasani Jul 9, 2020
c7c337a
Fix/suppress release build violations
mavasani Jul 9, 2020
26a4962
Address feedback
mavasani Jul 10, 2020
c7c9150
Address feedback and add issues for all TODOs for suppressions that a…
mavasani Jul 10, 2020
36ebc6b
Merge remote-tracking branch 'upstream/master' into CodeStyleEnforcement
mavasani Jul 10, 2020
4ce82b4
Merge remote-tracking branch 'upstream/master' into CodeStyleEnforcement
mavasani Jul 10, 2020
63f236d
Remove experimental feed
dibarbet Jul 10, 2020
918f670
Merge pull request #45847 from mavasani/CodeStyleEnforcement
Jul 11, 2020
21803cb
Merge pull request #45614 from hartmair/master
CyrusNajmabadi Jul 11, 2020
4153950
Use TestHost consistently (#45861)
tmat Jul 11, 2020
fc2f4b5
Merge pull request #45899 from dibarbet/remove_exp_feed
dibarbet Jul 11, 2020
c0b0187
Update wrong error code in test comments (#45917)
Youssef1313 Jul 12, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 3 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ dotnet_diagnostic.RS0037.severity = none
# warning RS0005: Do not use generic CodeAction.Create to create CodeAction
dotnet_diagnostic.RS0005.severity = none

[src/{Analyzers,CodeStyle,Features,Workspaces}/**/*.{cs,vb}]
[src/{Analyzers,CodeStyle,Features,Workspaces,EditorFeatures}/**/*.{cs,vb}]

# IDE0011: Add braces
csharp_prefer_braces = when_multiline:warning
# NOTE: We need the below severity entry for Add Braces due to https://github.com/dotnet/roslyn/issues/44201
Expand Down Expand Up @@ -266,4 +267,4 @@ dotnet_diagnostic.CA1822.severity = warning
dotnet_diagnostic.IDE0007.severity = warning
csharp_style_var_for_built_in_types = true:warning
csharp_style_var_when_type_is_apparent = true:warning
csharp_style_var_elsewhere = true:warning
csharp_style_var_elsewhere = true:warning
2 changes: 0 additions & 2 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
<add key="dotnet5" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<!-- Microsoft.VisualStudio.* packages (e.g. Microsoft.VisualStudio.LanguageServer.Protocol.Extensions): https://github.com/dotnet/roslyn/issues/43242 -->
<add key="experimental-vs-packages" value="https://dotnet.myget.org/F/experimental-vs-packages/api/v3/index.json" />
<!-- Microsoft.CodeAnalysis.Test.Resource.Proprietary -->
<add key="roslyn-tools" value="https://dotnet.myget.org/F/roslyn-tools/api/v3/index.json" />
<add key="roslyn-analyzers" value="https://dotnet.myget.org/F/roslyn-analyzers/api/v3/index.json" />
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<CodeStyleAnalyzerVersion>3.7.0-3.20271.4</CodeStyleAnalyzerVersion>
<VisualStudioEditorPackagesVersion>16.4.248</VisualStudioEditorPackagesVersion>
<ILToolsPackageVersion>5.0.0-alpha1.19409.1</ILToolsPackageVersion>
<MicrosoftVisualStudioLanguageServerProtocolPackagesVersion>16.7.29</MicrosoftVisualStudioLanguageServerProtocolPackagesVersion>
<MicrosoftVisualStudioLanguageServerProtocolPackagesVersion>16.8.5</MicrosoftVisualStudioLanguageServerProtocolPackagesVersion>
</PropertyGroup>
<!--
Dependency versions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1178,10 +1178,10 @@ static ref int M2(in int arg1, in (int Alice, int Bob) arg2)

var comp = CreateCompilationWithMscorlib45(text, new[] { ValueTupleRef, SystemRuntimeFacadeRef });
comp.VerifyDiagnostics(
// (18,20): error CS8410: Cannot return variable 'in int' by writable reference because it is a readonly variable
// (18,20): error CS8333: Cannot return variable 'in int' by writable reference because it is a readonly variable
// return ref arg1;
Diagnostic(ErrorCode.ERR_RefReturnReadonlyNotField, "arg1").WithArguments("variable", "in int").WithLocation(18, 20),
// (23,20): error CS8411: Members of variable 'in (int Alice, int Bob)' cannot be returned by writable reference because it is a readonly variable
// (23,20): error CS8334: Members of variable 'in (int Alice, int Bob)' cannot be returned by writable reference because it is a readonly variable
// return ref arg2.Alice;
Diagnostic(ErrorCode.ERR_RefReturnReadonlyNotField2, "arg2.Alice").WithArguments("variable", "in (int Alice, int Bob)").WithLocation(23, 20)
);
Expand Down Expand Up @@ -1269,10 +1269,10 @@ static ref int M(in int arg1, in (int Alice, int Bob) arg2)

var comp = CreateCompilationWithMscorlib45(text, new[] { ValueTupleRef, SystemRuntimeFacadeRef });
comp.VerifyDiagnostics(
// (10,24): error CS8410: Cannot return variable 'in int' by writable reference because it is a readonly variable
// (10,24): error CS8333: Cannot return variable 'in int' by writable reference because it is a readonly variable
// return ref arg1;
Diagnostic(ErrorCode.ERR_RefReturnReadonlyNotField, "arg1").WithArguments("variable", "in int").WithLocation(10, 24),
// (14,24): error CS8411: Members of variable 'in (int Alice, int Bob)' cannot be returned by writable reference because it is a readonly variable
// (14,24): error CS8334: Members of variable 'in (int Alice, int Bob)' cannot be returned by writable reference because it is a readonly variable
// return ref arg2.Alice;
Diagnostic(ErrorCode.ERR_RefReturnReadonlyNotField2, "arg2.Alice").WithArguments("variable", "in (int Alice, int Bob)").WithLocation(14, 24)
);
Expand Down Expand Up @@ -1388,10 +1388,10 @@ ref int M1(in int arg11, in (int Alice, int Bob) arg21)

var comp = CreateCompilationWithMscorlib45(text, new[] { ValueTupleRef, SystemRuntimeFacadeRef });
comp.VerifyDiagnostics(
// (12,28): error CS8410: Cannot return variable 'in int' by writable reference because it is a readonly variable
// (12,28): error CS8333: Cannot return variable 'in int' by writable reference because it is a readonly variable
// return ref arg11;
Diagnostic(ErrorCode.ERR_RefReturnReadonlyNotField, "arg11").WithArguments("variable", "in int").WithLocation(12, 28),
// (16,28): error CS8411: Members of variable 'in (int Alice, int Bob)' cannot be returned by writable reference because it is a readonly variable
// (16,28): error CS8334: Members of variable 'in (int Alice, int Bob)' cannot be returned by writable reference because it is a readonly variable
// return ref arg21.Alice;
Diagnostic(ErrorCode.ERR_RefReturnReadonlyNotField2, "arg21.Alice").WithArguments("variable", "in (int Alice, int Bob)").WithLocation(16, 28)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected override string GetCompletionString(string commandName)
private static readonly Regex s_referenceRegex = new Regex(@"\s*#\s*r\s+", RegexOptions.Compiled);
private static readonly Regex s_loadCommandRegex = new Regex(@"#load\s+", RegexOptions.Compiled);

private bool IsReplCommandLocation(SnapshotPoint characterPoint)
private static bool IsReplCommandLocation(SnapshotPoint characterPoint)
{
// TODO(cyrusn): We don't need to do this textually. We could just defer this to
// IsTriggerCharacter and just check the syntax tree.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public CSharpSendToInteractiveSubmissionProvider()
protected override bool CanParseSubmission(string code)
{
ParseOptions options = CSharpParseOptions.Default.WithKind(SourceCodeKind.Script);
SyntaxTree tree = SyntaxFactory.ParseSyntaxTree(code, options);
var tree = SyntaxFactory.ParseSyntaxTree(code, options);
return tree.HasCompilationUnitRoot &&
!tree.GetDiagnostics().Any(diagnostic => diagnostic.Severity == DiagnosticSeverity.Error);
}

protected override IEnumerable<TextSpan> GetExecutableSyntaxTreeNodeSelection(TextSpan selectionSpan, SyntaxNode root)
{
SyntaxNode expandedNode = GetSyntaxNodeForSubmission(selectionSpan, root);
var expandedNode = GetSyntaxNodeForSubmission(selectionSpan, root);
return expandedNode != null
? new TextSpan[] { expandedNode.Span }
: Array.Empty<TextSpan>();
Expand All @@ -46,7 +46,7 @@ protected override IEnumerable<TextSpan> GetExecutableSyntaxTreeNodeSelection(Te
/// </summary>
/// <param name="selectionSpan">Selection that user has originally made.</param>
/// <param name="root">Root of the syntax tree.</param>
private SyntaxNode GetSyntaxNodeForSubmission(TextSpan selectionSpan, SyntaxNode root)
private static SyntaxNode GetSyntaxNodeForSubmission(TextSpan selectionSpan, SyntaxNode root)
{
GetSelectedTokens(selectionSpan, root, out var startToken, out var endToken);

Expand Down Expand Up @@ -117,7 +117,7 @@ private static bool IsSubmissionNode(SyntaxNode node)
|| node.IsKind(SyntaxKind.UsingDirective);
}

private void GetSelectedTokens(
private static void GetSelectedTokens(
TextSpan selectionSpan,
SyntaxNode root,
out SyntaxToken startToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,22 @@ protected override string GetEndingString(Document document, int position, Cance
return null;
}

private SyntaxNode ParseNode(SyntaxTree tree, SyntaxNode owningNode, string textToParse)
private static SyntaxNode ParseNode(SyntaxTree tree, SyntaxNode owningNode, string textToParse)
=> owningNode switch
{
BaseFieldDeclarationSyntax n => SyntaxFactory.ParseCompilationUnit(WrapInType(textToParse), options: (CSharpParseOptions)tree.Options),
BaseMethodDeclarationSyntax n => SyntaxFactory.ParseCompilationUnit(WrapInType(textToParse), options: (CSharpParseOptions)tree.Options),
BasePropertyDeclarationSyntax n => SyntaxFactory.ParseCompilationUnit(WrapInType(textToParse), options: (CSharpParseOptions)tree.Options),
StatementSyntax n => SyntaxFactory.ParseStatement(textToParse, options: (CSharpParseOptions)tree.Options),
UsingDirectiveSyntax n => SyntaxFactory.ParseCompilationUnit(textToParse, options: (CSharpParseOptions)tree.Options),
BaseFieldDeclarationSyntax _ => SyntaxFactory.ParseCompilationUnit(WrapInType(textToParse), options: (CSharpParseOptions)tree.Options),
BaseMethodDeclarationSyntax _ => SyntaxFactory.ParseCompilationUnit(WrapInType(textToParse), options: (CSharpParseOptions)tree.Options),
BasePropertyDeclarationSyntax _ => SyntaxFactory.ParseCompilationUnit(WrapInType(textToParse), options: (CSharpParseOptions)tree.Options),
StatementSyntax _ => SyntaxFactory.ParseStatement(textToParse, options: (CSharpParseOptions)tree.Options),
UsingDirectiveSyntax _ => SyntaxFactory.ParseCompilationUnit(textToParse, options: (CSharpParseOptions)tree.Options),

_ => (SyntaxNode)null,
};

/// <summary>
/// wrap field in type
/// </summary>
private string WrapInType(string textToParse)
private static string WrapInType(string textToParse)
=> "class C { " + textToParse + " }";

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ private static bool ContainsOnlyWhitespace(IBraceCompletionSession session)
return true;
}

private IEnumerable<AbstractFormattingRule> GetFormattingRules(Document document)
private static IEnumerable<AbstractFormattingRule> GetFormattingRules(Document document)
{
var indentStyle = document.GetOptionsAsync(CancellationToken.None).WaitAndGetResult_CanCallOnBackground(CancellationToken.None).GetOption(FormattingOptions.SmartIndent);
return SpecializedCollections.SingletonEnumerable<AbstractFormattingRule>(BraceCompletionFormattingRule.ForIndentStyle(indentStyle)).Concat(Formatter.GetDefaultFormattingRules(document));
}

private void FormatTrackingSpan(IBraceCompletionSession session, bool shouldHonorAutoFormattingOnCloseBraceOption, IEnumerable<AbstractFormattingRule> rules = null)
private static void FormatTrackingSpan(IBraceCompletionSession session, bool shouldHonorAutoFormattingOnCloseBraceOption, IEnumerable<AbstractFormattingRule> rules = null)
{
if (!session.SubjectBuffer.GetFeatureOnOffOption(FeatureOnOffOptions.AutoFormattingOnCloseBrace) && shouldHonorAutoFormattingOnCloseBraceOption)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public override bool CheckOpeningPoint(IBraceCompletionSession session, Cancella
return true;
}

private bool PossibleTypeArgument(ITextSnapshot snapshot, SyntaxToken token, CancellationToken cancellationToken)
private static bool PossibleTypeArgument(ITextSnapshot snapshot, SyntaxToken token, CancellationToken cancellationToken)
{
// type argument can be easily ambiguous with normal < operations
if (!(token.Parent is BinaryExpressionSyntax node) || node.Kind() != SyntaxKind.LessThanExpression || node.OperatorToken != token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private bool TryHandleReturnKey(ITextBuffer subjectBuffer, ITextView textView)
return true;
}

private Span GetReplacementSpan(SnapshotPoint caretPosition)
private static Span GetReplacementSpan(SnapshotPoint caretPosition)
{
// We want to replace all the whitespace following the caret. This is standard <enter> behavior in VS that
// we want to mimic.
Expand All @@ -92,7 +92,7 @@ private Span GetReplacementSpan(SnapshotPoint caretPosition)
return Span.FromBounds(start, end);
}

private string? GetTextToInsert(SnapshotPoint caretPosition)
private static string? GetTextToInsert(SnapshotPoint caretPosition)
{
var currentLine = caretPosition.GetContainingLine();
var firstNonWhitespacePosition = currentLine.GetFirstNonWhitespacePosition() ?? -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private CSharpDecompiledSourceFormattingRule()
return operation ?? nextOperation.Invoke(in previousToken, in currentToken);
}

private AdjustNewLinesOperation? GetAdjustNewLinesOperation(SyntaxToken previousToken, SyntaxToken currentToken)
private static AdjustNewLinesOperation? GetAdjustNewLinesOperation(SyntaxToken previousToken, SyntaxToken currentToken)
{
// To help code not look too tightly packed, we place a blank line after every statement that ends with a
// `}` (unless it's also followed by another `}`).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static async Task<Document> FormatDocumentAsync(Document document, Cancel
return formattedDoc;
}

private Document PerformDecompilation(Document document, string fullName, Compilation compilation, string assemblyLocation)
private static Document PerformDecompilation(Document document, string fullName, Compilation compilation, string assemblyLocation)
{
// Load the assembly.
var file = new PEFile(assemblyLocation, PEStreamOptions.PrefetchEntireImage);
Expand All @@ -122,7 +122,7 @@ private Document PerformDecompilation(Document document, string fullName, Compil
return document.WithText(SourceText.From(text));
}

private async Task<Document> AddAssemblyInfoRegionAsync(Document document, ISymbol symbol, CancellationToken cancellationToken)
private static async Task<Document> AddAssemblyInfoRegionAsync(Document document, ISymbol symbol, CancellationToken cancellationToken)
{
var assemblyInfo = MetadataAsSourceHelpers.GetAssemblyInfo(symbol.ContainingAssembly);
var compilation = await document.Project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
Expand All @@ -148,7 +148,7 @@ private async Task<Document> AddAssemblyInfoRegionAsync(Document document, ISymb
return document.WithSyntaxRoot(newRoot);
}

private async Task<Document> ConvertDocCommentsToRegularCommentsAsync(Document document, IDocumentationCommentFormattingService docCommentFormattingService, CancellationToken cancellationToken)
private static async Task<Document> ConvertDocCommentsToRegularCommentsAsync(Document document, IDocumentationCommentFormattingService docCommentFormattingService, CancellationToken cancellationToken)
{
var syntaxRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

Expand All @@ -157,7 +157,7 @@ private async Task<Document> ConvertDocCommentsToRegularCommentsAsync(Document d
return document.WithSyntaxRoot(newSyntaxRoot);
}

private string GetFullReflectionName(INamedTypeSymbol containingType)
private static string GetFullReflectionName(INamedTypeSymbol containingType)
{
var stack = new Stack<string>();
stack.Push(containingType.MetadataName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ protected override bool IsSingleExteriorTrivia(DocumentationCommentTriviaSyntax
&& lastTextToken.TrailingTrivia.Count == 0;
}

private IList<SyntaxToken> GetTextTokensFollowingExteriorTrivia(XmlTextSyntax xmlText)
private static IList<SyntaxToken> GetTextTokensFollowingExteriorTrivia(XmlTextSyntax xmlText)
{
var result = new List<SyntaxToken>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected override void TryCompleteTag(ITextView textView, ITextBuffer subjectBu
}
}

private bool HasFollowingEndTagTrivia(XmlElementSyntax parentElement, SyntaxToken lessThanSlashToken)
private static bool HasFollowingEndTagTrivia(XmlElementSyntax parentElement, SyntaxToken lessThanSlashToken)
{
var expectedEndTagText = "</" + parentElement.StartTag.Name.LocalName.ValueText + ">";

Expand Down Expand Up @@ -113,7 +113,7 @@ private bool HasUnmatchedIdenticalParent(XmlElementStartTagSyntax parentStartTag
return false;
}

private bool HasMatchingEndTag(XmlElementStartTagSyntax parentStartTag)
private static bool HasMatchingEndTag(XmlElementStartTagSyntax parentStartTag)
{
if (parentStartTag == null)
{
Expand Down
Loading