-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Newline inserted after ES6 module import/export #382
Comments
Related to #388. |
I think the issue here is we don't handle export as a reserved word. |
Hey @bitwiseman that exactly the problem, but for instance if I write something like
It will get beautified as
Which does not look good :) Plus, if I want the brace style import
It will get beautified as
What do you think about that ? |
All this sounds fine. The |
Any news on how close this issue is to being resolved? |
It will be in the next release. The infrastructure is there, it should be a minor change. |
+1 for fixing the formatting of export statements! |
+1 |
4 similar comments
+1 |
+1 |
+1 |
+1 |
+n. I think is just a matter of add these keywords to the list of reserved words. Is that correct? edit: nope. I tried to find where the new rules would be, but is waaay too much code to risk a change =/ |
👍 |
It looks like this is a significant undertaking to do this right. I'm sorry folks but I have to punt this to the next release. For reference: |
Doing this right will take work on the same level as if statements. Getting so it behaves vaguely okay in some situations, I can do right now. Related to #382
That is exactly correct. 😃 For that you get the following fix - the nonsensical input below will produce identical output from the beautifier. Most scenarios still look horrible, but felt I could hack in these with minimal pain. module "a" {
import odd from "Odd";
export default function div(x, y) {}
export function sum(x, y) {
return x + y;
}
export var pi = 3.141593;
export default moduleName;
export *
} |
👍 |
In my copious free time... 😄 |
+1 |
1 similar comment
+1 |
With js-beautify 1.5.10, I'm getting the following: Input: import { x, y, z } from './other'; Output: import {
x, y, z
}
from './other'; I definitely don't want the newline after the ending brace. |
+1 |
Any plans for supporting this? |
Is this still not fixed? |
It is still open. Pull requests welcome. |
+1 Although there is a workaround using : This is not very nice to see. |
+1 |
2 similar comments
+1 |
+1 |
For anyone interested, the remaining issue is with |
I still get the behaviour for imports, but all tickets are closed. How can I preserve a single line in imports after beautification in Atom? Thanks! |
Got it, all that was needed was to add following config in .jsbeautifyrc
|
I am still experiencing this issue with import { mod1, mod2 } from 'filePath'; becomes import {
mod1,
mod2
} from 'filePath'; for those of you that it works correctly, can you post your .rc file json with the correct properties pointed out? I have no idea why it isn't working at all. {
"preserve_newlines": true,
"max_preserve_newlines": 2
} that did not fix it (as posted above) |
@the-simian The correct option is |
@eloquence thanks for the update, I'll try that out as soon as I can Here is the context full working json in the .jsbeautifyrc file: {
"brace_style": "collapse-preserve-inline", //<----that
"break_chained_methods": false,
"end_with_newline": false,
"eol": "\n",
"eval_code": false,
"indent_char": " ",
"indent_level": 0,
"indent_size": 1,
"indent_with_tabs": true,
"jslint_happy": false,
"keep_array_indentation": false,
"keep_function_indentation": false,
"max_preserve_newlines": 4, //<---this
"preserve_newlines": true, // <---this too
"space_after_anon_function": false,
"space_before_conditional": true,
"unescape_strings": false,
"wrap_attributes": "auto",
"wrap_attributes_indent_size": 2,
"wrap_line_length": 0
} |
@loopmode I got a similar problem with "brace_style": "collapse-preserve-inline", Input: const _state = { ...state } Output: const _state = {...state } |
While |
@Coburn37 - Please file a new issue and/or see #1052 to see if that describes what you want. |
+1. I am not a fan of collapse,preserve-inline. I would like to add a rule specifically for imports... |
Hey,
I'm running jsbeautifier on a collection of Ember.JS ES6 modules and I've noticed a small issue with export statements.
Suppose I have a module that exports as below
jsbeautifier will add a newline after export
It's a minor problem that is only an issue for us as we enforce a jsbeautifier run before a commit is accepted. So, if a developer removes the newline, the file in question will be included in the commit even though it may have nothing to do with the changes being commited.
The text was updated successfully, but these errors were encountered: