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

Update Rubocop and fix offenses #735

Merged
merged 6 commits into from
Jun 5, 2018
Merged

Conversation

murny
Copy link
Collaborator

@murny murny commented May 28, 2018

  • Upgrade Rubocop from 0.51 to 0.56

- app/models/concerns/item_properties.rb

# TODO: Review and fix these
Naming/UncommunicativeMethodParamName:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Rubocop doesn't like parameters with less then 3 letters (fq, qf, q, ip, as, etc)
Naming/UncommunicativeMethodParamName: Method parameter must be at least 3 characters long.

Disabled the offenders for now

Rails/FindEach:
Enabled: false

# TODO: False postivies on headers, remove this once on rubocop > 0.56.0 as fixed in next release
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This got fixed upstream: rubocop/rubocop#5888

Disabling offender for now, can remove this once we on 0.56+

@@ -74,15 +74,45 @@ Naming/FileName:
- Rakefile
- Gemfile

# TODO: Review and fix these
Naming/MemoizedInstanceVariableName:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Rubocop wants memorized instance variable to be the same name as the method name.

For example

def count
  @count ||= super
end

instead of

def count
  @count_cache ||= super
end

Naming/MemoizedInstanceVariableName: Memoized variable @count_cache does not match method name count. Use @count instead. @count_cache ||= super

We have a few offenders of this. Disabling for now

# There comes a point where I question Rubocop's maintainer's sanity
Rails/UnknownEnv:
Enabled: false

# Autocorrecting this actively breaks code
Rails/FindEach:
Style/AsciiComments:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Most of these diffs below are for reordering these in alphabetical order

@@ -38,7 +38,7 @@ class Admin::UsersControllerTest < ActionDispatch::IntegrationTest
assert_equal I18n.t('admin.users.show.unsuspend_flash'), flash[:notice]

user.reload
refute user.suspended?
assert_not user.suspended?
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

rubocop prefers assert_not instead of the refute style assertions

@@ -266,7 +267,7 @@ def license_for_uri(uri)
code = CONTROLLED_VOCABULARIES[:license].from_uri(uri)
license = URI_CODE_TO_LICENSE[code].to_s

license.blank? ? 'unselected' : license
license.presence || 'unselected'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

.presence will return itself if true, otherwise nil. Rubocop autocorrects these

@murny murny requested a review from mbarnett May 31, 2018 16:58
@@ -159,9 +159,9 @@ def reify_result_set

def sort_clause
model = criteria[:restrict_to_model].first.owning_class
indexes = criteria[:sort].present? ? criteria[:sort] : model.default_sort_indexes
indexes = criteria[:sort].presence || model.default_sort_indexes
Copy link
Contributor

Choose a reason for hiding this comment

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

Am I the only one that finds presence less readable?

I'm not married to removing it but I'm not loving it either

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm indifferent? So if anyone feels strongly about this, we can disable

Copy link
Contributor

@mbarnett mbarnett May 31, 2018

Choose a reason for hiding this comment

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

@cwant || @pgwillia ? Any strong feelings? I can learn to live with this, I just don't find it terribly obvious.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, no strong opinion.
In honesty, I had to look presence up -- would be nice if the method had a more illustrative name (oh well).

Copy link
Contributor

Choose a reason for hiding this comment

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

99% of my feeling on this is "I wish it had a slightly different name".

I guess we live with it. My eyes aren't bleeding or anything.

Copy link
Contributor

Choose a reason for hiding this comment

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

In this very particular case, maybe fetch would be more readable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

gif

Copy link
Contributor

Choose a reason for hiding this comment

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

Between the two, I guess I like present more. It's kind of a "which do I like finding more, a used bandaid or a toe-nail" situation though

bin/yarn Outdated
exit 1
end
exec 'yarnpkg', *ARGV
rescue Errno::ENOENT
Copy link
Contributor

@mbarnett mbarnett May 31, 2018

Choose a reason for hiding this comment

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

I think rubocop screwed this up. Now if APP_ROOT doesn't exist (possible if you're cd'd into the dir in one terminal after rm-ing it in another), that error will get rescued here and the wrong error message displayed.

It's a real corner-case, admittedly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can revert, rubocop autocorrected this. So can disable this file for whatever it's doing.

@murny murny merged commit 2e7e3b8 into ualbertalib:master Jun 5, 2018
@murny murny deleted the rubocop-upgrade branch June 5, 2018 19:52
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

3 participants