Reputation: 11841
How do I make IntelliJ IDEA insert a new line at every end of file, so that GitHub doesn't complain for example?
Upvotes: 445
Views: 149143
Reputation: 181
With the Intellij version 2022.3.1
Preferences (cmd+,) -> Editor -> General -> Ensure every saved file ends with a line break
Check, apply, and click ok
Upvotes: 4
Reputation: 11841
Change your Editor settings:
Settings
→ Editor
→ General
→ Ensure every saved file ends with a line break
Upvotes: 683
Reputation: 8495
For MAC users:
Preferences > Editor > General > Ensure every saved file ends with a line break
Upvotes: 118
Reputation: 29
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"
Upvotes: 1
Reputation: 960
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
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
Upvotes: 26
Reputation: 953
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
This should have been a comment, but I wanted to add the screenshot as well so wrote as an answer.
Upvotes: 6
Reputation: 119
General -> Save Files For IntelliJ IDEA 2020.
Check the Bottom Right Corner:
Upvotes: 6
Reputation: 2041
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.
Upvotes: 5
Reputation: 56724
File > Settings... > Editor > General > Ensure line feed at file end on Save
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
Upvotes: 52
Reputation: 4360
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 :)
Upvotes: 61