To add in Schenider21’s and Eric5h5’s answers:
Line endings
CR+LF (Carriage return and Line Feed [ /r/n ]) are for Windows
LF (Line Feed [ \n ]) are for Linux and newer Mac / OSX versions (version 10 and above)
CR (Carriage Return [ \r ]) are for old Macs (version 9 and earlier).
The Problem
Usually as what they’ve mentioned, what happened here is that you have intermixed either one or more of the line ending types specified above. You can noticeably see this when you create a new C# script from the assets editor menu. The default script template is currently in LF, so if you’re using Windows (CR+LF), and overwrite the script, you now have a mixture of LF and CR+LF line endings, leading to said warnings.
You can also experience this if you’ve copy-pasted a code snippet from somewhere in the web, which could contain different line endings. If you have a script with CR+LF line endings, and you pasted a snippet containing CR endings, you now have a mixed line ending file with CR+LF and CR endings.
Why even bother?
At first glance it just seems pointless but as Eric5h5 have mentioned, this can lead to mysterious problems later on. The only thing some people who have not bothered to deal with it think that it doesn’t make any difference is that they haven’t been in one situation where line consistency is tantamount. Even so, when left alone without any action for too long, it can be extremely frustrating to get those warnings in Unity and receive a popup in Visual Studio every damn time you open the script with mixed endings.
Another notable problem you can get from this is if you’re using version control, which (depending on the system) will either complain or perform unwanted behaviors if your files contain mixed line endings.
Other Solutions
You can just solve this of course by selecting the line ending you want using your code editor (a popup will appear if you’re using VS) and selecting to convert, but if you have a lot of scripts in your project, that could get annoying and tiresome pretty quickly. One good suggestion Ryiah had mentioned was to edit the script template and replace it with your own script with your desired line ending.
My Solution
I really hate shameless advertising or anything, but I figured I might as well share a lightweight editor tool I made called Consistent Line Endings, since it’s…well, for free
It basically scans for line endings in your files (it supports a wide variety, including even shaders, compute files, etc), and normalizes and converts them for you. You can choose one of the three line endings–CR, LF, or CR+LF. If your file contains a mixture of them, everything will be fixed.
Using it, you can start fixing line endings either manually (right-click in project view, then choose normalize all files) or automatically (every time you make a change in your scripts, it automatically converts all of it for you). So basically, it’s your choice. Plus, it even outputs a log containing info about the conversion process, so you could check what line ending types do your files have previously if you want. You can also filter certain extensions that you want to convert and those that you don’t.
So far, this tool helped me to get rid of those annoying warnings and popups, so I wanted to share it to anyone who’s having the same problem. It’s completely free so if you want to give it a try, go ahead and get it here. 