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 1.69.0 offenses #482

Open
rwaffen opened this issue Nov 29, 2024 · 1 comment
Open

fix rubocop 1.69.0 offenses #482

rwaffen opened this issue Nov 29, 2024 · 1 comment
Assignees

Comments

@rwaffen
Copy link
Member

rwaffen commented Nov 29, 2024

Can you please have a look at this? I know that it is bad to object&.methode&.methode&.methode, but not how to fix it in our code...

Offenses:

app/models/data_file.rb:71:24: C: Style/SafeNavigationChainLength: Avoid safe navigation chains longer than 2 calls. (https://rubystyle.guide#safe-navigation)
    candidate_files = (node&.environment&.environment_layer&.hierarchies || []).map do |h|
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/hiera_data/layer/module.rb:7:22: C: Style/SafeNavigationChainLength: Avoid safe navigation chains longer than 2 calls. (https://rubystyle.guide#safe-navigation)
        @namespace = key&.match(/^(.+?)::/)&.captures&.first
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

167 files inspected, 2 offenses detected
@oneiros
Copy link
Collaborator

oneiros commented Dec 30, 2024

In the first instance it would be ideal if the node had a method hierarchies that somehow hides the fact that it is a long chain of method calls. This is a minor refactoring which may or may not provide any value. Please let me know if I should do this.

I think the second case can only be "improved" by blowing this up into multiple lines with a couple of if conditionals. The line is a bit hard to read, but I am not convinced that the longer form is really more helpful here.

Personally I would be totally fine with deactivating the cop, either for those specific lines or even altogether.

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

No branches or pull requests

2 participants