Is there a way to enable final newline (at the end...
# intellij
k
Is there a way to enable final newline (at the end of the file) in Kotlin code style settings? Can’t find it 🤔
m
That’s a general editor setting. Editor..General. Under
Other
.
Ensure line feed at file end on Save
. I don’t think it allows it by language. It’s either all files or no files
k
Makes sense
Thanks!
m
Would be great to have that as part of the project settings committed to Git
m
I’ve used Detekt for that (sort of). Set the ‘all files must have blank line at end’. First time someone gets that, they hopefully ask, and update their settings. But yes, project settings in Git is a good alternative. Thus far I haven’t experimented with that. Always been nervous about committing IntelliJ files of any sort into the project as the wrong one committed can cause all sorts of hard to explain/diagnose problems.
m
yeah, getting gitignore files to just allow the right IDEA files is tricky 😄
r
in case you haven't heard of it yet, https://editorconfig.org/
k
So I have the EditorConfig plugin installed and
insert_final_newline=true
but that does’t seem to affect IDEs code style formatter
r
it works for me, have you restarted idea after you installed the plugin?
also make sure it is actually enabled (Settings -> Code Style -> Enable EditorConfig support)
k
I’ve had plugin for a while
let me check that flag though
yup, enabled
r
it does it on save in my case
p
It's annoying with detekt and Autoformat. I.e. sometimes I have 2 new lines at the end of a file and intellijs auto format doesn't remove them but detekt complains so I have to remove them manually