https://kotlinlang.org logo
k

Kirill Zhukov

03/11/2019, 4:06 PM
Is there a way to enable final newline (at the end of the file) in Kotlin code style settings? Can’t find it 🤔
m

Mike

03/11/2019, 4:50 PM
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

Kirill Zhukov

03/11/2019, 5:00 PM
Makes sense
Thanks!
m

Marc Knaup

03/11/2019, 5:31 PM
Would be great to have that as part of the project settings committed to Git
m

Mike

03/11/2019, 6:00 PM
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

Marc Knaup

03/11/2019, 6:01 PM
yeah, getting gitignore files to just allow the right IDEA files is tricky 😄
r

robstoll

03/11/2019, 7:39 PM
in case you haven't heard of it yet, https://editorconfig.org/
k

Kirill Zhukov

03/11/2019, 8:22 PM
So I have the EditorConfig plugin installed and
insert_final_newline=true
but that does’t seem to affect IDEs code style formatter
r

robstoll

03/11/2019, 8:23 PM
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

Kirill Zhukov

03/11/2019, 8:38 PM
I’ve had plugin for a while
let me check that flag though
yup, enabled
r

robstoll

03/11/2019, 8:40 PM
it does it on save in my case
p

Paul Woitaschek

03/12/2019, 6:02 PM
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
11 Views