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
Roslynator fix doesn't fix all instances of long line diagnostic (RCS0056) #1182
Comments
Hi, Thanks for the feedback 👍. Fixer for this diagnostic needs to be improved. The reason why it does not fix all lines is that it's not trivial to determine how to wrap a line. And when I'm talking about wrapping a line I mean to format it so it's not too long but it looks nice and it's readable (not just inserting a newline at nearest location to make it short enough). Could you send a link to a repo so it's possible to reproduce it? Code fix provider: |
Ah I suspected this 😃 some of the instances that are left behind are long strings, which as you say, are difficult to wrap sensibly as you wouldn't want to e.g., cut a word in half. Hmm... I'll probably need to do some manual hacking then :) unfortunately this is an internal repo so can't really share a link. Thanks for this tool though, it's really useful! |
I'm glad you like Roslynator! Maybe you can send just some lines which were not wrapped but look like they could be wrapped (not the long literals). Then possibly the fixer could be improved for these cases. |
For some of them it feels like it should be possible to have a sensible wrapping. For example, this one:
It has quite a bit of space for indentation, but it should be possible to wrap after the equals (I'm using 120 as the limit), and then wrap on every argument to the method. I have a similar example but with a function signature. I can manually wrap it by just dropping every argument into their own line, which I think is uncontroversial, but it's not doing it automatically at the moment. |
Yeah, this case should be fixable. |
Fair :) if I have some time tonight I'll try to reproduce this in a public repo and see if I can help with producing a fix. |
Just to add a bit more data to this, one of them is fairly easy to replicate. Example with a concrete bit of code from one of my pet projects: public ActivePlayer? GetPlayerInGame(
string username,
string gameSessionId,
string hubConnectionId)
{
using var context = new GameDbContext();
return context.ActivePlayers.FirstOrDefault(p => p.PlayerName == username && p.CurrentGame.Id == gameSessionId && p.ConnectionId == hubConnectionId);
} I added a bunch of whitespace before the Will see if I can figure out how to have a go at fixing this... |
The easiest way to find out is to add test with your code snippet and see the result. |
Yeah, I think this reproduces it: public async Task Test_Assignment()
{
await VerifyDiagnosticAndFixAsync(@"
class C
{
static string foo()
{
[| string x = foo();|]
return null;
}
}
",
@"
class C
{
static string foo()
{
string x
= foo();
return null;
}
}
");
} This is with the original 125 max line length. 125 is right after the But I get the following output:
|
The problem is with the following line: int indentation = SyntaxTriviaAnalysis.GetIncreasedIndentationLength(node); where I made the PR which should solve this issue. |
But this issue with the indentation shouldn't have anything to do with the code fixer for RCS0056 (on condition that the indentation is increased/decreased by single step, which is common case). |
So I don't know... but using your PR branch, and re-running my test above, I can get it to pass by tweaking the indentation a bit. |
Your code sample is part of the PR and it's passing: |
PR is complete. Please make any further development on the PR branch before it's merged. |
merged #1188 |
Product and Version Used: Roslynator CLI 0.6.1.0 with Roslynator Analyzer 4.4.0
Steps to Reproduce:
Add the following to .editorconfig:
Run
roslynator fix
against a large project, with >1000 instances of lines longer than 120.Actual Behavior:
When doing this, Roslynator will fix a bunch of lines in a bunch of files (around 500), but leaves many hundred behind.
When I run
roslynator analyze
, it clearly finds the ones that still have long lines, but refuses to fix them.In fact, if I run
roslynator fix
again, it also finds them but leaves them behind underUnfixed diagnostics
. It's unclear why these are unfixed... and I'd really like it for it to pick up all the ones it needs fixing, as fixing them all by hand will be painful.The text was updated successfully, but these errors were encountered: