From b2ef844cc4d084e0df00a82467e6edc69134399b Mon Sep 17 00:00:00 2001 From: nofaralfasi Date: Mon, 19 Feb 2024 12:24:13 +0200 Subject: [PATCH 1/2] Use reusable GitHub Actions for testing --- .github/workflows/unit_tests.yaml | 19 ++++++++++++++ Gemfile | 10 +++----- hammer_cli_foreman_discovery.gemspec | 5 ++-- test/unit/discovery_rules_test.rb | 24 +++++++++--------- test/unit/discovery_test.rb | 38 ++++++++++++++-------------- 5 files changed, 57 insertions(+), 39 deletions(-) create mode 100644 .github/workflows/unit_tests.yaml diff --git a/.github/workflows/unit_tests.yaml b/.github/workflows/unit_tests.yaml new file mode 100644 index 0000000..01b36a6 --- /dev/null +++ b/.github/workflows/unit_tests.yaml @@ -0,0 +1,19 @@ +name: CI + +on: + pull_request: + push: + branches: + - 'master' + +concurrency: + group: ${{ github.ref_name }}-${{ github.workflow }} + cancel-in-progress: true + +jobs: + test: + name: Tests + uses: theforeman/actions/.github/workflows/test-gem.yml@v0 + with: + command: bundle exec rake test + \ No newline at end of file diff --git a/Gemfile b/Gemfile index fbcae40..036e215 100644 --- a/Gemfile +++ b/Gemfile @@ -3,16 +3,14 @@ source "https://rubygems.org" gemspec gem 'gettext', '>= 3.1.3', '< 4.0.0' -if RUBY_VERSION < '2.1.0' - gem 'fast_gettext', '< 1.2.0' -end +gem 'rake', '~> 13.0' +gem 'hammer_cli_foreman', github: 'theforeman/hammer-cli-foreman', branch: 'master' group :test do - gem 'rake', '>= 12.3.3' gem 'thor' - gem 'minitest', '4.7.4' + gem 'minitest', '~> 5.18' gem 'minitest-spec-context' - gem 'simplecov', '< 0.9.0' # 0.9.0 is not compatible with Ruby 1.8.x + gem 'simplecov' gem 'mocha' gem 'ci_reporter', '>= 1.6.3', "< 2.0.0", :require => false end diff --git a/hammer_cli_foreman_discovery.gemspec b/hammer_cli_foreman_discovery.gemspec index f75815b..5188889 100644 --- a/hammer_cli_foreman_discovery.gemspec +++ b/hammer_cli_foreman_discovery.gemspec @@ -21,6 +21,7 @@ DESC s.extra_rdoc_files = Dir['LICENSE', 'README*'] s.require_paths = ["lib"] - s.add_dependency "hammer_cli_foreman", ">= 0.1.2" - s.add_development_dependency 'rake' + s.add_dependency 'hammer_cli_foreman', '~> 3.9' + + s.required_ruby_version = '>= 2.7', '< 4' end diff --git a/test/unit/discovery_rules_test.rb b/test/unit/discovery_rules_test.rb index 73476ca..4390e3c 100644 --- a/test/unit/discovery_rules_test.rb +++ b/test/unit/discovery_rules_test.rb @@ -9,26 +9,26 @@ include CommandTestHelper - context "ListCommand" do + describe "ListCommand" do let(:cmd) { HammerCLIForemanDiscovery::DiscoveryRule::ListCommand.new("", ctx) } before :each do DiscoveryResourceMock.discovery_rules_index end - context "parameters" do + describe "parameters" do it_should_accept "no arguments" it_should_accept_search_params end - context "output" do + describe "output" do let(:expected_record_count) { cmd.resource.call(:index).length } it_should_print_n_records it_should_print_columns ["ID", "Name", "Priority", "Search", "Host Group", "Hosts Limit", "Enabled"] end end - context "InfoCommand" do + describe "InfoCommand" do let(:cmd) { HammerCLIForemanDiscovery::DiscoveryRule::InfoCommand.new("", ctx) } @@ -36,12 +36,12 @@ cmd.stubs(:get_parameters).returns([]) end - context "parameters" do + describe "parameters" do it_should_accept "id", ["--id=1"] it_should_accept "name", ["--name=rule"] end - context "output" do + describe "output" do with_params ["--id=1"] do it_should_print_n_records 1 it_should_print_columns ["ID", "Name", "Priority", "Search", "Host Group", "Hosts Limit", "Enabled", "Hostname template", "Hosts", "Locations", "Organizations"] @@ -50,22 +50,22 @@ end - context "DeleteCommand" do + describe "DeleteCommand" do let(:cmd) { HammerCLIForemanDiscovery::DiscoveryRule::DeleteCommand.new("", ctx) } - context "parameters" do + describe "parameters" do it_should_accept "name", ["--name=rule"] it_should_accept "id", ["--id=1"] end end - context "CreateCommand" do + describe "CreateCommand" do let(:cmd) { HammerCLIForemanDiscovery::DiscoveryRule::CreateCommand.new("", ctx) } - context "parameters" do + describe "parameters" do it_should_accept "name, priority, search, hostgroup, hostgroup-id, hosts-limit, locations, organizations and enabled", ["--name=rule", "--priority=1", "--search='cpu_count > 1'", "--hostgroup='test'", "--hostgroup-id=1", "--hosts-limit=1", @@ -84,11 +84,11 @@ end end - context "UpdateCommand" do + describe "UpdateCommand" do let(:cmd) { HammerCLIForemanDiscovery::DiscoveryRule::UpdateCommand.new("", ctx) } - context "parameters" do + describe "parameters" do it_should_accept "id, name, priority, search, hostgroup, hostgroup-id, hosts-limit and enabled", ["--id=1", "--name=rule", "--priority=1", "--search=cpu_count > 1", "--hostgroup='test'", "--hostgroup-id=1", "--hosts-limit=1", "--enabled=true"] it_should_accept "name", ["--name=rule", "--new-name=rule2"] diff --git a/test/unit/discovery_test.rb b/test/unit/discovery_test.rb index da60ea0..17e4ba0 100644 --- a/test/unit/discovery_test.rb +++ b/test/unit/discovery_test.rb @@ -9,26 +9,26 @@ include CommandTestHelper - context "ListCommand" do + describe "ListCommand" do let(:cmd) { HammerCLIForemanDiscovery::DiscoveredHost::ListCommand.new("", ctx) } before :each do DiscoveryResourceMock.discovered_hosts_index end - context "parameters" do + describe "parameters" do it_should_accept "no arguments" it_should_accept_search_params end - context "output" do + describe "output" do let(:expected_record_count) { cmd.resource.call(:index).length } it_should_print_n_records it_should_print_columns ["ID", "Name", "MAC", "Last report", "Subnet", "CPUs", "Memory", "Disk count", "Disks size"] end end - context "InfoCommand" do + describe "InfoCommand" do let(:cmd) { HammerCLIForemanDiscovery::DiscoveredHost::InfoCommand.new("", ctx) } @@ -36,12 +36,12 @@ cmd.stubs(:get_parameters).returns([]) end - context "parameters" do + describe "parameters" do it_should_accept "id", ["--id=1"] it_should_accept "name", ["--name=host"] end - context "output" do + describe "output" do with_params ["--id=1"] do it_should_print_n_records 1 it_should_print_columns ["ID", "Name", "MAC", "Last report", "Subnet", "CPUs", "Memory", "Disk count", "Disks size", "Organization", "Location"] @@ -51,21 +51,21 @@ end - context "DeleteCommand" do + describe "DeleteCommand" do let(:cmd) { HammerCLIForemanDiscovery::DiscoveredHost::DeleteCommand.new("", ctx) } - context "parameters" do + describe "parameters" do it_should_accept "name", ["--name=host"] it_should_accept "id", ["--id=1"] end end - context "ProvisionCommand" do + describe "ProvisionCommand" do let(:cmd) { HammerCLIForemanDiscovery::DiscoveredHost::ProvisionCommand.new("", ctx) } - context "parameters" do + describe "parameters" do it_should_accept "name, architecture_id, domain_id, operatingsystem_id and more", ["--name=host", "--architecture-id=1", "--domain-id=1", "--operatingsystem-id=1", "--ip=1.2.3.4", "--mac=11:22:33:44:55:66", "--medium-id=1", "--partition-table-id=1", "--subnet-id=1", @@ -84,35 +84,35 @@ end end - context "AutoProvisionCommand" do + describe "AutoProvisionCommand" do let(:cmd) { HammerCLIForemanDiscovery::DiscoveredHost::AutoProvisionCommand.new("", ctx) } - context "parameters" do + describe "parameters" do it_should_accept "name", ["--name=host"] it_should_accept "id", ["--id=1"] end end - context "RebootCommand" do + describe "RebootCommand" do let(:cmd) { HammerCLIForemanDiscovery::DiscoveredHost::RebootCommand.new("", ctx) } - context "parameters" do + describe "parameters" do it_should_accept "name", ["--name=host"] it_should_accept "id", ["--id=1"] end end - context "RefreshFactsCommand" do + describe "RefreshFactsCommand" do let(:cmd) { HammerCLIForemanDiscovery::DiscoveredHost::RefreshFactsCommand.new("", ctx) } - context "parameters" do + describe "parameters" do it_should_accept "name", ["--name=host"] it_should_accept "id", ["--id=1"] end end - context "FactsCommand" do + describe "FactsCommand" do let(:cmd) { HammerCLIForemanDiscovery::DiscoveredHost::FactsCommand.new("", ctx) } @@ -120,12 +120,12 @@ DiscoveryResourceMock.facts_index end - context "parameters" do + describe "parameters" do it_should_accept "name", ["--name=mac52540068f9d6"] it_should_accept "id", ["--id=1"] end - context "output" do + describe "output" do with_params ["--name=mac52540068f9d6"] do it_should_print_column "Fact" it_should_print_column "Value" From 9386e071a53a207a2459d03f9d6d99a231bcc934 Mon Sep 17 00:00:00 2001 From: nofaralfasi Date: Mon, 19 Feb 2024 13:35:52 +0200 Subject: [PATCH 2/2] Add RuboCop for code style enforcement --- .github/workflows/unit_tests.yaml | 4 + .rubocop.yml | 33 ++ .rubocop_todo.yml | 301 ++++++++++++++++++ Gemfile | 4 + Rakefile | 11 + lib/hammer_cli_foreman_discovery/discovery.rb | 5 +- 6 files changed, 355 insertions(+), 3 deletions(-) create mode 100644 .rubocop.yml create mode 100644 .rubocop_todo.yml diff --git a/.github/workflows/unit_tests.yaml b/.github/workflows/unit_tests.yaml index 01b36a6..9e8ee3f 100644 --- a/.github/workflows/unit_tests.yaml +++ b/.github/workflows/unit_tests.yaml @@ -11,6 +11,10 @@ concurrency: cancel-in-progress: true jobs: + rubocop: + name: Rubocop + uses: theforeman/actions/.github/workflows/rubocop.yml@v0 + test: name: Tests uses: theforeman/actions/.github/workflows/test-gem.yml@v0 diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..f25d7c8 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,33 @@ +inherit_from: .rubocop_todo.yml + +require: + - rubocop-performance + - rubocop-rails + - rubocop-minitest + +AllCops: + TargetRubyVersion: 2.7 + +Layout/DotPosition: + EnforcedStyle: 'trailing' + +Layout/EmptyLineAfterGuardClause: + Enabled: false + +Layout/LineLength: + Enabled: false + +Metrics: + Enabled: false + +Style/FormatStringToken: + EnforcedStyle: template + +Style/HashSyntax: + EnforcedStyle: no_mixed_keys + +Style/SymbolArray: + EnforcedStyle: brackets + +Style/Documentation: + Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..fe55b38 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,301 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2024-02-19 11:31:23 UTC using RuboCop version 1.57.2. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 4 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include. +# Include: **/*.gemfile, **/Gemfile, **/gems.rb +Bundler/OrderedGems: + Exclude: + - 'Gemfile' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: with_first_argument, with_fixed_indentation +Layout/ArgumentAlignment: + Exclude: + - 'lib/hammer_cli_foreman_discovery/discovery.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Layout/ClosingParenthesisIndentation: + Exclude: + - 'test/unit/discovery_resource_mock.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Layout/EmptyLineAfterMagicComment: + Exclude: + - 'hammer_cli_foreman_discovery.gemspec' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, DefLikeMacros, AllowAdjacentOneLineDefs, NumberOfEmptyLines. +Layout/EmptyLineBetweenDefs: + Exclude: + - 'lib/hammer_cli_foreman_discovery/discovery.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Layout/EmptyLines: + Exclude: + - 'lib/hammer_cli_foreman_discovery/discovery.rb' + +# Offense count: 19 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, no_empty_lines +Layout/EmptyLinesAroundBlockBody: + Exclude: + - 'lib/hammer_cli_foreman_discovery/command_extensions/provision_with_puppet.rb' + - 'test/unit/discovery_rules_test.rb' + - 'test/unit/discovery_test.rb' + +# Offense count: 5 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only +Layout/EmptyLinesAroundClassBody: + Exclude: + - 'lib/hammer_cli_foreman_discovery/discovery.rb' + - 'lib/hammer_cli_foreman_discovery/discovery_rule.rb' + - 'lib/hammer_cli_foreman_discovery/i18n.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Layout/EmptyLinesAroundExceptionHandlingKeywords: + Exclude: + - 'lib/hammer_cli_foreman_discovery.rb' + +# Offense count: 8 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines +Layout/EmptyLinesAroundModuleBody: + Exclude: + - 'lib/hammer_cli_foreman_discovery/discovery.rb' + - 'lib/hammer_cli_foreman_discovery/discovery_references.rb' + - 'lib/hammer_cli_foreman_discovery/discovery_rule.rb' + - 'lib/hammer_cli_foreman_discovery/i18n.rb' + - 'test/unit/discovery_resource_mock.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. +Layout/ExtraSpacing: + Exclude: + - 'lib/hammer_cli_foreman_discovery/discovery.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: consistent, consistent_relative_to_receiver, special_for_inner_method_call, special_for_inner_method_call_in_parentheses +Layout/FirstArgumentIndentation: + Exclude: + - 'test/unit/discovery_resource_mock.rb' + +# Offense count: 6 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: special_inside_parentheses, consistent, align_braces +Layout/FirstHashElementIndentation: + Exclude: + - 'test/unit/discovery_resource_mock.rb' + +# Offense count: 11 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. +# SupportedHashRocketStyles: key, separator, table +# SupportedColonStyles: key, separator, table +# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit +Layout/HashAlignment: + Exclude: + - 'lib/hammer_cli_foreman_discovery/discovery.rb' + - 'test/unit/discovery_resource_mock.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Layout/HeredocIndentation: + Exclude: + - 'hammer_cli_foreman_discovery.gemspec' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: Width, AllowedPatterns. +Layout/IndentationWidth: + Exclude: + - 'lib/hammer_cli_foreman_discovery/discovery.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: symmetrical, new_line, same_line +Layout/MultilineMethodCallBraceLayout: + Exclude: + - 'lib/hammer_cli_foreman_discovery.rb' + +# Offense count: 15 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. +# SupportedStylesForExponentOperator: space, no_space +Layout/SpaceAroundOperators: + Exclude: + - 'lib/hammer_cli_foreman_discovery/discovery.rb' + - 'test/unit/discovery_resource_mock.rb' + +# Offense count: 4 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets. +# SupportedStyles: space, no_space, compact +# SupportedStylesForEmptyBrackets: space, no_space +Layout/SpaceInsideArrayLiteralBrackets: + Exclude: + - 'test/unit/discovery_resource_mock.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceInsideBlockBraces: + Exclude: + - 'lib/hammer_cli_foreman_discovery/discovery.rb' + +# Offense count: 7 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. +# SupportedStyles: space, no_space, compact +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceInsideHashLiteralBraces: + Exclude: + - 'lib/hammer_cli_foreman_discovery/command_extensions/provision_with_puppet.rb' + - 'lib/hammer_cli_foreman_discovery/discovery.rb' + - 'test/unit/discovery_resource_mock.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: final_newline, final_blank_line +Layout/TrailingEmptyLines: + Exclude: + - 'lib/hammer_cli_foreman_discovery/discovery_references.rb' + - 'lib/hammer_cli_foreman_discovery/i18n.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: PreferredName. +Naming/RescuedExceptionsVariableName: + Exclude: + - 'lib/hammer_cli_foreman_discovery/discovery.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/Encoding: + Exclude: + - 'hammer_cli_foreman_discovery.gemspec' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/ExpandPathArguments: + Exclude: + - 'hammer_cli_foreman_discovery.gemspec' + +# Offense count: 13 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, always_true, never +Style/FrozenStringLiteralComment: + Exclude: + - 'Gemfile' + - 'Rakefile' + - 'hammer_cli_foreman_discovery.gemspec' + - 'lib/hammer_cli_foreman_discovery.rb' + - 'lib/hammer_cli_foreman_discovery/command_extensions/provision_with_puppet.rb' + - 'lib/hammer_cli_foreman_discovery/discovery.rb' + - 'lib/hammer_cli_foreman_discovery/discovery_references.rb' + - 'lib/hammer_cli_foreman_discovery/discovery_rule.rb' + - 'lib/hammer_cli_foreman_discovery/i18n.rb' + - 'lib/hammer_cli_foreman_discovery/version.rb' + - 'test/unit/discovery_resource_mock.rb' + - 'test/unit/discovery_rules_test.rb' + - 'test/unit/discovery_test.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/IfUnlessModifier: + Exclude: + - 'lib/hammer_cli_foreman_discovery/discovery.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: short, verbose +Style/PreferredHashMethods: + Exclude: + - 'lib/hammer_cli_foreman_discovery/discovery.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowedCompactTypes. +# SupportedStyles: compact, exploded +Style/RaiseArgs: + EnforcedStyle: compact + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantSelf: + Exclude: + - 'Gemfile' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: implicit, explicit +Style/RescueStandardError: + Exclude: + - 'lib/hammer_cli_foreman_discovery.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: RequireEnglish. +# SupportedStyles: use_perl_names, use_english_names, use_builtin_english_names +Style/SpecialGlobalVars: + EnforcedStyle: use_perl_names + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: Mode. +Style/StringConcatenation: + Exclude: + - 'lib/hammer_cli_foreman_discovery/discovery.rb' + +# Offense count: 356 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiterals: + Exclude: + - 'Gemfile' + - 'Rakefile' + - 'hammer_cli_foreman_discovery.gemspec' + - 'lib/hammer_cli_foreman_discovery.rb' + - 'lib/hammer_cli_foreman_discovery/command_extensions/provision_with_puppet.rb' + - 'lib/hammer_cli_foreman_discovery/discovery.rb' + - 'lib/hammer_cli_foreman_discovery/discovery_references.rb' + - 'lib/hammer_cli_foreman_discovery/discovery_rule.rb' + - 'test/unit/discovery_resource_mock.rb' + - 'test/unit/discovery_rules_test.rb' + - 'test/unit/discovery_test.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: MinSize, WordRegex. +# SupportedStyles: percent, brackets +Style/WordArray: + EnforcedStyle: brackets diff --git a/Gemfile b/Gemfile index 036e215..2dbaac1 100644 --- a/Gemfile +++ b/Gemfile @@ -13,6 +13,10 @@ group :test do gem 'simplecov' gem 'mocha' gem 'ci_reporter', '>= 1.6.3', "< 2.0.0", :require => false + gem 'rubocop', '~> 1.57.0' + gem 'rubocop-minitest', '~> 0.9.0' + gem 'rubocop-performance', '~> 1.5.2' + gem 'rubocop-rails', '~> 2.7.1' end # load local gemfile diff --git a/Rakefile b/Rakefile index 6d6ba9f..1ef3b7f 100644 --- a/Rakefile +++ b/Rakefile @@ -17,3 +17,14 @@ require "hammer_cli_foreman_discovery/version" require "hammer_cli_foreman_discovery/i18n" require "hammer_cli/i18n/find_task" HammerCLI::I18n::FindTask.define(HammerCLIForemanDiscovery::I18n::LocaleDomain.new, HammerCLIForemanDiscovery.version.to_s) + +begin + require 'rubocop/rake_task' + RuboCop::RakeTask.new +rescue StandardError => _e + puts 'Rubocop not loaded.' +end + +task :default do + Rake::Task['rubocop'].execute +end diff --git a/lib/hammer_cli_foreman_discovery/discovery.rb b/lib/hammer_cli_foreman_discovery/discovery.rb index 9f09dfd..0c2c604 100644 --- a/lib/hammer_cli_foreman_discovery/discovery.rb +++ b/lib/hammer_cli_foreman_discovery/discovery.rb @@ -126,9 +126,8 @@ def parameter_attributes end end - build_options without: %i[ - root_pass ptable_id host_parameters_attributes - puppet_class_ids environment_id puppet_proxy_id puppet_ca_proxy_id + build_options without: [ + :root_pass, :ptable_id, :host_parameters_attributes, :puppet_class_ids, :environment_id, :puppet_proxy_id, :puppet_ca_proxy_id ] do |o| # TODO: Until the API is cleaned up o.expand.except(:environments)