Add settings to remove trailing newlines #269

Open
danielcompton opened this Issue Sep 8, 2016 · 8 comments

Projects

None yet

4 participants

@danielcompton
danielcompton commented Sep 8, 2016 edited

It would be handy to be able to trim any extra trailing newlines from the end of a file, so there is always just one final newline. I'm not sure if this would be behaviour that would be added to insert_final_newline or whether it would be another setting.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@xuhdev
Member
xuhdev commented Sep 8, 2016

If you set insert_final_newline=false, final newlines should be removed. If it is unset or set to something random such as none, then it should not be touched.

@danielcompton

Are you sure? The docs on the website say

insert_final_newline: set to true to ensure file ends with a newline when saving and false to ensure it doesn't.

They don't seem to say anything about extra trailing new lines?

@xuhdev
Member
xuhdev commented Sep 8, 2016

Ah, sorry I didn't notice that you meant extra newlines! I can look into this, but this feature is probably limited by what editors provide us.

@jedmao
Member
jedmao commented Sep 8, 2016

Yep. I think this comes down to the name insert_final_newline, which is an action of inserting a line, not removing 1 or more lines from the end of a document. It's not supposed to support line removals, which means the only way to achieve that would be to introduce a new rule or rename this existing rule into something more meaningful and deprecate the older name.

@MikeChou

Maybe add another setting called 'remove_duplicate_final_newlines'.

The whitespace package of Atom editor combines two settings as one called 'ensure single trailing newline'. But two settings can provide more functions than one (by combinations of these two settings).

@xuhdev
Member
xuhdev commented Oct 25, 2016 edited

If we use a new name, how would we deal with its compatibility with insert_final_newline then? The best way for me is add a new legal value single to insert_final_newline to ensure only one single final new line is there.

@jedmao
Member
jedmao commented Oct 25, 2016

@xuhdev, I like that suggestion the best; though, a new rule value like this will most definitely take a while for all the plugins to implement. Just sayin'.

@xuhdev
Member
xuhdev commented Oct 25, 2016

Yeah, definitely. But we can push the doc first so people can work on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment