-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6705 from sharwell/strict-references
Implement RS1038 (Strict compiler reference analysis)
- Loading branch information
Showing
56 changed files
with
1,323 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## RS1022: Do not use types from Workspaces assembly in an analyzer | ||
|
||
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. | ||
|
||
|Item|Value| | ||
|-|-| | ||
|Category|MicrosoftCodeAnalysisCorrectness| | ||
|Enabled|True| | ||
|Severity|Warning| | ||
|CodeFix|False| | ||
--- | ||
|
||
> **Warning** | ||
> | ||
> The analysis performed by RS1022 is slow and relies on implementation details of the JIT compiler for correctness. | ||
> Authors of compiler extensions are encouraged to use the stricter (and faster) analyzer RS1038 instead of this rule. | ||
> | ||
> RS1038 is enabled by default. To enable RS1022 instead, the following configuration may be added to **.globalconfig**: | ||
> | ||
> ```ini | ||
> roslyn_correctness.assembly_reference_validation = relaxed | ||
> ``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
## RS1038: Compiler extensions should be implemented in assemblies with compiler-provided references | ||
|
||
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. | ||
|
||
|Item|Value| | ||
|-|-| | ||
|Category|MicrosoftCodeAnalysisCorrectness| | ||
|Enabled|True| | ||
|Severity|Warning| | ||
|CodeFix|False| | ||
--- | ||
|
||
This rule helps ensure compiler extensions (e.g. analyzers and source generators) will load correctly in all compilation | ||
scenarios. Depending on the manner in which the compiler is invoked, some assemblies may not be present during a build, | ||
and attempting to reference them will result in exceptions that prevent the compiler extension from loading. RS1038 is | ||
the most strict and best performing validation for this scenario. | ||
|
||
RS1038 is enabled by default unless relaxed validation has been manually enabled in **.globalconfig** as described in | ||
[RS1022](RS1022.md). | ||
|
||
### Rules for compiler feature references | ||
|
||
* Compiler features supporting C# code should only reference the NuGet packages **Microsoft.CodeAnalysis.Common** and/or **Microsoft.CodeAnalysis.CSharp** | ||
* Compiler features supporting Visual Basic code should only reference **Microsoft.CodeAnalysis.Common** and/or **Microsoft.CodeAnalysis.VisualBasic** | ||
* Compiler features supporting both C# and Visual Basic should only reference **Microsoft.CodeAnalysis.Common** | ||
* Compiler features should not be implemented in assemblies containing a reference to **Microsoft.CodeAnalysis.Workspaces.Common** | ||
|
||
> **Note** | ||
> | ||
> This analyzer only checks references to the core Roslyn assemblies. Compiler extensions with other dependencies may | ||
> face restrictions and/or packaging requirements outside the scope of this analyzer. | ||
### Compiler extension points | ||
|
||
The following compiler extension points are examined by this analyzer: | ||
|
||
* `DiagnosticAnalyzer` | ||
* `DiagnosticSuppressor` | ||
* `ISourceGenerator` | ||
* `IIncrementalGenerator` | ||
|
||
### Other extension points | ||
|
||
Some extension points provided by Roslyn are IDE extensions (e.g. code fixes and completion providers). These features | ||
may ship in the same package as compiler features, but should be implemented in their own assembly since they require a | ||
reference to non-compiler package **Microsoft.CodeAnalysis.Workspaces.Common**. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/Microsoft.CodeAnalysis.Analyzers/Core/AnalyzerReleases.Unshipped.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
; Please do not edit this file manually, it should only be updated through code fix application. | ||
|
||
### New Rules | ||
|
||
Rule ID | Category | Severity | Notes | ||
--------|----------|----------|------- | ||
RS1038 | MicrosoftCodeAnalysisCorrectness | Warning | CompilerExtensionStrictApiAnalyzer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.