Skip to content

Detect line breaks in different OS #1894

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

luissmg
Copy link

@luissmg luissmg commented Jul 23, 2018

Check the following issue for reference.
#1893

@luissmg luissmg changed the title Detect different line breaks in different OS Detect line breaks in different OS Jul 23, 2018
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

This seems a fine improvement, despite CRLF being a terrible idea to use, even on Windows.

However, can you please add some tests for this?

@luissmg
Copy link
Author

luissmg commented Aug 3, 2018

Hi. Adding the tests right now. Do you want me to add tests for every case that exists right now but just change the line break?
Asking because there are already 800 lines of tests for this rule.

@ljharb
Copy link
Member

ljharb commented Aug 3, 2018

@luissmg we definitely don't need that many tests :-) one or two should probably suffice.

@luissmg
Copy link
Author

luissmg commented Aug 3, 2018

I thought just the same but wanted to confirm first :)

@luissmg
Copy link
Author

luissmg commented Aug 6, 2018

@ljharb Sorry for taking so long on this. Added the tests!

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

Thanks!

@ljharb
Copy link
Member

ljharb commented Aug 7, 2018

@luissmg altho it seems like the tests are failing

@luissmg
Copy link
Author

luissmg commented Aug 7, 2018

@ljharb I was checking and this test that I added is exactly the same as the one above that is passing, excepting for the type of line break.

Shouldn't it pass too or am I missing something?

Edit: the other test with \r is passing!

@ljharb
Copy link
Member

ljharb commented Aug 7, 2018

I suspect the failing test ends up with a mix of \r\n and \n, which seems like a problem. Perhaps the autofixer should detect the linebreak type most commonly used in the file, or in the node it’s looking at, and use that instead of always outputting a LF?

@grahammcculloch
Copy link

Hi. Would love to see this get merged 😄 Currently making me sad about my Windows machine!

@ljharb
Copy link
Member

ljharb commented Sep 14, 2018

It needs a rebase and fixed tests.

@luissmg
Copy link
Author

luissmg commented Sep 14, 2018

@ljharb @grahammcculloch Doing that this weekend!

@evertonfraga
Copy link

@luissmg any news? :)

countNewLinesBeforeContent = (child.raw.match(/^ *\n/g) || []).length;
countNewLinesAfterContent = (child.raw.match(/\n *$/g) || []).length;
countNewLinesBeforeContent = (child.raw.match(/^ *[\r\n|\r|\n]/g) || []).length;
countNewLinesAfterContent = (child.raw.match(/[\r\n|\r|\n] *$/g) || []).length;

Choose a reason for hiding this comment

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

I think you meant (\r\n|\r|\n) or [\r\n] since brackets will match anything inside, even pipes. The best regex for line endings is simply \r?\n. It will match both CRLF and LF. Matching only CR is not needed as it's not used anymore.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you so much for the tip! Will try to fix it this weekend

@luissmg
Copy link
Author

luissmg commented Dec 27, 2018

Hi guys. I will try to fix this in this weekend. Sorry for not replying any sooner.

@ljharb
Copy link
Member

ljharb commented Aug 9, 2021

@luissmg are you still interested in completing this PR?

@ljharb ljharb marked this pull request as draft August 9, 2021 21:09
@luissmg
Copy link
Author

luissmg commented Aug 10, 2021

Hi @ljharb! Sorry for letting this here in the air. I will try to push something this week. Will apply the suggestion from @sindresorhus and check if the tests are ok

@luissmg
Copy link
Author

luissmg commented Aug 16, 2021

Hey @ljharb, how are you? I took a look into this today. can you check if it is okay?

@ljharb
Copy link
Member

ljharb commented Aug 16, 2021

@luissmg unfortunately the tests don't fail, when your fix is removed.

@luissmg
Copy link
Author

luissmg commented Aug 17, 2021

@ljharb Hmmmm you are right... Could be that this problem is not a problem anymore?

@ljharb
Copy link
Member

ljharb commented Aug 20, 2021

It's entirely possible!

@ljharb ljharb force-pushed the master branch 4 times, most recently from deb3090 to a32f61e Compare November 10, 2022 22:51
@ljharb ljharb force-pushed the master branch 2 times, most recently from 59af733 to 865ed16 Compare November 11, 2022 02:45
@ljharb ljharb force-pushed the master branch 4 times, most recently from 069314a to 181c68f Compare November 18, 2022 17:19
@ljharb ljharb force-pushed the master branch 2 times, most recently from 380e32c to 51d342b Compare July 4, 2024 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants