-
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
Support newline before logical or ternary operator #605
Comments
Oo, I just realized this made my big equality function a crazy one-liner
turns into
So this is more far reaching than I first thought. I'll take a look at the source. |
Congratulations on an easy-to read library. In the small chance that future readers use the same formatting I do, the following code snippet should solve your problems. I haven't tested much besides the few files I wanted js-beautify for, but I will update it if I run into any issues. Inserted at line 1079 of js-beautify version 1.5.4
due to my styling be different from most others, I won't bother with a PR. Go ahead and close this. |
No, your suggestion seems very reasonable. |
I appreciate the feedback. I just looked into running the /js/tests/run-tests and found it requires /usr/bin/spidermonkey-1.7 to exist. Any documentation on that? I searched the repo and found nothing. |
try running |
I'll have a fix finished tonight, but man would it be helpful for all these tests to be associated with some id for quick reference haha |
And actually I do need your or another maintainer's input on whether this should be optional behavior. The only time I can see where it matters is the following case: var a = (b Without an option, the above case is ambiguous. As I see it, we can either
I lean towards # 2 because I don't feel any ambiguous cases will be important enough to style correctly. If someone writes code like the above, they likely don't care much about how it comes out. Please let me know your thoughts. |
Ah, I see. It makes sense to do #1 in order to preserve existing behavior - no one is going to complain, that your change broke them. It also keeps the combinations for testing somewhat simpler... But I can see the attraction of #2. As a default, you should be able to check if the operator is also followed by a new line, then force to one behavior or the other. They may not care, but we should shoot for some consistency. |
I don't mean to be argumentative - but I don't see a case where anyone will complain about their code breaking as a result of this new operator-first change. I agree that it would be safer to make this optional, but mainly because I understand that I can't foresee all use-cases. I will certainly make it an option, but for sake of playing devil's advocate, can you think of a case where someone would be surprised? Edit: I will have a PR tomorrow with it being an option :) |
You'd be surprised. 😄 Let's say someone is expecting the beautifier to force operator-before-newline and then it doesn't anymore, as in the case of team-wide style enforcer. |
Ah good point - Thanks much |
I find it funny the beautify.js isn't beautified haha. The code I wrote could easily be expanded to allow for other operator-first notation (such as string concatenation). Just food for thought. |
did this ever get solved? |
Nope. I let it be because interest doesn't seem to be there. Taking a look at your referenced issue however, I'd love to have a maintainer give me feedback on my PR. I'm willing to add tests/modify the code as needed. |
@alexjamesbrown - I'll for sure have the PR updated by mid-next week, though I'm aiming for this weekend. Go ahead and watch the relevent PR for further updates. When the PR is merged, I'll mark your referenced issue as closed. |
cool, sounds good! thanks! |
I would love newline option for && || ? : operators |
Ha - I know, bitwiseman and I were working on a draft and life caught up with us. These hollidays are killing me along with work. I will get to this when I can. I appreciate the interest though - because it's nice to know people will use this feature. |
Also looking for an option to beautify our busy schedules 😃 |
#735 added option to control this. |
So I use ternary operators every once in a while, and I format them like the following:
however running this through js-beautify I get
I haven't used the tool much, and didn't see any relevant options besides the preserve lines but that didn't help. I understand this is a very narrow use-case and so if the functionality doesn't exist I'm fine with that.
Thanks for the work put into this library
The text was updated successfully, but these errors were encountered: