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

Check and change some of our current rubocop configuration #456

Closed
wants to merge 1 commit into from

Conversation

DJA89
Copy link
Contributor

@DJA89 DJA89 commented Sep 13, 2023

Board:

Notion ticket


Description:

Checking the Rubocop rules we have set specific options to in our .rubocoop.yml


Notes:

List of changes or comments:

  • Layout/SpaceBeforeFirstArg: Removed exception and added AllowForAlignment so it works ok for how we use it on views.
  • Lint/BinaryOperatorWithIdenticalOperands: Removed, unlikely to be used but I only see positives as it removed redundancy.
  • Lint/DeprecatedOpenSSLConstant: Removed, it’s a deprecation warning, we shouldn’t use deprecated stuff if possible.
  • Lint/RaiseException: Removed, we shouldn’t raise plain Exceptions as catching them would mean catching every other kind of Exception in the same place.
  • Style/ArrayCoercion: Removed as it can cause problems Style/ArrayCoercion does not play nicely with Hashes rubocop/rubocop#8783.
  • Rails/FilePath: Removed so it’s enabled, it’s good to always use the same syntax, the default is to use arguments but I’m fine if slashes are preferred.
  • Style/BlockDelimiters: Removed except on specs, it feels wrong to use braces on multi line blocks, if this is how most of the company uses it nowadays then we can change it but I believe it’s the other way around. Left it on specs because it is usually how they are used for expect { }.to even if it's multiline..
  • Style/ExpandPathArguments: I’m not really sure what difference this makes, never used it, might be good to have it turned on just to have consistency.
  • Style/GlobalStdStream: Same as above.
  • Style/HashEachMethods: Removed as it’s faster: https://stackoverflow.com/questions/46532459/what-is-the-difference-between-keys-each-and-each-key.
  • Style/HashTransformKeys: Removed as we have the necessary version of ruby and it looks way less confusing.
  • Style/HashTransformValues: Same as above.
  • Style/RedundantFetchBlock: Removed as it's faster https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/RedundantFetchBlock.
  • Style/RedundantFileExtensionInRequire: I’ve removed it since I’ve never seen us use require ‘something.rb’ explicitly.
  • Style/RedundantRegexpCharacterClass: Removed it as it only looks positive.
  • Style/ReturnNil: Do we usually return nil explicitly? Not used to this but not removing it as I’m not sure what most of us do.
  • Style/SlicingWithRange: Removing it as we have the necessary ruby version.
  • Style/StringConcatenation: I personally prefer interpolation, maybe using the conservative mode, wdpt? https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/StringConcatenation.

Tasks:

  • Add each element in this format

Risk:


Preview:

Copy link
Contributor

@guillermoap guillermoap left a comment

Choose a reason for hiding this comment

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

I feel we have to discuss a lot of the changes made in this PR, some make sense to me but the majority don't.

@@ -29,21 +29,11 @@ Layout/LineLength:
- db/**/*

Layout/SpaceBeforeFirstArg:
Exclude:
- app/views/api/**/**/*
AllowForAlignment: true
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like having aligned comments, would this limit the ability of having multi line comments that are not aligned?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is for comments right? I think it's because in views we do

json.id         user.id
json.email      user.email
json.name       user.full_name
json.username   user.username

which I don't like but it is what it is 🤷

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 indeed only for arguments, not comments. Layout::CommentIndentation would be the one that would modify comments

Style/BlockDelimiters:
EnforcedStyle: braces_for_chaining
Exclude:
Copy link
Contributor

Choose a reason for hiding this comment

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

why did we remove this config for specs? Not saying I like the braces_for_chaining but even the default one is a good config to have.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is the idea

image

Comment on lines -38 to -46
Lint/BinaryOperatorWithIdenticalOperands:
Enabled: false

Lint/DeprecatedOpenSSLConstant:
Enabled: false

Lint/RaiseException:
Enabled: false

Copy link
Contributor

Choose a reason for hiding this comment

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

I like this rules being enabled by default

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 do too

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

@@ -88,11 +75,9 @@ RSpec/MultipleExpectations:
RSpec/NamedSubject:
Enabled: false

Style/ArrayCoercion:
Enabled: true
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm 50/50 on this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See my note, I removed it mainly because of the issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm okay with removing this

@@ -73,9 +63,6 @@ Metrics/ModuleLength:
Metrics/PerceivedComplexity:
Max: 12

Rails/FilePath:
Enabled: false
Copy link
Contributor

Choose a reason for hiding this comment

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

I would leave this config

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. So you would leave it turned off?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would leave this disabled as well 😄

Style/HashLikeCase:
MinBranchesCount: 4

Style/HashTransformKeys:
Enabled: false
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL I learned about transform_keys, but again since it can generate false positives I prefer no to enable it by default

Copy link
Member

Choose a reason for hiding this comment

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

https://docs.rubocop.org/rubocop/usage/auto_correct.html#safe-auto-correct

maybe we don't need to worry too much about the unsafe cops since we can use a safe autocorrect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can also AutoCorrect: false so it never happens and it has to be a manual choice

Style/HashTransformKeys:
Enabled: false

Style/HashTransformValues:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Enabled: false

Style/RedundantFileExtensionInRequire:
Enabled: false
Copy link
Contributor

Choose a reason for hiding this comment

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

👍🏻

Enabled: false

Style/RedundantRegexpCharacterClass:
Enabled: false
Copy link
Contributor

Choose a reason for hiding this comment

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

👍🏻

Style/ReturnNil:
Enabled: true

Style/SlicingWithRange:
Copy link
Contributor

Choose a reason for hiding this comment

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

As same as above given the nature of false positives this has I would keep it disabled by default

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 was getting my info from rubydoc.info which did not mention some of these false positives, I see docs.rubocop.org is better documented (as it should)

Copy link
Contributor

@sebastiancaraballo sebastiancaraballo left a comment

Choose a reason for hiding this comment

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

Nice

Comment on lines -38 to -46
Lint/BinaryOperatorWithIdenticalOperands:
Enabled: false

Lint/DeprecatedOpenSSLConstant:
Enabled: false

Lint/RaiseException:
Enabled: false

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

@@ -73,9 +63,6 @@ Metrics/ModuleLength:
Metrics/PerceivedComplexity:
Max: 12

Rails/FilePath:
Enabled: false
Copy link
Contributor

Choose a reason for hiding this comment

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

I would leave this disabled as well 😄

@@ -88,11 +75,9 @@ RSpec/MultipleExpectations:
RSpec/NamedSubject:
Enabled: false

Style/ArrayCoercion:
Enabled: true
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm okay with removing this

@@ -103,35 +88,14 @@ Style/ExpandPathArguments:
Style/GlobalStdStream:
Enabled: false

Style/HashEachMethods:
Copy link
Contributor

Choose a reason for hiding this comment

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

@santib santib closed this Apr 25, 2024
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.

None yet

4 participants