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

Can't Nest Conditionals #680

Closed
loganknecht opened this issue Apr 28, 2015 · 3 comments
Closed

Can't Nest Conditionals #680

loganknecht opened this issue Apr 28, 2015 · 3 comments

Comments

@loganknecht
Copy link

Hi there!

I'm using this wonderful tool via the sublime html prettify plugin.

I'm having an issue with it where it won't nest conditionals and was redirected to posting here.


Original Posting:

victorporof/Sublime-HTMLPrettify#219

Hello!

I'm having an issue with my code where I want to nest conditional logic for better readability, however upon saving it causes the conditionals to be inlined together.

For example this is how I want the code to look

if((!_.isNull(jqXHR.responseJSON) && !_.isUndefined(jqXHR.responseJSON)) 
   && (!_.isNull(jqXHR.responseJSON.errMessage) && !_.isUndefined(jqXHR.responseJSON.errMessage))) {
    signup_error_field.html(jqXHR.responseJSON.errMessage);
} else {
    signup_error_field.html('An Unexpected Error Occurred:\n' + error_thrown);
}

But, when I save it formats it to this

if((!_.isNull(jqXHR.responseJSON) && !_.isUndefined(jqXHR.responseJSON)) && (!_.isNull(jqXHR.responseJSON.errMessage) && _.isUndefined(jqXHR.responseJSON.errMessage))) {
    signup_error_field.html(jqXHR.responseJSON.errMessage);
} else {
    signup_error_field.html('An Unexpected Error Occurred:\n' + error_thrown);
}

I tried changing multiple settings, however I wasn't able to really configure it such that it would match the desired style.

Is there a setting that would afford me this ability that I'm unaware of?

@bitwiseman
Copy link
Member

Yes, the beautifier does not quite support what you are trying.

This works (remains formatted as shown):

if ((!_.isNull(jqXHR.responseJSON) && !_.isUndefined(jqXHR.responseJSON)) &&
    (!_.isNull(jqXHR.responseJSON.errMessage) && !_.isUndefined(jqXHR.responseJSON.errMessage))) {
    signup_error_field.html(jqXHR.responseJSON.errMessage);
} else {
    signup_error_field.html('An Unexpected Error Occurred:\n' + error_thrown);
}

This does not work:

if((!_.isNull(jqXHR.responseJSON) && !_.isUndefined(jqXHR.responseJSON)) 
   && (!_.isNull(jqXHR.responseJSON.errMessage) && !_.isUndefined(jqXHR.responseJSON.errMessage))) {
    signup_error_field.html(jqXHR.responseJSON.errMessage);
} else {
    signup_error_field.html('An Unexpected Error Occurred:\n' + error_thrown);
}

PR #735 is aimed at making that second version work.

@loganknecht
Copy link
Author

Aw... Ok. I await with bated breathe for #735. Thank you.

@bitwiseman bitwiseman added this to the v1.6.0 milestone Jan 20, 2016
@bitwiseman bitwiseman modified the milestones: 2.0.0, v1.6.0, v1.6.3, v2.0.0 Jan 29, 2016
@bitwiseman
Copy link
Member

#735 added option to control this.

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

2 participants