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

feat: add Layout/AccessModifierIndentation #22

Merged
merged 2 commits into from
Apr 3, 2024

Conversation

ferranpm
Copy link
Member

@ferranpm ferranpm commented Mar 14, 2024

What is the goal?

To standardise how private sections are indented in a class
While navigating Simba, I found a couple of classes with the private section indented (e.g. ServiceItems::ServiceItemStates::HandlerJob) and found that Rubocop did not complain.
We've usually used the outdented version

class Blop
  def initialize
  end

private

  def private_method
  end
end

This PR just adds the cop that looks for that outdentation.

Is this a restricting or expanding change?

RESTRICTING change

How is it tested?

Manual tests

@ferranpm ferranpm requested a review from a team March 14, 2024 16:47
@ferranpm ferranpm changed the title Add Layout/AccessModifierIndentation feat: add Layout/AccessModifierIndentation Mar 14, 2024
# https://docs.rubocop.org/rubocop/cops_layout.html#layoutaccessmodifierindentation
Layout/AccessModifierIndentation:
EnforcedStyle: outdent

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a great opportunity to test out the drafted flow, thanks! 🙌🏻

The proposal is to add Severity: info to restricting changes, allowing some time for teams to adopt new restricting agreements on our style. Some months later, we can remove the Severity: info thingy to make the change mandatory.

We need to settle things and communicate changes to the teams before moving forward with the PR, but it would be great to have your early feedback on the proposal ❤️

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! Updated :)

Copy link

@valdis valdis Mar 22, 2024

Choose a reason for hiding this comment

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

i don't think that we need to make this severity: info, because rubocop checks are performed only on the changed files, so the impact is scoped to the code that you are workin on.
I think we all have allready agreed that we want uniform styling of the code everywhere, so adding yet another rule that slightly changes some of the code's formatting has minimal impact on our workflow.

Copy link
Contributor

Choose a reason for hiding this comment

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

@valdis not all applications have rubocop configured to run on changed files only, though that is the case for most of them. We want to make sure these style changes are as non-disruptive as possible to everyone, and that's why we proposed to use severity: info for restricting changes, making them mandatory only after teams have had enough time to update.

Maybe we should consider using non-full scans in all our repositories, though.

Copy link

@oinak oinak left a comment

Choose a reason for hiding this comment

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

I have a concern.

Right now the rule that wants private methods indented relative to private is not activating, but if you apply the fix for the new rule and indent private it will:

The changes will not be like

-private
+  private

but like

-private
+  private

-  def any_other_method
-    here
-  end
+    def any_other_method
+      here
+    end

-  def below
-    here
-  end
+    def below
+      here
+    end

Copy link

@tomtomecek-es tomtomecek-es left a comment

Choose a reason for hiding this comment

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

💯

@ferranpm
Copy link
Member Author

I have a concern.

Right now the rule that wants private methods indented relative to private is not activating, but if you apply the fix for the new rule and indent private it will:

The changes will not be like

-private
+  private

but like

-private
+  private

-  def any_other_method
-    here
-  end
+    def any_other_method
+      here
+    end

-  def below
-    here
-  end
+    def below
+      here
+    end

I'm not sure I completely follow your scenario, so I've come up with the weirdest indentation and it seems to work for me:

fpelayo in ~/Workspace/sequra-style at M211 on access-modifier-indentation
> cat Bipbop.rb
class Bipbop
  def the_public_thing
    "This is public"
  end

    private

def the_private_thing
  "This is private"
end
end

fpelayo in ~/Workspace/sequra-style at M211 on access-modifier-indentation
> bundle exec rubocop -A Bipbop.rb 1>/dev/null 2>&1

fpelayo in ~/Workspace/sequra-style at M211 on access-modifier-indentation
> cat Bipbop.rb
class Bipbop
  def the_public_thing
    "This is public"
  end

private

  def the_private_thing
    "This is private"
  end
end

Is this not the case you're concerned about?

@valdis
Copy link

valdis commented Mar 22, 2024

I have a concern.

Right now the rule that wants private methods indented relative to private is not activating, but if you apply the fix for the new rule and indent private it will:

The changes will not be like

-private
+  private

but like

-private
+  private

-  def any_other_method
-    here
-  end
+    def any_other_method
+      here
+    end

-  def below
-    here
-  end
+    def below
+      here
+    end

Rules that force code re-formating are anoying, but they annoy us only for a limited time. Thus i don't see this being a problem.
If we agree that this is the way how we want all our code formated, then let's set the rules and enforce them right away so each new PR we do would be forced to adapt this change.

@ferranpm ferranpm merged commit 3fb4ece into master Apr 3, 2024
4 checks passed
@ferranpm ferranpm deleted the access-modifier-indentation branch April 3, 2024 10:09
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.

8 participants