Search code examples
editorconfig

What does the insert_final_newline EditorConfig option actually do?


As far as I'm concerned, there are the following options when it comes to the "final newline" in a file (considering only Unix-style line endings and disregarding Classic MacOS and DOS, for now):

  1. No final newline character:
    first line\n
    last line
    
  2. Newline character at the end of the last line:
    first line\n
    last line\n
    
  3. A whole final new line:
    first line\n
    last line, except not really\n
    \n
    

Which ones of these exactly are achieved by setting insert_final_newline to true and false, respectively, in .editorconfig?


Solution

  • if setting insert_final_newline to true:

    Fix this A whole final new line:

    if setting insert_final_newline to false:

    1. No final newline character:

      first line\n
      last line
      

    Sorry, let me make one correction!

    if setting insert_final_newline to true:

    1. Newline character at the end of the last line:

      first line\n
      last line\n
      

    Original text:

    enter image description here

    Hex shows the following, 0D0A is \r\n

    enter image description here