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

Fix rubocop config and warnings #15503

Merged
merged 6 commits into from
Jan 7, 2021
Merged

Fix rubocop config and warnings #15503

merged 6 commits into from
Jan 7, 2021

Conversation

abcang
Copy link
Contributor

@abcang abcang commented Jan 6, 2021

Due to the version upgrade of rubocop, the number of new warnings has increased.

$ be rubocop --fail-level W --display-only-fail-level-offenses --parallel
Inspecting 723 files
.......................................................................................................................................................................................................................................................................................................W.............................................................................W.........W.......W..W................W................................................................................................................................................WW.................................................................................................................................................W...................

Offenses:

app/models/account.rb:390:5: W: Lint/MissingSuper: Call super to initialize state of the parent class.
    def initialize(account, attributes) ...
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/home_feed.rb:4:3: W: Lint/MissingSuper: Call super to initialize state of the parent class.
  def initialize(account) ...
  ^^^^^^^^^^^^^^^^^^^^^^^
app/models/list_feed.rb:4:3: W: Lint/MissingSuper: Call super to initialize state of the parent class.
  def initialize(list) ...
  ^^^^^^^^^^^^^^^^^^^^
app/models/poll.rb:75:5: W: Lint/MissingSuper: Call super to initialize state of the parent class.
    def initialize(poll, id, title, votes_count) ...
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/public_feed.rb:11:3: W: Lint/MissingSuper: Call super to initialize state of the parent class.
  def initialize(account, options = {}) ...
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/tag_feed.rb:15:3: W: Lint/MissingSuper: Call super to initialize state of the parent class.
  def initialize(tag, account, options = {}) ...
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/keys/claim_service.rb:10:5: W: Lint/MissingSuper: Call super to initialize state of the parent class.
    def initialize(account, device_id, key_attributes = {}) ...
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/keys/query_service.rb:9:5: W: Lint/MissingSuper: Call super to initialize state of the parent class.
    def initialize(account, devices) ...
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/keys/query_service.rb:22:5: W: Lint/MissingSuper: Call super to initialize state of the parent class.
    def initialize(attributes = {}) ...
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/paperclip/color_extractor.rb:145:10: W: Lint/FloatComparison: Avoid (in)equality comparisons of floats as they are unreliable.
      if s == 0.0
         ^^^^^^^^

723 files inspected, 10 offenses detected

@@ -2,7 +2,8 @@ require:
- rubocop-rails

AllCops:
TargetRubyVersion: 2.4
TargetRubyVersion: 2.5
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The minimum supported version of Mastodon is currently 2.5.

@@ -2,7 +2,8 @@ require:
- rubocop-rails

AllCops:
TargetRubyVersion: 2.4
TargetRubyVersion: 2.5
NewCops: disable
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New cops can be falsely detected, so I thought it wouldn't be necessary to actively enable them. The current unconfigured state is pending and the new cop remains disabled.
By setting it explicitly, the warning that prompts you to set the new cop will not be displayed.

@errors = {}
@original_field = attributes
string_limit = account.local? ? 255 : 2047
super(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The same thing can be achieved by giving hash to the initializer of ActiveModelSerializers::Model.

@verified_at = Time.now.utc
@attributes['verified_at'] = @verified_at
self.verified_at = Time.now.utc
@original_field['verified_at'] = @verified_at
Copy link
Contributor Author

@abcang abcang Jan 6, 2021

Choose a reason for hiding this comment

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

I had to maintain this process to propagate the changes to the fields of account. I changed the name of the instance variable because it was a little confusing.

@@ -1,6 +1,6 @@
# frozen_string_literal: true

class PublicFeed < Feed
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The methods defined in the Feed weren't used at all, so it didn't seem necessary to inherit them.

@name = attributes['name'].strip[0, string_limit]
@value = attributes['value'].strip[0, string_limit]
@verified_at = attributes['verified_at']&.to_datetime
@errors = {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

errors didn't seem to be used

@Gargron Gargron merged commit efffdd3 into mastodon:master Jan 7, 2021
@abcang abcang deleted the fix_rubocop branch January 7, 2021 09:47
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