-
Notifications
You must be signed in to change notification settings - Fork 453
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
Javascript Trailing Commas #534
Comments
The two JavaScript beautifiers that are currently supported are I do not believe that Likewise, I do not see this functionality for |
I am probably stripping trailing commas. Before ES5 trailing commas were a syntax error and even after they were no longer an error in JavaScript they are generally regarded as either nonsense or a bad practice. I could create a new option to forcefully inject a trailing comma in object literals. This would mean trailing commas are either always present or never present. |
This has been addressed by Pretty Diff with #524 (comment) I am going to mark this issue as a duplicate of #524 now. |
Published to v0.28.12 as JavaScript option |
The end_with_commas doesn't work in JSX files whereas it seems supported by Prettydiff. Thanks. |
Should work. Support is on JavaScript language: https://github.com/Glavin001/atom-beautify/blob/master/src/languages/javascript.coffee#L109-L113 Please follow https://github.com/Glavin001/atom-beautify/blob/master/CONTRIBUTING.md#new-issues-bugs-questions-etc and share a Gist of your results of running command |
Ok I think I find out why it didn't work. I was in Babel ES6 JavaScript file grammar and when I switch to Javascript it works. |
This could make sense. You had the following:
Atom Beautify first determines the appropriate language to use and then finds the appropriate beautifiers for that language. See applicable code:
The default beautifier for JSX language is When you switched the grammar to JavaScript there was a match for Atom Beautify language JavaScript (not language JSX). The default beautifier for JavaScript is Looking at your
Note that in the above the option Looking at Pretty Diff's documentation I do see So given all of this, it would suggest that Pretty Diff is not properly handling the Hope that helps! |
I can confirm its not working at http://prettydiff.com/ so it definitely looks like a Pretty Diff defect. I will have to track down why this isn't working. Its working on my local. |
Nevermind, I had the |
Anyone figured out how to add the trailing comma when beautify is triggered? I'm on a regular ES6 .js file. Not .jsx. Tried all 3 beautifiers (jsbeautufy, JSCS fixer & prettydiff). None worked. I have the trailing commas switched on. Latest version of |
@piggyslasher I can reproduce the issue with this code:
I will have to look into this further. With the |
Here is my debug log: https://gist.github.com/prettydiff/4f34ed2f343cda0a1de0 Everything looks correct on the Atom Beautify side of the house as the value is set to true and is correctly translated to the proper option name in prettydiff. This is not broken at http://prettydiff.com/?m=beautify I am going to see if I can get output into the Chrome console that comes with Atom and see what is being input to the included prettydiff versus the output. |
I found the defect on the Pretty Diff side. Atom Beautify is working correctly. The fix is to convert https://github.com/prettydiff/prettydiff/blob/master/lib/jspretty.js#L1901 to:
My confusion earlier is that this defect is absent when object sorting is enabled. This is a Pretty Diff defect that will be fixed in the next release. I have already proven on my local that this fixes the problem in the atom-beautify package. |
You're a star mate. Will try this fix and get back to you. |
@piggyslasher Just grab the latest version (v1.16.10). I published the fix on Friday. |
Thx for the fix @prettydiff ;)
becomes the following after beautification :
As you can see it removes some trailing commas. That doesn't occur when I'm using the Javascript grammar. Have you got any idea where it comes from ? |
Weird. I was able to reproduce this defect at first, but now I cannot. I cam continuing to look at this. |
hi @prettydiff, did you find a way to handle that ? Thx. |
Sorry, this fell off my radar. I am looking this morning and still cannot reproduce the defect. I looking at both the online tool and in Atom with Atom Beautify. At this point I am thinking there could be a conflict of options. I am going to need the generated Pretty Diff option object. Could you go into the Then after you have saved that change you will need to restart Atom. When it opens back up you will need to open the Chrome console, which is cmd+opt+i on Mac or alt+ctrl+i on Windows. Then after verifying that the option is Thanks. |
@prettydiff, here it is :
|
Excellent, I will examine this further later today. |
@Glavin001 I am noticing when this option is checked and I beautify the code snippet in #534 (comment) the result is a toggling effect. Beautify the code sample several times and you can see commas flicker in and out. I am not sure that is causing that. @Bodhiz I am still having trouble reproducing this the problem of only partial trailing commas. |
Did you try with this grammar : https://github.com/gandm/language-babel ? |
I installed that package, which created the grammar We need to extend Atom Beautify to support that grammar name and any unique file extensions it supports. Would you mind opening a new issue for this so that we can track the work appropriately? |
You get that error directly in Atom ? Didn't get anything on my side. |
Unfortunately, this adds a trailing comma in an import statement as well:
|
@munjalpatel Good catch. I opened a defect: prettydiff/prettydiff#308 |
@munjalpatel I looked into this matter. Pretty Diff will not conditionally retain trailing commas. Pretty Diff has an option called If this option is provide a value of I tested your code sample at http://prettydiff.com/?m=beautify with and without |
Hi,
I'm using JSCS with airbnb preset and it recommends to use additional trailing commas but unfortunately atom-beautify removes them provoking JSCS error. Is there any way to fix this ?
Thanks in advance
The text was updated successfully, but these errors were encountered: