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

Bring back space_after_anon_function #474

Merged
merged 1 commit into from Sep 17, 2014

Conversation

gabrielmaldi
Copy link
Contributor

This PR adds the option jslint_happy_align_switch_case which allows to opt out of switch-case alignment when using jslint_happy.

With jslint_happy_align_switch_case = true (the default):

switch (something) {
case 1:
  break;
case 2:
  break;
}

With jslint_happy_align_switch_case = false:

switch (something) {
  case 1:
    break;
  case 2:
    break;
}

Most changes in this PR are trimmed trailing whitespace, use ?w=1 to focus on the real changes.
#15, #213, #372

ToDo:

  • JavaScript
  • Python
  • CLI
  • Tests
  • Docs

@bitwiseman
Copy link
Member

Interesting. The only reason we have jslint_happy is to make jslint not complain. Why not just use? jslint_happy = false? You want to make this change so that you get function () without the odd case indents?

@gabrielmaldi
Copy link
Contributor Author

Yes, as @rossipedia and @roman01la I just want the space between function and the parens.

I gave it some though before and came up with these alternatives for the API:

  1. Remove jslint_happy in favor of two specific options for switch-case alignment and the space in the function definition.
    • This has the nice property that is future-proof, because with good defaults you can always add new options to make jslint happy
    • I didn't go this way because it is a breaking change and because I saw that you used to have a space_after_anon_function that was deprecated
  2. Add a specific option for the space in the function definition
  3. Add a specific option for the switch-case alignment

Options 2 and 3 have the downside that if in the future jslint_happy makes more changes, we'd have to add more options to deal with that.

So I ended up going with option 3 because it seemed the least disruptive. What I'd like is actually option 1 and to also keep jslint_happy as a switch to turn some specific options on; but this decision obviously is beyond me 😃

@bitwiseman
Copy link
Member

I went ahead and cleaned up the spaces in master. Thanks for pointing them out.

There is a long standing tension between added formatting options and keeping the tool from degenerating into a completely configurable but untestable hell. In #221, we've discussed "The beautifier basic formatter, not a general-purpose custom formatter."

It looks like what you really want add the space_after_anon_function back, but you're trying to respect the direction of the design. Thanks for trying, but you might as well just put the old setting back in - it was clearer about what it was doing. 😄

In fact, option 4 (option 1 but keep jslint_happy) sounds like the right way to go. 😄 Give that try.

@gabrielmaldi gabrielmaldi changed the title Opt out of switch-case alignment when using jslint_happy Bring back space_after_anon_function Jun 11, 2014
@gabrielmaldi
Copy link
Contributor Author

Thanks, I'll follow that discussion.

I pushed some changes to bring space_after_anon_function back. Go ahead and tell me if you think that something should be different (or just push minor changes yourself if you feel like it).

Just FYI, I use Sublime Text 3 with these options 😃:

{
  "trim_trailing_white_space_on_save": true,
  "ensure_newline_at_eof_on_save": true
}

@evocateur
Copy link
Contributor

"trim_trailing_white_space_on_save": true (regardless of how much I agree with it) is a very noisy setting for projects that you don't own. I'd recommend disabling it, since all it does is create confusion when evaluating pull requests.

@gabrielmaldi
Copy link
Contributor Author

@evocateur you're right, sorry.

@evocateur
Copy link
Contributor

@gabrielmaldi Any news on the Python implementation? I appreciate your responsiveness to the feedback here.

@gabrielmaldi
Copy link
Contributor Author

I mistakenly thought I had asked for some help because I had never written a line of Python before. Anyway, I dived into it and it was pretty simple since all I had to do was copy the whole structure of an existing option.

I also added the new option to the CLI and docs.

Just shoot any feedback 😃

@gabrielmaldi
Copy link
Contributor Author

Hey, just a friendly reminder that if you guys want me to work further on this PR just go ahead and tell me what you think I should do/change 😄

@@ -266,6 +271,7 @@
opt.space_in_paren = (options.space_in_paren === undefined) ? false : options.space_in_paren;
opt.space_in_empty_paren = (options.space_in_empty_paren === undefined) ? false : options.space_in_empty_paren;
opt.jslint_happy = (options.jslint_happy === undefined) ? false : options.jslint_happy;
opt.space_after_anon_function = (options.space_after_anon_function === undefined) ? false : options.space_after_anon_function;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, I'd suggest adding this at line 279:

// force opt.space_after_anon_function to true if opt.jslint_happy
if(opt.jslint_happy) {
    opt.space_after_anon_function = true;
}

Then below you can check for just opt.space_after_anon_function instead of two different options.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most likely I misunderstood, but we need this line here; otherwise space_after_anon_function won't be set to the desired value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change you made looks like what I intended. 😄

@bitwiseman
Copy link
Member

Sorry for the delay. Thanks again for you following through on this change, and for doing the python work as well. It looks really good.

A few minor changes (and mirror them in python) and we can merge this.


# force opts.space_after_anon_function to true if opts.jslint_happy
if self.opts.jslint_happy:
self.opts.space_after_anon_function = True
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't get this to work; it's what's making tests fail. Help? 😄

@gabrielmaldi
Copy link
Contributor Author

Thanks for your feedback! I went ahead and made the changes you suggested. If I missed anything just tell me.

I'm having trouble getting to force space_after_anon_function to true if jslint_happy in Python. Any help will be appreciated.

@bitwiseman
Copy link
Member

Ah, you found a bug in the python code. I've just pushed a fix. Rebase your changes on top of master and squash to one commit. Tests should then pass.

@gabrielmaldi
Copy link
Contributor Author

My first thought was that it was probably just what you fixed in c67a9e7. But I couldn't be sure because of my little knowledge of Python 😄

bitwiseman added a commit that referenced this pull request Sep 17, 2014
@bitwiseman bitwiseman merged commit 3d0ec5f into beautifier:master Sep 17, 2014
@gabrielmaldi gabrielmaldi deleted the switch-case-aligment branch September 17, 2014 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants