Skip to content

Commit cdcc3c4

Browse files
authored
Merge RoslynAnalyzers into Roslyn (#77617)
This PR brings over the roslyn owned packages from the roslyn-analyzers repo along with their history. The goal of this PR is to get the analyzers moved over in a state that we can live with so that they can be removed from roslyn-analyzers. We can then do further reorganization and integration as follow-ups. My changes begin at commit 24fbf05. NetAnalyzers will remain in roslyn-analyzers. Moved packages: - Microsoft.CodeAnalysis.Analyzers - Microsoft.CodeAnalysis.AnalyzerUtilities - Microsoft.CodeAnalysis.BannedApiAnalyzers - Microsoft.CodeAnalysis.Metrics - Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers - Microsoft.CodeAnalysis.PublicApiAnalyzers - Microsoft.CodeAnalysis.ResxSourceGenerator - Microsoft.CodeAnalysis.RulesetToEditorconfigConverter - Roslyn.Diagnostic.Analyzers The package versioning is maintained and separate from the current Roslyn package versioning. These packages use a variety of Microsoft.CodeAnalysis package versions and I have maintained that despite our use of transitive version pinning. I have also maintained Roslyn's use of these packages from our NuGet feeds. I have organized the code under a src/RoslynAnalyzers folder. ![image](https://github.com/user-attachments/assets/9b65893a-0c7e-4044-9324-158346c5a75a) The projects are organized in our solution file beneath an Analyzers folder. ![image](https://github.com/user-attachments/assets/d75bcf92-8e2a-4edf-a11d-b86949934543)
2 parents 0dcd8f5 + 207eb10 commit cdcc3c4

File tree

969 files changed

+286533
-81
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

969 files changed

+286533
-81
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ dotnet_diagnostic.IDE0055.severity = warning
154154
# https://github.com/dotnet/roslyn-analyzers/issues/7436 - False positives from valid GetDeclaredSymbol calls
155155
dotnet_diagnostic.RS1039.severity = none
156156

157-
# These xUnit analyzers were disabled temporarily to let us move to the
157+
# These xUnit analyzers were disabled temporarily to let us move to the
158158
# new xUnit and get past several component governance issues. The
159159
# following issue tracks enabling them
160160
#

.github/CODEOWNERS

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Automatically request reviews when a pull request changes any owned files
2-
# More information: https://github.com/blog/2392-introducing-code-owners
2+
3+
# More information: https://github.com/blog/2392-introducing-code-owners
34

45
*.yml @dotnet/roslyn-infrastructure
56
.github/ @dotnet/roslyn-infrastructure
@@ -15,15 +16,20 @@ scripts/ @dotnet/roslyn-infrastructure
1516
src/Analyzers/ @dotnet/roslyn-ide
1617
src/CodeStyle/ @dotnet/roslyn-ide
1718
src/Compilers/ @dotnet/roslyn-compiler
19+
1820
# Both IDE and Compiler traits are in this file, so we don't want to ping each other for changes to just this file.
21+
1922
# Technically this means that if someone changes _just_ this file no reviewers will be tagged, but this isn't likely
23+
2024
# to happen.
25+
2126
src/Compilers/Test/Core/Traits/Traits.cs
2227
src/EditorFeatures/ @dotnet/roslyn-ide
2328
src/Features/ @dotnet/roslyn-ide
2429
src/Interactive/ @dotnet/roslyn-interactive
2530
src/LanguageServer/ @dotnet/roslyn-ide
2631
src/NuGet/ @dotnet/roslyn-infrastructure
32+
src/RoslynAnalyzers/ @dotnet/roslyn-ide
2733
src/Scripting/ @dotnet/roslyn-interactive
2834
src/Setup/ @dotnet/roslyn-infrastructure
2935
src/Tools/AnalyzerRunner @dotnet/roslyn-ide

Roslyn.sln

Lines changed: 461 additions & 0 deletions
Large diffs are not rendered by default.

docs/analyzers/FixAllProvider.md

Lines changed: 69 additions & 69 deletions
Large diffs are not rendered by default.

docs/roslyn-analyzers/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Roslyn Analyzers
2+
3+
## Microsoft.CodeAnalysis.Analyzers
4+
5+
*Latest stable version:* <sub>[![NuGet](https://img.shields.io/nuget/v/Microsoft.CodeAnalysis.Analyzers.svg)](https://www.nuget.org/packages/Microsoft.CodeAnalysis.Analyzers)</sub>
6+
7+
*Latest pre-release version:* [here](https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet7/NuGet/Microsoft.CodeAnalysis.Analyzers/versions)
8+
9+
This package contains rules for correct usage of APIs from the [Microsoft.CodeAnalysis](https://www.nuget.org/packages/Microsoft.CodeAnalysis) NuGet package, i.e. .NET Compiler Platform ("Roslyn") APIs. These are primarily aimed towards helping authors of diagnostic analyzers and code fix providers to invoke the Microsoft.CodeAnalysis APIs in a recommended manner. [More info about rules in this package](../../src/RoslynAnalyzers/Microsoft.CodeAnalysis.Analyzers/Microsoft.CodeAnalysis.Analyzers.md)
10+
11+
## Roslyn.Diagnostics.Analyzers
12+
13+
*Latest stable version:* <sub>[![NuGet](https://img.shields.io/nuget/v/Roslyn.Diagnostics.Analyzers.svg)](https://www.nuget.org/packages/Roslyn.Diagnostics.Analyzers)</sub>
14+
15+
*Latest pre-release version:* [here](https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet7/NuGet/Roslyn.Diagnostics.Analyzers/versions)
16+
17+
This package contains rules that are very specific to the .NET Compiler Platform ("Roslyn") project, i.e. [dotnet/roslyn](https://github.com/dotnet/roslyn) repo. This analyzer package is *not intended for general consumption* outside the Roslyn repo. [More info about rules in this package](../../src/RoslynAnalyzers/Roslyn.Diagnostics.Analyzers/Roslyn.Diagnostics.Analyzers.md)
18+
19+
## Microsoft.CodeAnalysis.BannedApiAnalyzers
20+
21+
*Latest stable version:* <sub>[![NuGet](https://img.shields.io/nuget/v/Microsoft.CodeAnalysis.BannedApiAnalyzers.svg)](https://www.nuget.org/packages/Microsoft.CodeAnalysis.BannedApiAnalyzers)</sub>
22+
23+
*Latest pre-release version:* [here](https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet7/NuGet/Microsoft.CodeAnalysis.BannedApiAnalyzers/versions)
24+
25+
This package contains customizable rules for identifying references to banned APIs. [More info about rules in this package](../../src/RoslynAnalyzers/Microsoft.CodeAnalysis.BannedApiAnalyzers/Microsoft.CodeAnalysis.BannedApiAnalyzers.md)
26+
27+
For instructions on using this analyzer, see [Instructions](../../src/RoslynAnalyzers/Microsoft.CodeAnalysis.BannedApiAnalyzers/BannedApiAnalyzers.Help.md).
28+
29+
## Microsoft.CodeAnalysis.PublicApiAnalyzers
30+
31+
*Latest stable version:* <sub>[![NuGet](https://img.shields.io/nuget/v/Microsoft.CodeAnalysis.PublicApiAnalyzers.svg)](https://www.nuget.org/packages/Microsoft.CodeAnalysis.PublicApiAnalyzers)</sub>
32+
33+
*Latest pre-release version:* [here](https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet7/NuGet/Microsoft.CodeAnalysis.PublicApiAnalyzers/versions)
34+
35+
This package contains rules to help library authors monitoring change to their public APIs. [More info about rules in this package](../../src/RoslynAnalyzers/PublicApiAnalyzers/Microsoft.CodeAnalysis.PublicApiAnalyzers.md)
36+
37+
For instructions on using this analyzer, see [Instructions](../../src/RoslynAnalyzers/PublicApiAnalyzers/PublicApiAnalyzers.Help.md).

docs/roslyn-analyzers/rules/RS1022.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## RS1022: Do not use types from Workspaces assembly in an analyzer
2+
3+
Diagnostic analyzer types should not use types from Workspaces assemblies. Workspaces assemblies are only available when the analyzer executes in Visual Studio IDE live analysis, but are not available during command line build. Referencing types from Workspaces assemblies will lead to runtime exception during analyzer execution in command line build.
4+
5+
|Item|Value|
6+
|-|-|
7+
|Category|MicrosoftCodeAnalysisCorrectness|
8+
|Enabled|True|
9+
|Severity|Warning|
10+
|CodeFix|False|
11+
---
12+
13+
> **Warning**
14+
>
15+
> The analysis performed by RS1022 is slow and relies on implementation details of the JIT compiler for correctness.
16+
> Authors of compiler extensions are encouraged to use the stricter (and faster) analyzer RS1038 instead of this rule.
17+
>
18+
> RS1038 is enabled by default. To enable RS1022 instead, the following configuration may be added to **.globalconfig**:
19+
>
20+
> ```ini
21+
> roslyn_correctness.assembly_reference_validation = relaxed
22+
> ```

docs/roslyn-analyzers/rules/RS1038.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## RS1038: Compiler extensions should be implemented in assemblies with compiler-provided references
2+
3+
Types which implement compiler extension points should not be declared in assemblies that contain references to assemblies which are not provided by all compilation scenarios. Doing so may cause the feature to behave unpredictably.
4+
5+
|Item|Value|
6+
|-|-|
7+
|Category|MicrosoftCodeAnalysisCorrectness|
8+
|Enabled|True|
9+
|Severity|Warning|
10+
|CodeFix|False|
11+
---
12+
13+
This rule helps ensure compiler extensions (e.g. analyzers and source generators) will load correctly in all compilation
14+
scenarios. Depending on the manner in which the compiler is invoked, some assemblies may not be present during a build,
15+
and attempting to reference them will result in exceptions that prevent the compiler extension from loading. RS1038 is
16+
the most strict and best performing validation for this scenario.
17+
18+
RS1038 is enabled by default unless relaxed validation has been manually enabled in **.globalconfig** as described in
19+
[RS1022](RS1022.md).
20+
21+
### Rules for compiler feature references
22+
23+
* Compiler features supporting C# code should only reference the NuGet packages **Microsoft.CodeAnalysis.Common** and/or **Microsoft.CodeAnalysis.CSharp**
24+
* Compiler features supporting Visual Basic code should only reference **Microsoft.CodeAnalysis.Common** and/or **Microsoft.CodeAnalysis.VisualBasic**
25+
* Compiler features supporting both C# and Visual Basic should only reference **Microsoft.CodeAnalysis.Common**
26+
* Compiler features should not be implemented in assemblies containing a reference to **Microsoft.CodeAnalysis.Workspaces.Common**
27+
28+
> **Note**
29+
>
30+
> This analyzer only checks references to the core Roslyn assemblies. Compiler extensions with other dependencies may
31+
> face restrictions and/or packaging requirements outside the scope of this analyzer.
32+
33+
### Compiler extension points
34+
35+
The following compiler extension points are examined by this analyzer:
36+
37+
* `DiagnosticAnalyzer`
38+
* `DiagnosticSuppressor`
39+
* `ISourceGenerator`
40+
* `IIncrementalGenerator`
41+
42+
### Other extension points
43+
44+
Some extension points provided by Roslyn are IDE extensions (e.g. code fixes and completion providers). These features
45+
may ship in the same package as compiler features, but should be implemented in their own assembly since they require a
46+
reference to non-compiler package **Microsoft.CodeAnalysis.Workspaces.Common**.

docs/roslyn-analyzers/rules/RS1041.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## RS1041: Compiler extensions should be implemented in assemblies targeting netstandard2.0
2+
3+
Types which implement compiler extension points should only be declared in assemblies targeting netstandard2.0. More specific target frameworks are only available in a subset of supported compilation scenarios, so targeting them may cause the feature to behave unpredictably.
4+
5+
|Item|Value|
6+
|-|-|
7+
|Category|MicrosoftCodeAnalysisCorrectness|
8+
|Enabled|True|
9+
|Severity|Warning|
10+
|CodeFix|False|
11+
---
12+
13+
This rule helps ensure compiler extensions (e.g. analyzers and source generators) will load correctly in all compilation
14+
scenarios. Depending on the manner in which the compiler is invoked, the compiler may execute under .NET Framework or
15+
.NET, and compiler extensions are expected to work consistently in both cases. By targeting netstandard2.0, compiler
16+
extensions are known to be compatible with both execution environments.
17+
18+
### Compiler extension points
19+
20+
The following compiler extension points are examined by this analyzer:
21+
22+
* `DiagnosticAnalyzer`
23+
* `DiagnosticSuppressor`
24+
* `ISourceGenerator`
25+
* `IIncrementalGenerator`

eng/Directory.Packages.props

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
<MicrosoftWindowsDesktopAppRuntimePackagesVersion>8.0.10</MicrosoftWindowsDesktopAppRuntimePackagesVersion>
2222
<_xunitVersion>2.9.2</_xunitVersion>
2323
<SqliteVersion>2.1.0</SqliteVersion>
24+
<!-- HumanizerVersion is referenced from the Text.Analyzers.Package.csproj -->
25+
<HumanizerVersion>2.14.1</HumanizerVersion>
2426
</PropertyGroup>
2527

2628
<!--
@@ -116,7 +118,7 @@
116118
<PackageVersion Include="Nerdbank.Streams" Version="2.11.79" />
117119
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
118120
<PackageVersion Include="StreamJsonRpc" Version="2.21.10" />
119-
121+
120122
<!--
121123
VS Debugger
122124
-->
@@ -225,8 +227,12 @@
225227
<PackageVersion Include="SQLitePCLRaw.bundle_green" Version="$(SqliteVersion)" />
226228
<PackageVersion Include="SQLitePCLRaw.lib.e_sqlite3" Version="$(SqliteVersion)" />
227229
<PackageVersion Include="SQLitePCLRaw.provider.dynamic_cdecl" Version="$(SqliteVersion)" />
230+
<PackageVersion Include="SQLitePCLRaw.lib.e_sqlite3.linux" Version="$(SqliteVersion)" />
231+
<PackageVersion Include="SQLitePCLRaw.lib.e_sqlite3.osx" Version="$(SqliteVersion)" />
232+
<PackageVersion Include="SQLitePCLRaw.lib.e_sqlite3.v110_xp" Version="$(SqliteVersion)" />
233+
<PackageVersion Include="SQLitePCLRaw.provider.e_sqlite3.net45" Version="$(SqliteVersion)" />
228234

229-
<PackageVersion Include="Humanizer.Core" Version="2.14.1" />
235+
<PackageVersion Include="Humanizer.Core" Version="$(HumanizerVersion)" />
230236
<PackageVersion Include="ICSharpCode.Decompiler" Version="8.2.0.7535" />
231237
<PackageVersion Include="Microsoft.CodeAnalysis.Elfie" Version="1.0.0" />
232238

@@ -237,10 +243,15 @@
237243
<PackageVersion Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.13.0" />
238244
<PackageVersion Include="BasicUndo" Version="0.9.3" />
239245
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit" Version="$(MicrosoftCodeAnalysisTestingVersion)" />
246+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" Version="$(MicrosoftCodeAnalysisTestingVersion)" />
240247
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="$(MicrosoftCodeAnalysisTestingVersion)" />
248+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeRefactoring.Testing" Version="$(MicrosoftCodeAnalysisTestingVersion)" />
241249
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeRefactoring.Testing.XUnit" Version="$(MicrosoftCodeAnalysisTestingVersion)" />
250+
<PackageVersion Include="Microsoft.CodeAnalysis.Test.Resources.Proprietary" Version="2.0.0-pre-20160714" />
242251
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.Analyzer.Testing.XUnit" Version="$(MicrosoftCodeAnalysisTestingVersion)" />
252+
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.CodeFix.Testing" Version="$(MicrosoftCodeAnalysisTestingVersion)" />
243253
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.CodeFix.Testing.XUnit" Version="$(MicrosoftCodeAnalysisTestingVersion)" />
254+
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.CodeRefactoring.Testing" Version="$(MicrosoftCodeAnalysisTestingVersion)" />
244255
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.CodeRefactoring.Testing.XUnit" Version="$(MicrosoftCodeAnalysisTestingVersion)" />
245256
<PackageVersion Include="Microsoft.DiaSymReader.Converter" Version="1.1.0-beta2-22302-02" />
246257
<PackageVersion Include="Microsoft.DiaSymReader.Converter.Xml" Version="1.1.0-beta2-22302-02" />
@@ -313,5 +324,15 @@
313324
the generators we build would load on the command line but not load in IDEs.
314325
-->
315326
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.1.0" />
316-
</ItemGroup>
327+
<!--
328+
The version of Roslyn used in the RoslynAnalyzers varies. These are defaults that
329+
will be overridden in the RoslynAnalyzer project files.
330+
-->
331+
<!--<PackageVersion Include="Microsoft.CodeAnalysis" Version="4.1.0" /> -->
332+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.1.0" />
333+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.1.0" />
334+
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic" Version="4.1.0" />
335+
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="4.1.0" />
336+
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.1.0" />
337+
</ItemGroup>
317338
</Project>

eng/SourceBuildPrebuiltBaseline.xml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
<UsageData>
55
<IgnorePatterns>
6-
<!-- These are cases where the component chooses, when built in isolation, to
6+
<!-- These are cases where the component chooses, when built in isolation, to
77
remain dependent on stable versions. These versions may not have source build intermediates associated with them.
88
They cannot be source build reference packages because they actually provide functionality. In full source build, these versions are
9-
overridden by previous repo outputs or come from previously source-built artifacts. -->
9+
overridden by previous repo outputs or come from previously source-built artifacts. -->
1010
<UsagePattern IdentityGlob="Microsoft.CodeAnalysis.Analyzers/*" />
1111
<UsagePattern IdentityGlob="Microsoft.CodeAnalysis.AnalyzerUtilities/*" />
1212
<UsagePattern IdentityGlob="Microsoft.CodeAnalysis.CSharp.CodeStyle/*" />
@@ -49,6 +49,15 @@
4949
<UsagePattern IdentityGlob="System.Text.Json/9.0*" />
5050
<UsagePattern IdentityGlob="System.Threading.Tasks.Dataflow/9.0*" />
5151
<UsagePattern IdentityGlob="System.Windows.Extensions/9.0*" />
52+
53+
<!-- This is the version of Microsoft.CodeAnalysis used by RoslynAnalyzers for tooling executed
54+
in repo source-build, as well as unit tests. -->
55+
<UsagePattern IdentityGlob="Microsoft.CodeAnalysis*/*3.11.0*" />
56+
<UsagePattern IdentityGlob="Microsoft.CodeAnalysis*/*4.0.1*" />
57+
<UsagePattern IdentityGlob="Microsoft.CodeAnalysis*/*4.1.0*" />
58+
<UsagePattern IdentityGlob="Microsoft.CodeAnalysis*/*4.6.0-1.final*" />
59+
<!-- Dependency of Microsoft.CodeAnalysis.Common 4.6.0-1.final -->
60+
<UsagePattern IdentityGlob="Microsoft.CodeAnalysis.Analyzers/*3.3.4*" />
5261
</IgnorePatterns>
5362
<Usages>
5463
<Usage Id="Microsoft.Build" Version="17.3.4" IsDirectDependency="true" />

eng/Version.Details.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Dependencies>
33
<ProductDependencies>
4+
<!-- RoslynAnalyzers reference older builds of Roslyn and this is necessary for SourceBuild. -->
5+
<Dependency Name="Microsoft.CodeAnalysis" Version="3.11.0">
6+
<Uri>https://github.com/dotnet/roslyn</Uri>
7+
<Sha>ae1fff344d46976624e68ae17164e0607ab68b10</Sha>
8+
</Dependency>
49
<!-- Intermediate is necessary for source build. -->
510
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-externals" Version="9.0.0-alpha.1.24575.1">
611
<Uri>https://github.com/dotnet/source-build-externals</Uri>

0 commit comments

Comments
 (0)