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 rules #182

Closed
wants to merge 3 commits into from
Closed

Conversation

archanaserver
Copy link
Contributor

@archanaserver archanaserver commented Jan 26, 2024


Layout/ExtraSpacing:
Enabled: true

# JobTemplates use this for inputs, we should probably whitelist classes
Security/YAMLLoad:
Copy link
Member

Choose a reason for hiding this comment

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

This will be an issue with Ruby 3 where load became safe_load.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ekohl what is this about? could you please brief more.

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/cops_security.html#securityyamlload already has a note. Looks like it's Ruby 3.1, not 3.0.

@@ -2,7 +2,7 @@ module ForemanTemplates
class ExportResult
attr_reader :template, :name, :template_file, :exported, :additional_info

def initialize(template, exported = true)
def initialize(template, exported: true)
Copy link
Member

Choose a reason for hiding this comment

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

I think either this API change breaks things, or it's the one parse_result:

Failure:
test_0008_should force update locked template on import(Minitest::Result) [/home/jenkins/workspace/foreman_templates-pull-request/label/fast/ruby/2.7/plugin/test/functional/api/v2/template_controller_test.rb:110]:
Expected response to be a <2XX: success>, but was a <500: Internal Server Error>
Response body: {
  "error": {"message":"wrong number of arguments (given 1, expected 0)"}
}

But the commit Fix Style/OptionalBooleanParameter cop breaks things. It's not a safe cop where you can simply change things, just like I said in theforeman/foreman-installer#883 (comment).

Copy link
Member

Choose a reason for hiding this comment

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

Even though boolean kw parameter looks nicer, I'd not change signatures just now to make rubocop happy.

Copy link
Member

@ofedoren ofedoren left a comment

Choose a reason for hiding this comment

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

Except for the boolean kw arguments rule, LGTM.

@@ -2,7 +2,7 @@ module ForemanTemplates
class ExportResult
attr_reader :template, :name, :template_file, :exported, :additional_info

def initialize(template, exported = true)
def initialize(template, exported: true)
Copy link
Member

Choose a reason for hiding this comment

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

Even though boolean kw parameter looks nicer, I'd not change signatures just now to make rubocop happy.

@@ -7,7 +7,7 @@ def initialize(template_file)
@template_file = template_file.split('/').last
end

def to_h(verbose = false)
Copy link
Member

Choose a reason for hiding this comment

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

Same here, let's stick with the old optional argument.

@ofedoren
Copy link
Member

@archanaserver, could you please rebase?

Copy link
Member

@ofedoren ofedoren left a comment

Choose a reason for hiding this comment

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

Well, after rebasing it seems there is nothing left to fix. Maybe I'd treat this PR to ensure we resolved the issue Ewoud mentioned in https://github.com/theforeman/foreman_templates/pull/182/files#r1467571359

@@ -26,7 +26,7 @@ class TemplateControllerTest < ::ActionController::TestCase
FactoryBot.create(:provisioning_template, :name => 'export_test_template')
post :export, params: { "repo" => tmpdir, "filter" => "^export_test_template", "negate" => true, "metadata_export_mode" => "keep" }
assert_response :success
refute_includes(Dir.entries("#{tmpdir}/provisioning_templates/provision"), 'export_test_template.erb')
Copy link
Member

Choose a reason for hiding this comment

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

Hmm.. Is this necessary?

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 guess, I've skipped this while rebasing, lemme fix it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants