File-based apps: extend "missing shebang" analyzer to #:ref directives#54553
Open
jjonescz wants to merge 2 commits into
Open
File-based apps: extend "missing shebang" analyzer to #:ref directives#54553jjonescz wants to merge 2 commits into
#:ref directives#54553jjonescz wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Extends the MissingShebangInFileBasedProgram analyzer (CA2266) so it also flags entry-point files that contain #:ref directives without a shebang line, mirroring the existing behavior for #:include. Tests across the run-file/convert suites are updated to add the shebang where appropriate, and analyzer unit tests are parameterized to cover the new directive. #:project and #:package are explicitly verified to NOT require a shebang.
Changes:
- Renames
IsIncludeDirectivetoIsShebangRequiringDirectiveand matches bothincludeandrefvia a smallIsDirectivehelper. - Parameterizes analyzer unit tests with
[Theory]/[InlineData]to coverinclude,ref,project, andpackagedirective variants. - Adds shebangs to existing run-file and project-convert tests that use
#:ref, plus a newMissingShebangWarning_RefDirectiveintegration test; updates expected error line numbers (1 → 2).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Microsoft.CodeAnalysis.NetAnalyzers/src/Microsoft.CodeAnalysis.CSharp.NetAnalyzers/Microsoft.NetCore.Analyzers/Usage/CSharpMissingShebangInFileBasedProgram.cs | Extends shebang-required detection to include #:ref in addition to #:include. |
| src/Microsoft.CodeAnalysis.NetAnalyzers/tests/.../Usage/MissingShebangInFileBasedProgramTests.cs | Parameterizes analyzer tests; adds package/project no-diagnostic cases and ref warning/codefix cases. |
| test/dotnet.Tests/CommandTests/Run/RunFileTests_BuildOptions.cs | Adds a new integration test asserting CA2266 fires for a #:ref entry point and disappears once a shebang is added. |
| test/dotnet.Tests/CommandTests/Run/RunFileTests_Directives.cs | Adds shebangs to existing #:ref tests and updates expected directive error line number. |
| test/dotnet.Tests/CommandTests/Run/RunFileTests_General.cs | Adds shebangs and bumps expected error line for #:ref tests. |
| test/dotnet.Tests/CommandTests/Run/RunFileTests_CscOnlyAndApi.cs | Adds shebangs to entry-point sources that use #:ref. |
| test/dotnet.Tests/CommandTests/Project/Convert/DotnetProjectConvertTests.cs | Adds shebangs to dotnet project convert test inputs that use #:ref. |
5 tasks
Member
Author
|
@333fred @RikkiGibson for reviews, thanks |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Resolves #53749.
Corresponding doc update: dotnet/docs#54120