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

Added :justify_hash option. #319

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Pysis868
Copy link

@Pysis868 Pysis868 commented Sep 8, 2017

Allows you to not justify hash key-value pair output.
Works for indent > 0 and < 0 cases. The = 0 should be unrelated
and untouched.

Added the specs I thought were needed (the minimum).

Stayed within some style checks, and ignored others where deemed
appropriate.

In addition to working pn the feature per the contributing guidelines:

  • Went ahead and added myself to the contributor section in
    CONTRIBUTING, along with fixing some other minor bits.
  • In CHANGELOG, fixed some minor bits.
  • Went ahead an added myself here for later release buidl refernce
    ease.
  • Also highlighted the fact that my link is to an issue. You can add
    the PR link to it later.

@Pysis868
Copy link
Author

Pysis868 commented Sep 8, 2017

Didn't have the most fun in the align function, what with indentations, width, and several use cases, but still had some :).

The use is fairly coupled with the left_width function that was using more at one point. Maybe I wasn't reading the code correctly when trying to change it, but something didn't feel easy when going through it.

What helped most is when I started treating left_width as the true indentation level, which I am essentially accomplishing now by reversing the indented block. Wondering if that could be rewritten more.

@Pysis868
Copy link
Author

Pysis868 commented Sep 8, 2017

Also noting #317 can be closed when this PR is.

Allows you to not justify hash key-value pair output.
Works for `indent` `> 0` and `< 0` cases.  The `= 0` should be unrelated
and untouched.

Added the specs I thought were needed (the minimum).

Stayed within some style checks, and ignored others where deemed
appropriate.

In addition to working pn the feature per the contributing guidelines:
 - Went ahead and added myself to the contributor section in
CONTRIBUTING, along with fixing some other minor bits.
 - In CHANGELOG, fixed some minor bits.
 - Went ahead an added myself here for later release buidl refernce
ease.
 - Also highlighted the fact that my link is to an issue.  You can add
the PR link to it later.
@Pysis868 Pysis868 force-pushed the add-justify-hash-option branch from a255d4e to d043f61 Compare September 8, 2017 03:45
Copy link
Collaborator

@imajes imajes left a comment

Choose a reason for hiding this comment

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

Hey, good start but i think there are some changes which will improve overall style and clarity. ! 👍

end
else
value
end
end

def align_justify(value, width) # rubocop:disable Metrics/AbcSize
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove any rubocop disable comments; They're a bad practice because it'll never report for this metric again.

def align_justify(value, width) # rubocop:disable Metrics/AbcSize
if options[:indent] > 0
value.rjust(width)
elsif options[:indent] == 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

These two branches (the elsif/else) can be condensed into just line 142.

@@ -123,18 +123,29 @@ def outdent

def align(value, width)
if options[:multiline]
Copy link
Collaborator

Choose a reason for hiding this comment

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

since you are here, it'd be great to resolve the ABCSize issues in this method. Return early unless options[:multiline],

Copy link
Author

Choose a reason for hiding this comment

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

ok, wasn't sure how far to take Metrics, and I attempted to clear it up some already.

else
indent[0, indentation + options[:indent]] + value.ljust(width)
align_no_justify(value)
Copy link
Collaborator

Choose a reason for hiding this comment

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

something about this method name feels off, and it's doing more than just aligning / justifying, sort of-- indenting then justify. Is there a way to break it into those two steps?


width = left_width(data) if options[:justify_hash]
Copy link
Collaborator

Choose a reason for hiding this comment

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

width is now no longer set, which will potentially have unexpected consequences in L49, L51 and/or L56.

Copy link
Collaborator

Choose a reason for hiding this comment

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

is now potentially no longer set. :)

@imajes
Copy link
Collaborator

imajes commented Nov 7, 2017

hey @Pysis868 - wanted to follow up on this :) this is a 👍 PR, but i'd like to tune it up a little bit as per the comments. Do you have time to take a look?

thanks! 🥇

@hakunin
Copy link

hakunin commented Feb 9, 2023

I have to switch from awesome print just because of this issue causing me lost time in development.

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.

3 participants