Skip to content
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

Use file-scoped namespaces #9619

Merged
merged 4 commits into from
Dec 12, 2024

Conversation

drewnoakes
Copy link
Member

@drewnoakes drewnoakes commented Dec 11, 2024

In our team meeting today we agreed to convert the repository to use file-scoped namespaces through the repo.

Since the feature was added to C#, we have been using it in new files, and adding it to old files when working on them.

This approach has two downsides:

  • It makes the diff harder to review when a PR makes actual changes along with introducing file-scoped namespaces, as almost every line in the file appears as changed.
  • Given we now have a mix of styles, it's harder to tell whether a method is indented twice because it's in a nested class or in a block-scoped namespace.

We decided to bite the bullet and make this change in one go across the entire repository.

This PR also adds a .git-blame-ignore-revs file that tells git to ignore the particular commit in git blame operations, meaning this PR won't be displayed in blame views.

We use the .editorconfig file to set the use of block-scoped namespaces as an error, to prevent their use in future.

Microsoft Reviewers: Open in CodeFlow

Excludes a few changes that break some of our columnar alignment.
This change was applied automatically in VS, via the Roslyn codefix.
This file tells git/GitHub to ignore certain commits from the blame view.

The file is configured to exclude a recent solution-wide conversion from block-scoped to file-scoped namespaces, which touched most lines in the repo. With this, GitHub's blame view will ignore the change, making browsing changes on GitHub easier.
@drewnoakes drewnoakes requested a review from a team as a code owner December 11, 2024 01:41
Copy link
Contributor

@melytc melytc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks for doing this :)

@drewnoakes drewnoakes merged commit 24eabd0 into dotnet:main Dec 12, 2024
5 checks passed
@drewnoakes drewnoakes deleted the use-file-scoped-namespaces branch December 12, 2024 00:30
@dotnet-policy-service dotnet-policy-service bot added this to the 17.12 milestone Dec 12, 2024
@drewnoakes
Copy link
Member Author

VS's CodeLens doesn't respect the .git-blame-ignore-revs file. I filed a bug about that here: https://dev.azure.com/devdiv/DevDiv/_workitems/edit/2325242

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants