-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Convert to file-scope namespaces #16539
Conversation
This pull request has merge conflicts. Please resolve those before requesting a review. |
As with other such PRs, it only makes sense if you configure an analyzer to guard against it, and make sure it actually fails the build in CI. |
We already have a suggestion for this in the Line 35 in 5c45566
warn instead of suggestion
|
@Piedone I changed the editor settings to warn against using block-scope namespaces. |
Please check if the CI build indeed fails. |
There is a way to prevent that, apply the same change in the files that are changed by every PR. Would take a script to do it, but it doesn't seem very hard, even more with the gh cli.
|
Seems to be passing. |
This approach sounds promising. But, I don't have much time to adventure with this approach. If you have the time, adding this script will be time saver for the PR. |
I mean, it should fail if there's a non-compliant file. Changing the .editorconfig doesn't guarantee you'll see the same behavior in CI. |
I remembered Seb against this change in the past, because it will break every PR, it would be nice to add this incrementally and new PRs |
@Piedone I added CI to ensure important formatting is apply on the PR CI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be good, but indeed with some help for PR authors, at least with a comment with guidelines under each (I think just "1. dotnet format
2. commit/push and don't be afraid that all files changed 3. merge" should be enough).
@Piedone look at my last commit. I expected the build to fail since the |
See #16539 (comment) |
This pull request has merge conflicts. Please resolve those before requesting a review. |
Maybe also consider ignore revisions configuration for Git after this has been merged: sebastienros/jint@a08f452 |
@lahma that sounds like a good idea. But I think we have to do it after we merge this PR to get the hash or the merge-squash commit so we can add it to the |
Yes, I believe you need to merge this first and then add he file when you know the exact hash in the repo. |
.gitattributes
Outdated
@@ -1,7 +1,4 @@ | |||
* text=auto | |||
*.cs eol=crlf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will still be necessary, see Lombiq/.NET-Analyzers#71. The other two I don't think so, so OK to remove those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
text=auto is supposed to do the conversion automatically. I don't think it's a good idea to force crlf.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And each extension can be forced for a specific format (text or binary)
Examples:
https://github.com/dotnet/dotnet/blob/main/src/aspire/.gitattributes
https://github.com/dotnet/dotnet/blob/main/src/aspnetcore/.gitattributes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a Roslyn bug: dotnet/roslyn#55526
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read the comments, and they don't seem to imply there is a bug, I don't think so either. Sam correctly mentions the end_of_line should not be forced and that's it:
It also needs to remove this from .editorconfig and there won't be conflicting behaviors.
end_of_line = crlf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mike did the changes, the CI is green. I also cloned on Linux after these changes, did a dotnet format and no files were updated.
And it's LF:
00000000: 7573 696e 6720 5379 7374 656d 3b0a 7573 using System;.us
00000010: 696e 6720 5379 7374 656d 2e43 6f6c 6c65 ing System.Colle
00000020: 6374 696f 6e73 2e47 656e 6572 6963 3b0a ctions.Generic;.
00000030: 7573 696e 6720 5379 7374 656d 2e43 6f6c using System.Col
00000040: 6c65 6374 696f 6e73 2e49 6d6d 7574 6162 lections.Immutab
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll see :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a possibility there will be some glitches, but I think only from files that are incorrectly tagged as text vs. binary, or some which are currently cr-lf but should be lf only (web assets for instance).
I can have a look at one of the repositories where you have had the issue if you want and see if I can understand why you are getting problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me the recommendation is to enforce the same line ending everywhere and not let the platform handle it: dotnet/roslyn#55526 (comment) I don't particularly like this, but we're actually doing that in the Lombiq repos (including end_of_line = crlf
in the .editorconfig) and it works reliably, no issues since then.
But perhaps indeed if we removed all of this then it'd also work.
This was a problem with all of our projects using https://github.com/Lombiq/.NET-Analyzers, i.e. where these props and config files are loaded. Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please help PR authors though: #16539 (review)
I think all the anthers needs to do is run the following command in their PRs
Then maybe also We would have to merge this one, then try the above steps on some of the PRs to see if that fixes everything or if we need to other steps. The problem is that most of the current PRs already have merge conflicts. and trying to fix them with the above two commands may not be easy. But either way, they should start with the above commands, and they fix the per-existing merge conflict. |
Don't tell me, tell the PR authors :). |
After we merge this, I'll attempt to fix a PR and provide steps for the others to follow. |
@Piedone if you are good with the last changes, please merge this PR. Otherwise, please provide more feedback. |
Yes this will cause a conflict for every PR we have. However, the current PRs seems to have no activities for a while.
If any PR need to fix it's merge conflicts, simply convert the conflicted files to file-scope namespaces or use this command
Note to reviewers, since it would be crazy to review 3.5k files, I run the following command
Then made the changes to the following files:
.editorconfig
changed thecsharp_style_namespace_declarations
to warning..editorconfig