Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not remove last line-feed from file. #109

Closed
starquake opened this issue Sep 29, 2014 · 9 comments
Closed

Do not remove last line-feed from file. #109

starquake opened this issue Sep 29, 2014 · 9 comments
Assignees

Comments

@starquake
Copy link

I use atom-beautify with linter jscs (google preset but I think it also complains with jquery preset) but it keeps complaining: Missing line feed at file end.

Enabling "js preserve new lines" does not fix this. And there is no way to let these two plugins come to peace with each other. Could you keep the last line-feed intact or make it an option to keep it intact?

@Icehunter
Copy link
Contributor

This appears to have happened since atom itself was updated for 0.133.0. I'm checking my update logs to see if any other plugin was updated but I went back 10 versions on this project and this issue was still manifesting itself.

It was working fine until I updated either atom/another plugin today though :(

@starquake
Copy link
Author

You are right. It was fixed right after updating to 0.133.0. I did not upgrade any plugins. I will close the issue.

@Icehunter
Copy link
Contributor

@Glavin001 I notice this issue is now present again with 0.136.0. I've gone over the code and there doesn't seem to be that big of a change over the previous versions.

I think the largest one was keeping "this" referenced in the events. Have you experienced this in your files as well?

@Glavin001
Copy link
Owner

I have not experienced this before. Could you each provide a little more information that may allow me to reproduce? I also hope to be written more Unit Tests when I have time, so we can detect these breaks earlier on.

@Glavin001 Glavin001 reopened this Oct 8, 2014
@Icehunter
Copy link
Contributor

Sure thing!

Whitespace Settings:
Ensure Single Trailing Newline

.jsbeautifyrc (multiple editor's are used)

{
    "indent_size": 4,
    "indent_char": " ",
    "indent_level": 0,
    "indent_with_tabs": false,
    "preserve_newlines": true,
    "max_preserve_newlines": 2,
    "jslint_happy": true,
    "brace_style": "end-expand",
    "keep_array_indentation": false,
    "keep_function_indentation": false,
    "space_before_conditional": true,
    "break_chained_methods": false,
    "eval_code": false,
    "unescape_strings": false,
    "wrap_line_length": 0
}

Sample:

'use strict';
module.exports = require('./lib/module');

That is the desired output. When using manual beautify (not on save) it will remove that last line and then when I save it restores the line.

The old behaviour was that it would remove and then process using the whitespace plugin. It appears now though the whitespace is always processed first for some reason. I'm thinking it's the even subscriptions of both plugins. Whitespace came with atom so maybe there was some changes under the hood.

@starquake starquake reopened this Oct 8, 2014
@starquake
Copy link
Author

Sorry! Accidentally hit the close button!

@Glavin001
Copy link
Owner

By default it should preserve newlines (max 10): https://github.com/Glavin001/atom-beautify/blob/master/lib/language-options.coffee#L67-L68

I have confirmed that the options passed to js-beauty includes the preserve_newlines:true and max_preserve_newlines:10: https://github.com/Glavin001/atom-beautify/blob/master/lib/language-options.coffee#L155-L158
image

This leads me to believe that it is a bug with js-beautify: https://github.com/beautify-web/js-beautify

You can confirm it is not specific to Atom-Beautify by entering @Icehunter 's sample code (note the trailing newline, 3 lines):

'use strict';
module.exports = require('./lib/module');

at http://jsbeautifier.org/ and beautifying to the result of 2 lines.


@starquake could you forward this Issue over to the folks at js-beautify and everyone else be sure to comment so they know this is of top priority.

Let me know if there is anything else I can do from a Atom Beautify perspective -- such as updated js-beautify dependency for any future releases.

Thanks for your support and feedback on Atom Beautify!

@Icehunter
Copy link
Contributor

Finally figured this one out and sorry for the late comment.

js-beautify added a new option:

"end_with_newline": true

I had been sticking myself for the longest time with 0.14.0 of this library because the new version of js-beautify added it.

After adding this into my .jsbeautifyrc file everything works as expected and "grunt jsbeautifier" will also pickup this for formatting with grunt tasks (those on team without atom).

@nelson6e65
Copy link

end_with_newline option, or similar, is available for SCSS?

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

No branches or pull requests

4 participants