-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Need 'fix-all' for naming style violations. #14983
Comments
Clearing milestone - this is not an RC issue. |
@Pilchie -- I believe we were thinking of having a "one-click cleanup" button for this (which would fix all formatting and name/style violations). |
I would like both options. One to fixup everything. And one to fix that specific violation. |
Same! Almost every event handler I've ever written has been camel case. I'd like a way to update an entire solution. :D |
I'm still blowing so much time on fixing these and then running into more. |
I've had some thoughts about at least a partial fix all implementation, but haven't completed it yet. For example:
|
I'd be happy to see this implemented too. |
I also would like to see this implemented. |
that enhancement would really speed up fixing such places |
As long as it takes less time and attention than me doing it by hand, it's valuable to me no matter how long it otherwise takes to execute. |
at the very least an option to do this in code clean up for the page would alleviate some of the pain. If there is work around in the meantime that anyone could share, please let me (and i'm assuming others) know about it. Thanks |
Hi, |
For some of you struggling with renaming properties after generating them from JSON, which for me was the most common case of naming style violations, Visual Studio Code has support for modifying results from regular expression find, so you can use the find and replace tool:
This surely does not fix all other naming style violations, but I'm leaving this here in case somebody else is trying to find an alternative to renaming hundreds of camel case properties manually. |
This works in VS Code, but not Visual Studio. |
It happens every time I paste special JSON as Class. I need to then move all properties to upper. I found that Alt+Enter and then Enter again is somewhat "fast" if you don't have many classes. Mmm, I've just realized there might be a better "paste JSON as class" option online. |
Here is a simple PowerShell Core script to change the method names to the correct casing: $tokens = @() # Will retain all method names to change
# Build the set of method names as token to replace (in case methods are referred to across classes)
foreach ($txt in Get-ChildItem -Path . -Include @('*.cs') -Recurse) {
[array]$tokens += Select-String -Pattern '(?<=(public|private|protected|internal)+ [\w\[\]<>\s]+ )[a-z]\w+(?=\s*\()' -CaseSensitive -Path $txt | ForEach-Object { $_.Matches.Value } | Select-Object -Unique
}
# Replace all tokens
foreach ($txt in Get-ChildItem -Path . -Include @('*.cs') -Recurse) {
$tmp = Get-Content -Path $txt | ForEach-Object { if (-not [string]::IsNullOrEmpty($tokens)) { $_ -creplace "($($tokens -join '|'))(?=\()", { $_.Value[0].ToString().ToUpperInvariant() + $_.Value.Substring(1) } } } # Assign to temp to avoid file locking
Set-Content -Value $tmp -Path $txt
} If you want to preview the changes before committing them to disk: $tokens = @() # Will retain all method names to change
# Build the set of method names as token to replace (in case methods are referred to across classes)
foreach ($txt in Get-ChildItem -Path . -Include @('*.cs') -Recurse) {
[array]$tokens += Select-String -Pattern '(?<=(public|private|protected|internal)+ [\w\[\]<>\s]+ )[a-z]\w+(?=\s*\()' -CaseSensitive -Path $txt | ForEach-Object { $_.Matches.Value } | Select-Object -Unique
}
# Replace all tokens with preview
foreach ($txt in Get-ChildItem -Path . -Include @('*.cs') -Recurse) {
$before = Select-String -Pattern "($($tokens -join '|'))(?=\()" -Path $txt -CaseSensitive -AllMatches
$tmp = Get-Content -Path $txt | ForEach-Object { if (-not [string]::IsNullOrEmpty($tokens)) { $_ -creplace "($($tokens -join '|'))(?=\()", { $_.Value[0].ToString().ToUpperInvariant() + $_.Value.Substring(1) } } } # Assign to temp to avoid file locking
$after = $tmp | Where-Object -FilterScript { $_ -imatch "($($tokens -join '|'))(?=\()" } | Select-String -Pattern "($($tokens -join '|'))(?=\()" -AllMatches
$(for($i=0;$i -lt $before.Count; $i++) {
[PSCustomObject]@{
Before = $before[$i]
After = $after[$i]
}
}) | Format-Table -AutoSize -Wrap
Set-Content -Value $tmp -Path $txt -Confirm
} Result: Diff svejdo1/TreeDistance/compare/master...mavaddat:TreeDistance:master |
There doesn't seem to be much movement on this? Running a powershell script to update large amounts of code just doesn't seem like a good idea. Other than going one field at a time. What options exist? |
The Roslyn API is public. So you could write a console tool that loads your solution, then performs all the renames you want, one at a time. |
I believe I tried this before and ran into the issue of the NamingStyle settings being internal so you'd need to create a separate system. How can I read the CodeStyle and NamingStyle settings into something like a json file? |
I figured it out with reflection. if anyone wants to give it a try I made it open source. |
Any update on this? |
@Varorbc Nope. |
If you use a more sophisticated generator like http://app.quicktype.io then you get C# properties to C# naming standards, annotated with attributes (for Newtonsoft or STJ) to JSON standards. They (QuickType) also have a VS extension |
You should be able to avoid reflection by passing the settings in using .editorconfig format. The pattern would be similar to this: |
how in the world is this not an option with this many people asking for it ... what is going on here ... surely the people who even run this repo are dealing with this same problem ... how are they not making a change for this ... makes no sense |
@quantfreedom we're not running into the issue because our code matches the naming styles we've chosen. We also don't have a solution here as we don't know how to accomplish this efficiently. |
Is there a solution? |
Hi @jerviscui, you can check the discussion here for the current status of this feature from Visual Studio. |
Any update on this? |
It's just too tedious to have to manually fix up every violation one at a time.
The text was updated successfully, but these errors were encountered: