2

My local development environment based on Windows and my production environment based on Linux.

I have an issue about "line separators (CR, LF, CRLF)". Every time I got blank lines in my code.

Which line separator type to should I choose for prevent the blank lines?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Ed Joe
  • 307
  • 1
  • 2
  • 6
  • I'd say -- go for Linux style (LF) -- it works fine on Windows (at least for PHP development -- I have no issues with using them, plus, one of the PSR recommends using them). Question is -- at what stage do you get blank lines? From your description it sounds like you are using FTP/SFTP and it happens at that stage. This is most likely is cased by your FTP server configuration that adds such extra breaks. Some links: 1) https://intellij-support.jetbrains.com/hc/en-us/community/posts/207053695-File-Comparison-to-not-take-into-account-line-endings- 2) https://youtrack.jetbrains.com/issue/WI-9103 – LazyOne Dec 19 '16 at 10:42
  • 1
    On related note: http://stackoverflow.com/a/40472391/783119 – LazyOne Dec 19 '16 at 10:43

1 Answers1

0

I am working in this exact environment as well, except my development environment is also in Linux.

The aggravating problem I have run into is editing CRLF text files in the Linux environment, whether they were Apache files, or shell scripts. Mainly, I couldn't easily edit them in Linux through vi, which is unhappy with the CR. If you never do that, then it may not be a problem for you. But if you see blank lines in your code, it might be something similar.

For HTML and PHP, Apache running in the Linux environment has never complained when serving up files or reading configuration files in CRLF.

The other side of it, was that it was hard to wrangle PHPStorm. The related post @LazyOne provided works, but PHPStorm is stubborn if you have been using CRLF as I had when I switched this setting. I found I still needed to change files by hand at times, which you can do along the bottom right of the editor window. You will see CR, LF or CRLF and you can click and change the setting for the particular file loaded in the editor:

enter image description here

As a side note, if you use git, you can set up a .gitattributes file in the project directory with this:

# Set the default behavior to always be linefeed for linux
* text eol=lf

Which causes git to normalize to LF as it states in the git documentation:

Set to string value "lf"

This setting forces Git to normalize line endings to LF on checkin and prevents conversion to CRLF when the file is checked out.

Community
  • 1
  • 1
Katie
  • 2,594
  • 3
  • 23
  • 31