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

Rubocop: Style/SafeNavigation #1518

Merged
merged 1 commit into from
Nov 28, 2017

Conversation

jaredmoody
Copy link
Contributor

No description provided.

@@ -26,8 +26,7 @@ def pad_if_necessary(hex)
# Returns a 3- or 6-char hex string for valid input, or nil
# for invalid input.
def validate(hex)
match = /^#?(([0-9a-f]{3}){1,2})$/i.match(hex)
match && match[1]
/^#?(([0-9a-f]{3}){1,2})$/i.match(hex)&.[](1)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only line of this PR I don't like - explicitly calling [] seems weird and perhaps unclear that it's equivalent

Alternatively, we could disable this cop on this line

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, that makes an already dense snippet even more obscure.

What's the cop say if we try to use a post-fix if instead?

       match = /^#?(([0-9a-f]{3}){1,2})$/i.match(hex)
       match[1] if match

Copy link
Member

Choose a reason for hiding this comment

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

Could also move the regex into a constant imo :)

however yes, &.[](1) doesn't seem nice

Copy link
Member

@PragTob PragTob left a comment

Choose a reason for hiding this comment

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

Agreed with the both of you :)

@@ -26,8 +26,7 @@ def pad_if_necessary(hex)
# Returns a 3- or 6-char hex string for valid input, or nil
# for invalid input.
def validate(hex)
match = /^#?(([0-9a-f]{3}){1,2})$/i.match(hex)
match && match[1]
/^#?(([0-9a-f]{3}){1,2})$/i.match(hex)&.[](1)
Copy link
Member

Choose a reason for hiding this comment

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

Could also move the regex into a constant imo :)

however yes, &.[](1) doesn't seem nice

@jaredmoody
Copy link
Contributor Author

Rubocop still complained on the Post-fix - updated with the regex pulled out into a constant and the cop disabled inline.

@PragTob
Copy link
Member

PragTob commented Nov 26, 2017

Merge conflict now and soemhow a test failed but travis doesn't load for me

@jasonrclark
Copy link
Member

Looking 🍏 now. Thanks!

@jasonrclark jasonrclark merged commit 548ec87 into shoes:master Nov 28, 2017
@jaredmoody jaredmoody deleted the robocop-style-safe-nav branch December 3, 2017 01:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants