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
Add auto-fixing to padded-blocks #6320
Comments
This seems like a reasonable request to me, though I'm sure where we stand regarding auto-fixing newlines (see #5958 (comment)). Thoughts @eslint/eslint-team? I'd be happy to take this on if we decide it's a good idea. |
Actually I have a branch where I was trying to implement this, and it lead me to that comment and other concerns raised in #6298. Even if we decide those are not a problem, it's not trivial to remove linebreaks, because they might not be |
"line breaks (better: newlines) can be one of Carriage Return (CR, \r, on older Macs), Line Feed (LF, \n, on Unices incl. Linux) or CR followed by LF (\r\n, on WinDOS).
Therefore, the most efficient RegExp literal to match all variants is
/\r?\n|\r/"
Source stackoverflow: http://stackoverflow.com/a/10805292
|
Whoops, my first response should have read "not sure where we stand..." |
Btw, it was great, to have fix for this) |
@alberto Yeah, that makes sense. Any reasons you can think of why the regex solution might not work for removing newlines? Still doesn't solve the problem of adding the right type newline, but that gets back to the discussion happening in the other issue I pointed to earlier (and the one you mentioned). |
Guys, here is the snippet to detect proper line endings in node: typeof process != 'undefined' && 'win32' === process.platform ? '\r\n' : '\n' |
@glebmachine that isn't accurate. Windows users can use Linux line endings and Linux users can use Windows line endings. You can't make assumptions about this based on the platform. Removing line breaks can be done with a regex, it's the insertion that is the problem here. |
@nzakas In this uncommon case you can check file for used line endings. |
@kaicataldo @nzakas re: removing linebreaks. Unless I am missing something here, it can't be done directly with a regex. To create a fixer you have to provide a range to remove, and you can't get the exact range of the linebreak without resorting to something like what's done in #6226. |
Could always look how JSCS 2.0 (pre-CST) does this fix. |
Re: inserting newline, just take the first matching newline in the file or a sensible os default. |
@lukeapage yes, basically. |
@lukeapage @mikesherov Makes sense to me! |
If we decide inserting the wrong linebreak is not a problem to us (even if |
As I understand it, it would match the type of the first line break it finds. There is of course the edge case where there might not be any newlines, but that I think that would be pretty rare... |
Cheers!! |
Please, add auto-fixing for padded-blocks option
The text was updated successfully, but these errors were encountered: