-
Notifications
You must be signed in to change notification settings - Fork 0
Restore and lock the analyzer's Roslyn floor #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
52983ad
build: restore and pin the analyzer's Roslyn floor from one source
claude a6bde60
test: enforce the analyzer's Roslyn floor
claude d2b97e6
ci: dogfood the analyzer on the Roslyn floor SDK
claude 9f0dd40
ci: stop Dependabot bumping the analyzer's Roslyn
claude 470762d
docs: document the analyzers' minimum compiler version
claude 0fafe31
ci: pin the floor check to SDK 8.0.100 and loosen the load proof
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,56 @@ | ||
| using System; | ||
| using System.Linq; | ||
| using System.Reflection; | ||
|
|
||
| using NFluent; | ||
|
|
||
| namespace FirstClassErrors.Analyzers.UnitTests; | ||
|
|
||
| /// <summary> | ||
| /// Enforces the analyzer's Roslyn load contract. The analyzer ships inside the FirstClassErrors package | ||
| /// and is loaded by each consumer's host compiler, so the Microsoft.CodeAnalysis version it is compiled | ||
| /// against is the minimum Roslyn able to load it; a higher one makes it fail to load (CS8032) on older | ||
| /// SDKs/IDEs. The floor is defined once in Directory.Build.props and surfaced here through assembly | ||
| /// metadata, so the csproj pin and this test can never diverge. | ||
| /// </summary> | ||
| public sealed class RoslynFloorTests { | ||
|
|
||
| [Fact] | ||
| public void Analyzer_stays_on_the_supported_Roslyn_floor() { | ||
| Assembly analyzerAssembly = typeof(DuplicateErrorCodeAnalyzer).Assembly; | ||
| Version floor = ReadFloor(analyzerAssembly); | ||
|
|
||
| // The analyzers use only the language-agnostic API (IOperation), so the compiler emits a reference | ||
| // to Microsoft.CodeAnalysis but not necessarily to Microsoft.CodeAnalysis.CSharp — only *used* | ||
| // references are recorded. Bound the whole family rather than one assembly name. | ||
| AssemblyName[] roslynReferences = analyzerAssembly | ||
| .GetReferencedAssemblies() | ||
| .Where(reference => reference.Name is not null | ||
| && reference.Name.StartsWith("Microsoft.CodeAnalysis", StringComparison.Ordinal)) | ||
| .ToArray(); | ||
|
|
||
| // If the family ever disappears from the metadata this test proves nothing: fail loudly rather | ||
| // than pass vacuously. | ||
| Check.That(roslynReferences).Not.IsEmpty(); | ||
|
|
||
| string[] offenders = roslynReferences | ||
| .Where(reference => OnMajorMinorBuild(reference.Version) > floor) | ||
| .Select(reference => $"{reference.Name} {reference.Version}") | ||
| .ToArray(); | ||
|
|
||
| Check.That(offenders).IsEmpty(); | ||
| } | ||
|
|
||
| private static Version ReadFloor(Assembly analyzerAssembly) { | ||
| AssemblyMetadataAttribute floor = analyzerAssembly | ||
| .GetCustomAttributes<AssemblyMetadataAttribute>() | ||
| .Single(metadata => metadata.Key == "RoslynFloorVersion"); | ||
|
|
||
| return OnMajorMinorBuild(Version.Parse(floor.Value!)); | ||
| } | ||
|
|
||
| // Roslyn assemblies carry a four-part version (x.y.z.0) while the floor is written as x.y.z; comparing on | ||
| // major.minor.build only keeps a raw 4.8.0.0 from reading as newer than the 4.8.0 floor. | ||
| private static Version OnMajorMinorBuild(Version? version) => | ||
| new(version?.Major ?? 0, version?.Minor ?? 0, version is { Build: >= 0 } ? version.Build : 0); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,29 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <!-- Floor-SDK dogfood consumer. Deliberately NOT part of FirstClassErrors.sln: ci.yml would build it | ||
| under the .NET 10 SDK, which proves nothing and only causes confusion. It is built solely by the | ||
| "floor" job in .github/workflows/analyzers.yml, whose nested tools/floor-check/global.json selects | ||
| the .NET 8 (Roslyn 4.8) SDK. It recompiles the real Usage sources with the analyzer wired in, so if | ||
| FirstClassErrors.Analyzers ever references a newer Roslyn the analyzer fails to load on the floor | ||
| host (CS8032) and this build turns red. --> | ||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <IsPackable>false</IsPackable> | ||
| <!-- An analyzer that fails to load (CS8032) or throws while loading (AD0001) must break the build, | ||
| not merely warn. That failure is the entire signal this project exists to produce. --> | ||
| <WarningsAsErrors>$(WarningsAsErrors);CS8032;AD0001</WarningsAsErrors> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <!-- Reuse the dogfood sample's sources verbatim (no duplication); skip its own build output. --> | ||
| <Compile Include="../../FirstClassErrors.Usage/**/*.cs" | ||
| Exclude="../../FirstClassErrors.Usage/obj/**/*.cs;../../FirstClassErrors.Usage/bin/**/*.cs" /> | ||
| <ProjectReference Include="../../FirstClassErrors/FirstClassErrors.csproj" /> | ||
| <ProjectReference Include="../../FirstClassErrors.Analyzers/FirstClassErrors.Analyzers.csproj" | ||
| OutputItemType="Analyzer" | ||
| ReferenceOutputAssembly="false" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or 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,6 @@ | ||
| { | ||
| "sdk": { | ||
| "version": "8.0.100", | ||
| "rollForward": "latestFeature" | ||
|
Reefact marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.