[dotnet] Add linting support with configurable dotnet format#16999
[dotnet] Add linting support with configurable dotnet format#16999titusfortner merged 5 commits intotrunkfrom
Conversation
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||||||
There was a problem hiding this comment.
Pull request overview
This PR enhances the .NET binding's linting and formatting capabilities by making the dotnet format tool configurable and separating fast formatting from comprehensive linting. Building on PR #16986, it introduces argument passing to allow different format modes (whitespace, style, analyzers) and optimizes the format script to run only whitespace formatting (~30s) instead of full linting (~100s). The PR also enforces file-scoped namespace declarations via .editorconfig and applies this formatting rule across the codebase.
Changes:
- Added configurable argument passing to dotnet format bazel target for both Unix and Windows scripts
- Optimized
format.shto run whitespace-only formatting for faster execution - Created separate rake tasks:
dotnet:format(whitespace-only) anddotnet:lint(full linting) - Enforced file-scoped namespace style by changing
.editorconfigseverity from suggestion to error - Applied the file-scoped namespace formatting to
WebElementWrapper.csas an example
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/private/dotnet_format.bzl | Modified to accept and pass command-line arguments to dotnet format via $@ (bash) and %* (Windows) |
| scripts/format.sh | Updated to invoke dotnet format with whitespace argument for performance optimization |
| rake_tasks/dotnet.rake | Added format task (whitespace-only, no args) and lint task (full linting with optional args) |
| dotnet/.editorconfig | Changed csharp_style_namespace_declarations from suggestion to error to enforce file-scoped namespaces |
| dotnet/test/common/WebElementWrapper.cs | Converted from block-scoped to file-scoped namespace declaration with adjusted indentation (formatting-only change) |
c8f63ad to
76b3ec3
Compare
User description
Figuring out how to get linting and formatting working across project
💥 What does this PR do?
In #16986 I added support for dotnet's format feature, but it hard coded one setting.
This PR allows the user to pass in parameters just like to native format:
The previous also added dotnet to format.sh which adds about 100 seconds to execution.
This PR only runs:
bazel run //dotnet:format -- whitespacewhich is about 30 seconds.This PR then wraps the typical features with:
./go dotnet:format- runs whitespace-only formatting./go dotnet:lint- runs full format + style + analyzersFinally, @nvborisenko created
dotnet/.editorconfiglast year, I set it to error so it would fail the lint job.🔧 Implementation Notes
Whitespace-only mode is ~3x faster than full linting, making it suitable for the general
format.shscript while full linting can be run separately.💡 Additional Considerations
This is a precursor to a final lint PR that makes sure everything is handled consistently across bindings and properly run by CI.
More things can be enforced by
.editorconfignow if you want (@RenderMichael / @nvborisenko)🔄 Types of changes
PR Type
Enhancement, Tests
Description
Add configurable dotnet format with argument support
Implement separate format (whitespace) and lint (full) tasks
Apply linting results to codebase with namespace declarations
Enforce file-scoped namespace style via .editorconfig
Diagram Walkthrough
File Walkthrough
dotnet_format.bzl
Add argument passing to format targetdotnet/private/dotnet_format.bzl
format
$@(bash) and%*(batch)parameters
dotnet.rake
Implement format and lint rake tasksrake_tasks/dotnet.rake
formattask that runs whitespace-only formatting via bazellinttask that runs full format with style and analyzersarguments
format.sh
Limit format.sh to whitespace modescripts/format.sh
bazel run //dotnet:formattobazel run//dotnet:format -- whitespace.editorconfig
Enforce file-scoped namespace as errordotnet/.editorconfig
csharp_style_namespace_declarationsseverity from suggestionto error
WebElementWrapper.cs
Apply file-scoped namespace formattingdotnet/test/common/WebElementWrapper.cs
syntax
file-scoped namespace