Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into features/ioperation
Browse files Browse the repository at this point in the history
* upstream/master: (68 commits)
  Update F1 Keywords to differentiate between semantics of default keyword (dotnet#48500)
  Default constructor suggestion between members (dotnet#48318) (dotnet#48503)
  Adjust ERR_PartialMisplaced diagnostic message (dotnet#48524)
  Refactor ChangedText.Merge and add fuzz testing (dotnet#48420)
  Apply suggestions from code review
  Do not crash on unexpected exception (dotnet#48367)
  Reference the contributing doc in 'Analyzer Suggestion' issue template
  Apply suggestions from code review
  Hardcode skipped Regex diagnostic ID as it is not available in CodeStyle layer
  Add using
  Skip help link for Regex diagnostic analyzer
  Add contributing doc for IDE code style analyzer documentation
  Make db lock static to investigate issue.
  Update dependencies from https://github.com/dotnet/roslyn build 20201012.2 (dotnet#48513)
  Hook up help link even for AbstractCodeQualityDiagnosticAnalyzer
  Add destructor intellisense test for record (dotnet#48297)
  Remove unused method (dotnet#48429)
  Fix bug
  Update src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsTag.cs
  Add more test
  ...
  • Loading branch information
333fred committed Oct 13, 2020
2 parents 38a25d1 + 8746590 commit b36fd91
Show file tree
Hide file tree
Showing 363 changed files with 3,231 additions and 2,128 deletions.
4 changes: 4 additions & 0 deletions .github/ISSUE_TEMPLATE/analyzer-suggestion.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ A small code snippet that describes a case that the analyzer should report.
**Additional information:**

Any more additional information you would like to add.

**Documentation requirements:**

When this analyzer is implemented, it must be documented by following the steps at [Documentation for IDE CodeStyle analyzers](../../docs/contributing/Documentation for IDE CodeStyle analyzers.md).
660 changes: 0 additions & 660 deletions Roslyn.sln

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ The minimal required version of .NET Framework is 4.7.2.

1. [Visual Studio 2019 16.8p2](https://visualstudio.microsoft.com/downloads/)
- Ensure C#, VB, MSBuild, .NET Core and Visual Studio Extensibility are included in the selected work loads
- Ensure Visual Studio is on Version "16.8 Preview 2" or greater
- Ensure Visual Studio is on Version "16.8 Preview 3" or greater
- Ensure "Use previews of the .NET Core SDK" is checked in Tools -> Options -> Environment -> Preview Features
- Restart Visual Studio
1. [.NET Core SDK 5.0 Preview 8](https://dotnet.microsoft.com/download/dotnet-core/5.0) [Windows x64 installer](https://dotnet.microsoft.com/download/dotnet/thank-you/sdk-5.0.100-preview.8-windows-x64-installer)
1. [.NET Core SDK 5.0 Release Candidate 1](https://dotnet.microsoft.com/download/dotnet-core/5.0) [Windows x64 installer](https://dotnet.microsoft.com/download/dotnet-core/thank-you/sdk-5.0.100-rc.1-windows-x64-installer)
1. [PowerShell 5.0 or newer](https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell). If you are on Windows 10, you are fine; you'll only need to upgrade if you're on earlier versions of Windows. The download link is under the ["Upgrading existing Windows PowerShell"](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-windows-powershell?view=powershell-6#upgrading-existing-windows-powershell) heading.
1. Run Restore.cmd
1. Open Roslyn.sln
Expand Down
33 changes: 33 additions & 0 deletions docs/contributing/Documentation for IDE CodeStyle analyzers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Documentation for IDE CodeStyle analyzers

## Overview

1. Official documentation for all [IDE analyzer diagnostic IDs](../../src/Analyzers/Core/Analyzers/IDEDiagnosticIds.cs) is added to `dotnet/docs` repo at <https://github.com/dotnet/docs/tree/master/docs/fundamentals/code-analysis/style-rules>.

2. Each IDE diagnostic ID has a dedicated documentation page. For example:
1. Diagnostic with code style option: <https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0011>
2. Diagnostic without code style option: <https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0004>
3. Multiple diagnostic IDs sharing the same option(s): <https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0003-ide0009>

3. We have tabular indices for IDE diagnostic IDs and code style options for easier reference and navigation:
1. Primary index (rule ID + code style options): <https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/>
2. Secondary index (code style options only): <https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#net-style-rules>
3. Indices for each preference/option group. For example:
1. Modifier preferences: <https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/modifier-preferences>
2. Expression-level preferences: <https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/expression-level-preferences>

## Action items when adding or updating IDE analyzers

Roslyn IDE team (@dotnet/roslyn-ide) is responsible for ensuring that the documentation for IDE analyzers is up-to-date. Whenever we add a new IDE analyzer, add new code style option(s) OR update semantics of existing IDE analyzers the following needs to be done:

1. **Action required in [dotnet\docs](https://github.com/dotnet/docs) repo**:
1. If you _creating a Roslyn PR for an IDE analyzer_:
1. Please follow the steps at [Contribute docs for 'IDExxxx' rules](https://docs.microsoft.com/contribute/dotnet/dotnet-contribute-code-analysis#contribute-docs-for-idexxxx-rules) to add documentation for IDE analyzers to [dotnet\docs](https://github.com/dotnet/docs) repo.
2. Ideally, the documentation PR should be created in parallel to the Roslyn PR or immediately following the approval/merge of Roslyn PR.
2. If you are _reviewing a Roslyn PR for an IDE analyzer_:
1. Please ensure that the analyzer author is made aware of the above doc contribution requirements, especially if it is a community PR.
2. If the documentation PR in is not being created in parallel to the Roslyn PR, please ensure that a [new doc issue](https://github.com/dotnet/docs/issues) is filed in `dotnet/docs` repo to track this work.

2. **No action required in Roslyn repo**: Help links have been hooked up to IDE code style analyzers in Roslyn repo in the base analyzer types, so every new IDE analyzer diagnostic ID will automatically have `https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ideXXXX` as its help link. There is no action required on the Roslyn PR to ensure this linking.

If you feel any of the existing IDE rule docs have insufficient or incorrect information, please submit a PR to [dotnet\docs](https://github.com/dotnet/docs) repo to update the documentation.
4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>4f384ab6a49fc642aec2acc4bcc938172a0744d1</Sha>
</Dependency>
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="3.9.0-1.20504.1">
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="3.9.0-1.20512.2">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>88287e9625dd15e0bad4f2a9a33fb5af3b3d0315</Sha>
<Sha>53f4d5b526c845d39387f8d2782e6c2bb7301ac9</Sha>
</Dependency>
</ToolsetDependencies>
</Dependencies>
3 changes: 1 addition & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</MajorVersion>
<MinorVersion>
</MinorVersion>
<MicrosoftNetCompilersToolsetVersion>3.9.0-1.20504.1</MicrosoftNetCompilersToolsetVersion>
<MicrosoftNetCompilersToolsetVersion>3.9.0-1.20512.2</MicrosoftNetCompilersToolsetVersion>
</PropertyGroup>
<PropertyGroup>
<!-- Versions used by several individual references below -->
Expand Down Expand Up @@ -57,7 +57,6 @@
<NuGetVisualStudioContractsVersion>5.7.0</NuGetVisualStudioContractsVersion>
<!-- This is working around Microsoft.VisualStudio.Shell.15.0 having an unstated conflicting reference on this with NuGet.VisualStudio.Contracts -->
<MicrosoftVisualStudioRpcContractsVersion>16.7.50</MicrosoftVisualStudioRpcContractsVersion>

<!--
Since the Microsoft.CodeAnalysis.Analyzers package is a public dependency of our NuGet
packages we will keep it untied to the RoslynDiagnosticsNugetPackageVersion we use for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@
namespace Microsoft.CodeAnalysis.CSharp.RemoveConfusingSuppression
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
internal class CSharpRemoveConfusingSuppressionDiagnosticAnalyzer : AbstractCodeStyleDiagnosticAnalyzer
internal sealed class CSharpRemoveConfusingSuppressionDiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
public CSharpRemoveConfusingSuppressionDiagnosticAnalyzer()
: base(IDEDiagnosticIds.RemoveConfusingSuppressionForIsExpressionDiagnosticId,
option: null,
new LocalizableResourceString(nameof(CSharpAnalyzersResources.Remove_unnecessary_suppression_operator), CSharpAnalyzersResources.ResourceManager, typeof(CSharpAnalyzersResources)),
new LocalizableResourceString(nameof(CSharpAnalyzersResources.Suppression_operator_has_no_effect_and_can_be_misinterpreted), CSharpAnalyzersResources.ResourceManager, typeof(CSharpAnalyzersResources)))
{
}

public override DiagnosticAnalyzerCategory GetAnalyzerCategory() => DiagnosticAnalyzerCategory.SemanticSpanAnalysis;

protected override void InitializeWorker(AnalysisContext context)
=> context.RegisterSyntaxNodeAction(AnalyzeSyntax, SyntaxKind.IsExpression, SyntaxKind.IsPatternExpression);

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

namespace Microsoft.CodeAnalysis.CodeStyle
{
internal abstract class AbstractBuiltInCodeStyleDiagnosticAnalyzer : AbstractCodeStyleDiagnosticAnalyzer, IBuiltInAnalyzer
internal abstract partial class AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
/// <summary>
/// Constructor for a code style analyzer with a single diagnostic descriptor and
Expand All @@ -40,7 +40,7 @@ protected AbstractBuiltInCodeStyleDiagnosticAnalyzer(
LocalizableString? messageFormat = null,
bool isUnnecessary = false,
bool configurable = true)
: base(diagnosticId, title, messageFormat, isUnnecessary, configurable)
: this(diagnosticId, title, messageFormat, isUnnecessary, configurable)
{
AddDiagnosticIdToOptionMapping(diagnosticId, option);
}
Expand Down Expand Up @@ -70,7 +70,7 @@ protected AbstractBuiltInCodeStyleDiagnosticAnalyzer(
LocalizableString? messageFormat = null,
bool isUnnecessary = false,
bool configurable = true)
: base(diagnosticId, title, messageFormat, isUnnecessary, configurable)
: this(diagnosticId, title, messageFormat, isUnnecessary, configurable)
{
AddDiagnosticIdToOptionMapping(diagnosticId, option, language);
}
Expand All @@ -97,7 +97,7 @@ protected AbstractBuiltInCodeStyleDiagnosticAnalyzer(
LocalizableString? messageFormat = null,
bool isUnnecessary = false,
bool configurable = true)
: base(diagnosticId, title, messageFormat, isUnnecessary, configurable)
: this(diagnosticId, title, messageFormat, isUnnecessary, configurable)
{
RoslynDebug.Assert(options != null);
Debug.Assert(options.Count > 1);
Expand Down Expand Up @@ -128,7 +128,7 @@ protected AbstractBuiltInCodeStyleDiagnosticAnalyzer(
LocalizableString? messageFormat = null,
bool isUnnecessary = false,
bool configurable = true)
: base(diagnosticId, title, messageFormat, isUnnecessary, configurable)
: this(diagnosticId, title, messageFormat, isUnnecessary, configurable)
{
RoslynDebug.Assert(options != null);
Debug.Assert(options.Count > 1);
Expand All @@ -139,7 +139,7 @@ protected AbstractBuiltInCodeStyleDiagnosticAnalyzer(
/// Constructor for a code style analyzer with a multiple diagnostic descriptors with per-language options that can be used to configure each descriptor.
/// </summary>
protected AbstractBuiltInCodeStyleDiagnosticAnalyzer(ImmutableDictionary<DiagnosticDescriptor, IPerLanguageOption> supportedDiagnosticsWithOptions)
: base(supportedDiagnosticsWithOptions.Keys.ToImmutableArray())
: this(supportedDiagnosticsWithOptions.Keys.ToImmutableArray())
{
foreach (var kvp in supportedDiagnosticsWithOptions)
{
Expand All @@ -153,7 +153,7 @@ protected AbstractBuiltInCodeStyleDiagnosticAnalyzer(ImmutableDictionary<Diagnos
protected AbstractBuiltInCodeStyleDiagnosticAnalyzer(
ImmutableDictionary<DiagnosticDescriptor, ILanguageSpecificOption> supportedDiagnosticsWithOptions,
string language)
: base(supportedDiagnosticsWithOptions.Keys.ToImmutableArray())
: this(supportedDiagnosticsWithOptions.Keys.ToImmutableArray())
{
foreach (var kvp in supportedDiagnosticsWithOptions)
{
Expand All @@ -168,7 +168,7 @@ protected AbstractBuiltInCodeStyleDiagnosticAnalyzer(
ImmutableDictionary<DiagnosticDescriptor, ILanguageSpecificOption> supportedDiagnosticsWithLangaugeSpecificOptions,
ImmutableDictionary<DiagnosticDescriptor, IPerLanguageOption> supportedDiagnosticsWithPerLanguageOptions,
string language)
: base(supportedDiagnosticsWithLangaugeSpecificOptions.Keys.Concat(supportedDiagnosticsWithPerLanguageOptions.Keys).ToImmutableArray())
: this(supportedDiagnosticsWithLangaugeSpecificOptions.Keys.Concat(supportedDiagnosticsWithPerLanguageOptions.Keys).ToImmutableArray())
{
foreach (var kvp in supportedDiagnosticsWithLangaugeSpecificOptions)
{
Expand All @@ -181,14 +181,6 @@ protected AbstractBuiltInCodeStyleDiagnosticAnalyzer(
}
}

/// <summary>
/// Constructor for a code style analyzer with a multiple diagnostic descriptors such that all the descriptors have no unique code style option to configure the descriptors.
/// </summary>
protected AbstractBuiltInCodeStyleDiagnosticAnalyzer(ImmutableArray<DiagnosticDescriptor> supportedDiagnosticsWithoutOptions)
: base(supportedDiagnosticsWithoutOptions)
{
}

private static void AddDiagnosticIdToOptionMapping(string diagnosticId, IPerLanguageOption? option)
{
if (option != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Microsoft.CodeAnalysis.CodeStyle
{
internal abstract class AbstractCodeStyleDiagnosticAnalyzer : DiagnosticAnalyzer
internal abstract partial class AbstractBuiltInCodeStyleDiagnosticAnalyzer : DiagnosticAnalyzer, IBuiltInAnalyzer
{
protected readonly string? DescriptorId;

Expand All @@ -16,11 +16,11 @@ internal abstract class AbstractCodeStyleDiagnosticAnalyzer : DiagnosticAnalyzer
protected readonly LocalizableString _localizableTitle;
protected readonly LocalizableString _localizableMessageFormat;

protected AbstractCodeStyleDiagnosticAnalyzer(
private AbstractBuiltInCodeStyleDiagnosticAnalyzer(
string descriptorId, LocalizableString title,
LocalizableString? messageFormat = null,
bool isUnnecessary = false,
bool configurable = true)
LocalizableString? messageFormat,
bool isUnnecessary,
bool configurable)
{
DescriptorId = descriptorId;
_localizableTitle = title;
Expand All @@ -30,7 +30,10 @@ protected AbstractCodeStyleDiagnosticAnalyzer(
SupportedDiagnostics = ImmutableArray.Create(Descriptor);
}

protected AbstractCodeStyleDiagnosticAnalyzer(ImmutableArray<DiagnosticDescriptor> supportedDiagnostics)
/// <summary>
/// Constructor for a code style analyzer with a multiple diagnostic descriptors such that all the descriptors have no unique code style option to configure the descriptors.
/// </summary>
protected AbstractBuiltInCodeStyleDiagnosticAnalyzer(ImmutableArray<DiagnosticDescriptor> supportedDiagnostics)
{
SupportedDiagnostics = supportedDiagnostics;

Expand All @@ -55,6 +58,7 @@ protected static DiagnosticDescriptor CreateDescriptorWithId(
DiagnosticSeverity.Hidden,
isEnabledByDefault: true,
description: description,
helpLinkUri: DiagnosticHelper.GetHelpLinkForDiagnosticId(id),
customTags: DiagnosticCustomTags.Create(isUnnecessary, isConfigurable, customTags));

public sealed override void Initialize(AnalysisContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ protected static DiagnosticDescriptor CreateDescriptor(
DiagnosticSeverity.Info,
isEnabledByDefault,
description,
helpLinkUri: DiagnosticHelper.GetHelpLinkForDiagnosticId(id),
customTags: DiagnosticCustomTags.Create(isUnnecessary, isConfigurable, customTags));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ namespace Microsoft.CodeAnalysis.RemoveUnnecessaryParentheses
internal abstract class AbstractParenthesesDiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
protected AbstractParenthesesDiagnosticAnalyzer(
string descriptorId, LocalizableString title, LocalizableString message)
string descriptorId, LocalizableString title, LocalizableString message, bool isUnnecessary = false)
: base(descriptorId,
options: ImmutableHashSet.Create<IPerLanguageOption>(CodeStyleOptions2.ArithmeticBinaryParentheses, CodeStyleOptions2.RelationalBinaryParentheses, CodeStyleOptions2.OtherBinaryParentheses, CodeStyleOptions2.OtherParentheses),
title, message)
{
}

protected AbstractParenthesesDiagnosticAnalyzer(ImmutableArray<DiagnosticDescriptor> diagnosticDescriptors)
: base(diagnosticDescriptors)
title,
message,
isUnnecessary: isUnnecessary)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Analyzers/Core/Analyzers/Analyzers.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)AbstractBuiltInCodeStyleDiagnosticAnalyzer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AbstractCodeQualityDiagnosticAnalyzer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AbstractCodeStyleDiagnosticAnalyzer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AbstractBuiltInCodeStyleDiagnosticAnalyzer_Core.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AbstractParenthesesDiagnosticAnalyzer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AddAccessibilityModifiers\AbstractAddAccessibilityModifiersDiagnosticAnalyzer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AddRequiredParentheses\AbstractAddRequiredParenthesesDiagnosticAnalyzer.cs" />
Expand Down Expand Up @@ -91,4 +91,4 @@
<ItemGroup Condition="'$(DefaultLanguageSourceExtension)' != '' AND '$(BuildingInsideVisualStudio)' != 'true'">
<ExpectedCompile Include="$(MSBuildThisFileDirectory)**\*$(DefaultLanguageSourceExtension)" />
</ItemGroup>
</Project>
</Project>
14 changes: 14 additions & 0 deletions src/Analyzers/Core/Analyzers/Helpers/DiagnosticHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Json;
Expand Down Expand Up @@ -256,6 +257,19 @@ public static Diagnostic CreateWithMessage(
properties);
}

public static string GetHelpLinkForDiagnosticId(string id)
{
if (id == "RE0001")
{
// TODO: Add documentation for Regex analyzer
// Tracked with https://github.com/dotnet/roslyn/issues/48530
return null;
}

Debug.Assert(id.StartsWith("IDE", StringComparison.Ordinal));
return $"https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/{id.ToLowerInvariant()}";
}

public sealed class LocalizableStringWithArguments : LocalizableString, IObjectWritable
{
private readonly LocalizableString _messageFormat;
Expand Down
Loading

0 comments on commit b36fd91

Please sign in to comment.