How to make IntelliJ IDEA insert a new line at every end of file?

Intellij IdeaLinefeed

Intellij Idea Problem Overview


How do I make IntelliJ IDEA insert a new line at every end of file, so that GitHub doesn't complain for example?

Intellij Idea Solutions


Solution 1 - Intellij Idea

Change your Editor settings:

Settings → Editor → General → Ensure line feed at file end on Save

Solution 2 - Intellij Idea

For MAC users:

Preferences > Editor > General > Ensure line feed at file end on save

Solution 3 - Intellij Idea

IntelliJ IDEA 2016.3

Approach 1

File > Settings... > Editor > General > Ensure line feed at file end on Save

File > Settings

Editor > General > Ensure

Approach 2

Help > Find Action... (Ctrl+Shift+A) > type "Ensure line feed" > switch the toggle to ON (using the mouse click or Enter) for "Other: Ensure line feed at file end on Save" line

Help > Find Action

Ensure line feed

Solution 4 - Intellij Idea

Possible alternative with a number of handy features is EditorConfig

Just submit an .editorconfig file to your repo

[*]
insert_final_newline = true

And it will work natively not only in Idea, but in all major IDEs (some require a plugin).

Now all team members would have same configuration, eol, eof, and no more tabs vs spaces :)

Solution 5 - Intellij Idea

For Mac Users: IntelliJ Idea version 2020.2

Option1:

IntelliJ Idea -> Preferences -> General -> Ensure an empty line at the end of a file on save enter image description here

Option2:

⬆️ + ⌘ + A or Or just click on Help from menu bar -> Find Action and then type Ensu and choose Ensure an empty line at the end of a file on save enter image description here

Solution 6 - Intellij Idea

General -> Save Files For IntelliJ IDEA 2020.

Check the Bottom Right Corner: screenshot

Solution 7 - Intellij Idea

In latest versions of IntelliJ, the setting has been renamed to 'Ensure an empty line at the end of a file on save', and it has been moved under Setting>Editor>General>Save Files

enter image description here

This should have been a comment, but I wanted to add the screenshot as well so wrote as an answer.

Solution 8 - Intellij Idea

As Rider (IDEA's cousin for .NET) is driving me crazy, this might be helpful for those writing C# as Ensure line feed at file end on Save alone won't work. It needs

File → Settings → Editor → Code Style → C# → Line Breaks and Wrapping → Line feed at end of file.

I don't remember changing it and I haven't imported any settings for sure, so I guess it's by default disabled.

Rider settings

Solution 9 - Intellij Idea

With the IntelliJ Idea version 2020.3: Go to File > Sttings > Editor > General > On Save

And then select/deselect "Ensure every saved file ends with a line break"

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNightRaView Question on Stackoverflow
Solution 1 - Intellij IdeaNightRaView Answer on Stackoverflow
Solution 2 - Intellij IdeancubicaView Answer on Stackoverflow
Solution 3 - Intellij IdeaROMANIA_engineerView Answer on Stackoverflow
Solution 4 - Intellij IdeasbedulinView Answer on Stackoverflow
Solution 5 - Intellij IdeabhordupurView Answer on Stackoverflow
Solution 6 - Intellij Ideaakhilrawat001View Answer on Stackoverflow
Solution 7 - Intellij IdeaAbhishek SinghView Answer on Stackoverflow
Solution 8 - Intellij IdeaStelios AdamantidisView Answer on Stackoverflow
Solution 9 - Intellij IdeajascadevView Answer on Stackoverflow