Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Format

on:
pull_request:
branches:
- main
types:
- opened
- reopened
- synchronize

permissions:
contents: read

concurrency:
group: format-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
format:
name: dotnet format
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
persist-credentials: false

- uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4
with:
dotnet-version: '10.0.302'

- name: Verify formatting and code style
id: verify
run: dotnet format CSharpDriver.sln --verify-no-changes

- name: Show how to fix
if: failure() && steps.verify.outcome == 'failure'
run: |
echo "::error::Formatting or code style issues found. Run 'dotnet format CSharpDriver.sln' locally and commit the result."
echo "Some violations cannot be fixed automatically and have to be corrected by hand."
19 changes: 19 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@ Restrict to one target with `--framework`:
dotnet test --framework net10.0
```

### Formatting and code style

Formatting and code style come from `.editorconfig`. Most of it is reported by your IDE as you type, and some of it fails the build — but a few rules can only be checked by `dotnet format`, so CI runs it on every pull request.

Check your changes, and fix them:

```zsh
dotnet format CSharpDriver.sln --verify-no-changes
dotnet format CSharpDriver.sln
```

Some violations cannot be fixed automatically by `dotnet format` and have to be corrected by hand.

Scoping the check to a single project is quicker than running it over the whole solution:

```zsh
dotnet format src/MongoDB.Bson/MongoDB.Bson.csproj --verify-no-changes
```

## Submit a PR

Push your branch to your fork once all tests pass. [Squash multiple commits into one](https://stackoverflow.com/questions/5189560/how-do-i-squash-my-last-n-commits-together) and rebase on the latest upstream first (use the "Sync fork" button on your fork's page).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,7 @@ private static AstFilter TranslateStringIndexOfComparison(TranslationContext con
var anyOfExpression = arguments[0];
anyOf = anyOfExpression.GetConstantValue<char[]>(containingExpression: expression);
}
else
if (method.IsOneOf(StringMethod.IndexOfWithCharOverloads))
else if (method.IsOneOf(StringMethod.IndexOfWithCharOverloads))
{
var valueExpression = arguments[0];
var value = valueExpression.GetConstantValue<char>(containingExpression: expression);
Expand Down
Loading