Skip to content
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

Bug: Lint error: Expected linebreaks to be 'LF' but found 'CRLF' #299

Closed
2 tasks done
adiati98 opened this issue Dec 18, 2023 · 6 comments · Fixed by #301
Closed
2 tasks done

Bug: Lint error: Expected linebreaks to be 'LF' but found 'CRLF' #299

adiati98 opened this issue Dec 18, 2023 · 6 comments · Fixed by #301

Comments

@adiati98
Copy link
Member

adiati98 commented Dec 18, 2023

Describe the bug

When I worked on the constants.ts file, I get lots error messages: Expected linebreaks to be 'LF' but found 'CRLF'.
And this error happens in all TypeScript files.

Screenshot

Lint error

Suggestion

After did some research, I found the same problem, and it happens only for Windows users.

As I am using Windows 11, the solution to add the linebreak-style rule configuration for Windows in this thread works. I don't get these error messages anymore. Below is the code I tried to apply in the eslintrc.js:

rules {
  "linebreak-style": ["error", "unix"],
  "linebreak-style": ["error", "windows"],
}

However, I'm not sure if this would be a good solution.

Alternative Solution

Adding a line in a .gitattributes file as mentioned in the official eslint docs to make it easy for developers to contribute to the codebase from different platforms.

And here is another resources for adding a .gitattributes file.

Steps to reproduce

On VS Code in the Windows machine:

  1. Open any TypeScript file.
  2. Click "PROBLEMS" tab on panel bar.
  3. You will see lots of error: Expected linebreaks to be 'LF' but found 'CRLF' messages.

Browsers

Chrome

Additional context (Is this in dev or production?)

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Contributing Docs

  • I agree to follow this project's Contribution Docs
@adiati98 adiati98 added 🐛 bug Something isn't working 👀 needs triage labels Dec 18, 2023
@jpmcb
Copy link
Member

jpmcb commented Dec 18, 2023

I'm unsure if we would want to add a lint rule for windows line breaks since the majority of people at OpenSauced are on macs and we wouldn't want to change those with an accidentally --fix on that eslint rule (which from my understanding would change all line endings everywhere in the project).

My assumption is also that we can't mix and match line endings: we sort of need to choose one.

In the 'app' repo, we ignore line endings:

https://github.com/open-sauced/app/blob/6acd16dac46afbb2c94f49f5cd4fb2b9c64d5b2b/.eslintrc.json#L9

I wonder if that's the solution here.

@adiati98
Copy link
Member Author

I'm unsure if we would want to add a lint rule for windows line breaks since the majority of people at OpenSauced are on macs and we wouldn't want to change those with an accidentally --fix on that eslint rule (which from my understanding would change all line endings everywhere in the project).

My assumption is also that we can't mix and match line endings: we sort of need to choose one.

In the 'app' repo, we ignore line endings:

https://github.com/open-sauced/app/blob/6acd16dac46afbb2c94f49f5cd4fb2b9c64d5b2b/.eslintrc.json#L9

I wonder if that's the solution here.

Would the alternative solution (the eslint official docs that I included in the issue) work?

I didn't see and missed a pass on a semicolon rule because all I could see was these line-breaking errors everywhere. 😂

The --fix is not working with the current configuration on Windows. Whenever possible, I think it would be great to apply settings/configuration that can be used across platforms to accommodate contributors who use different systems than Mac. 🙂

I'm not at my computer atm, but I can try applying the ignore line endings and let you know how it works later. 😊

@adiati98
Copy link
Member Author

@jpmcb I've tested out by adding the prettier to ignore the line endings as you pointed out. But it doesn't fix anything.

So, I tried out adding a .gitattribute file as per eslint docs and follow this instruction on GitHub to set up the configuration. And it works.

As mentioned on GitHub:

When you're collaborating on projects with Git and GitHub, Git might produce unexpected results if, for example, you're working on a Windows machine, and your collaborator has made a change in macOS.

You can configure Git to handle line endings automatically so you can collaborate effectively with people who use different operating systems.

From what mentioned above, I think applying this won't affect line endings for Mac users.

@jpmcb
Copy link
Member

jpmcb commented Dec 19, 2023

Feel free to drop a PR with some proposed changes and I can take a look on my mac 👍🏼

Copy link

🎉 This issue has been resolved in version 1.14.3-beta.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Copy link

🎉 This issue has been resolved in version 1.15.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants