diff --git a/.github/workflows/unit_tests.yaml b/.github/workflows/unit_tests.yaml index 1e3b5d6..8a170a8 100644 --- a/.github/workflows/unit_tests.yaml +++ b/.github/workflows/unit_tests.yaml @@ -14,6 +14,8 @@ jobs: rubocop: name: Rubocop uses: theforeman/actions/.github/workflows/rubocop.yml@v0 + with: + command: bundle exec rubocop --parallel --format github test: name: Tests diff --git a/.rubocop.yml b/.rubocop.yml index 0782293..9ede337 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,42 +1,11 @@ -require: - - rubocop-performance - - rubocop-minitest +inherit_from: .rubocop_todo.yml -AllCops: - NewCops: enable - -Layout/EmptyLineAfterGuardClause: - Enabled: false +inherit_gem: + theforeman-rubocop: + - strictest.yml -Layout/LineLength: - Enabled: false +AllCops: + TargetRubyVersion: 2.7 Metrics: Enabled: false - -Style/FormatStringToken: - EnforcedStyle: template - -Style/HashSyntax: - EnforcedStyle: no_mixed_keys - -Style/SymbolArray: - EnforcedStyle: brackets - -Style/Documentation: - Enabled: false - -Style/GuardClause: - Enabled: false - -Style/StringLiterals: - Enabled: false - -Style/FrozenStringLiteralComment: - Enabled: false - -Style/IfUnlessModifier: - Enabled: false - -Gemspec/RequireMFA: - Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..2e2b586 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,65 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2024-07-31 10:08:15 UTC using RuboCop version 1.64.1. +# 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: 21 +# 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.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_rule.rb' + - 'test/unit/discovery_rules_test.rb' + - 'test/unit/discovery_test.rb' + +# Offense count: 2 +# 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: 15 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. +# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys +# SupportedShorthandSyntax: always, never, either, consistent, either_consistent +Style/HashSyntax: + Exclude: + - 'Rakefile' + - 'lib/hammer_cli_foreman_discovery.rb' + - 'lib/hammer_cli_foreman_discovery/discovery.rb' + - 'lib/hammer_cli_foreman_discovery/discovery_references.rb' + - 'lib/hammer_cli_foreman_discovery/discovery_rule.rb' + +# Offense count: 350 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiterals: + Exclude: + - '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: 18 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. +# URISchemes: http, https +Layout/LineLength: + Max: 169 diff --git a/Gemfile b/Gemfile index 8d67365..724233f 100644 --- a/Gemfile +++ b/Gemfile @@ -11,10 +11,8 @@ group :test do gem 'minitest', '~> 5.18' gem 'minitest-spec-context' gem 'mocha' - gem 'rubocop', '~> 1.57.0' - gem 'rubocop-minitest', '~> 0.9.0' - gem 'rubocop-performance', '~> 1.5.2' gem 'simplecov' + gem 'theforeman-rubocop', '~> 0.1.0' gem 'thor' end diff --git a/Rakefile b/Rakefile index 1844265..f256866 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rake/testtask' require 'bundler/gem_tasks' @@ -24,5 +26,5 @@ rescue LoadError task default: :test else RuboCop::RakeTask.new - task default: [:rubocop, :test] + task default: %i[rubocop test] end diff --git a/hammer_cli_foreman_discovery.gemspec b/hammer_cli_foreman_discovery.gemspec index 5fd9019..b4eea43 100644 --- a/hammer_cli_foreman_discovery.gemspec +++ b/hammer_cli_foreman_discovery.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH.unshift(File.expand_path('lib', __dir__)) # Maintain your gem's version: diff --git a/lib/hammer_cli_foreman_discovery.rb b/lib/hammer_cli_foreman_discovery.rb index 1dd7055..eb22174 100644 --- a/lib/hammer_cli_foreman_discovery.rb +++ b/lib/hammer_cli_foreman_discovery.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module HammerCLIForemanDiscovery require 'hammer_cli_foreman_discovery/version' diff --git a/lib/hammer_cli_foreman_discovery/command_extensions/provision_with_puppet.rb b/lib/hammer_cli_foreman_discovery/command_extensions/provision_with_puppet.rb index 9c92f2c..f2c3fbe 100644 --- a/lib/hammer_cli_foreman_discovery/command_extensions/provision_with_puppet.rb +++ b/lib/hammer_cli_foreman_discovery/command_extensions/provision_with_puppet.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module HammerCLIForemanDiscovery module CommandExtensions class ProvisionWithPuppet < HammerCLI::CommandExtensions diff --git a/lib/hammer_cli_foreman_discovery/discovery.rb b/lib/hammer_cli_foreman_discovery/discovery.rb index 1ea25bc..aa1ae41 100644 --- a/lib/hammer_cli_foreman_discovery/discovery.rb +++ b/lib/hammer_cli_foreman_discovery/discovery.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'hammer_cli' require 'hammer_cli_foreman' require 'hammer_cli_foreman/fact' @@ -106,9 +108,7 @@ def request_params params['discovered_host']['root_pass'] = option_root_password unless option_root_password.nil? params['discovered_host']['overwrite'] = option_overwrite unless option_overwrite.nil? - if option_ask_root_password - params['discovered_host']['root_pass'] = ask_password - end + params['discovered_host']['root_pass'] = ask_password if option_ask_root_password params end @@ -124,8 +124,8 @@ def parameter_attributes end end - build_options without: [ - :root_pass, :ptable_id, :host_parameters_attributes, :puppet_class_ids, :environment_id, :puppet_proxy_id, :puppet_ca_proxy_id + build_options without: %i[ + 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) diff --git a/lib/hammer_cli_foreman_discovery/discovery_references.rb b/lib/hammer_cli_foreman_discovery/discovery_references.rb index 8c28678..c2eaf56 100644 --- a/lib/hammer_cli_foreman_discovery/discovery_references.rb +++ b/lib/hammer_cli_foreman_discovery/discovery_references.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module HammerCLIForemanDiscovery module DiscoveryReferences def self.hosts(dsl) diff --git a/lib/hammer_cli_foreman_discovery/discovery_rule.rb b/lib/hammer_cli_foreman_discovery/discovery_rule.rb index 474cced..e287684 100644 --- a/lib/hammer_cli_foreman_discovery/discovery_rule.rb +++ b/lib/hammer_cli_foreman_discovery/discovery_rule.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'hammer_cli' require 'hammer_cli_foreman' require 'hammer_cli_foreman_discovery/discovery_references' diff --git a/lib/hammer_cli_foreman_discovery/i18n.rb b/lib/hammer_cli_foreman_discovery/i18n.rb index 031ad1f..2d43618 100644 --- a/lib/hammer_cli_foreman_discovery/i18n.rb +++ b/lib/hammer_cli_foreman_discovery/i18n.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'hammer_cli/i18n' module HammerCLIForemanDiscovery diff --git a/lib/hammer_cli_foreman_discovery/version.rb b/lib/hammer_cli_foreman_discovery/version.rb index c0c627e..acc73d7 100644 --- a/lib/hammer_cli_foreman_discovery/version.rb +++ b/lib/hammer_cli_foreman_discovery/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module HammerCLIForemanDiscovery def self.version @version ||= Gem::Version.new('1.3.0') diff --git a/test/unit/discovery_resource_mock.rb b/test/unit/discovery_resource_mock.rb index 0a94cba..e45db9a 100644 --- a/test/unit/discovery_resource_mock.rb +++ b/test/unit/discovery_resource_mock.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.join(Gem.loaded_specs['hammer_cli_foreman'].full_gem_path, 'test/unit/apipie_resource_mock') module DiscoveryResourceMock @@ -21,16 +23,16 @@ def self.facts_index "search" => "", "sort" => { "by" => nil, - "order" => nil + "order" => nil, }, "results" => [{ "some.host.com" => { "network_br180" => "10.32.83.0", "mtu_usb0" => "1500", "physicalprocessorcount" => "1", - "rubyversion" => "1.8.7" - } - }] + "rubyversion" => "1.8.7", + }, + }], }) end diff --git a/test/unit/discovery_rules_test.rb b/test/unit/discovery_rules_test.rb index 689e7bc..ff5093f 100644 --- a/test/unit/discovery_rules_test.rb +++ b/test/unit/discovery_rules_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # using this before the require so test_helper resolves the correct foreman_api.json to use ENV['TEST_API_VERSION'] = '2.4' diff --git a/test/unit/discovery_test.rb b/test/unit/discovery_test.rb index 050bd1e..7c32d96 100644 --- a/test/unit/discovery_test.rb +++ b/test/unit/discovery_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # using this before the require so test_helper resolves the correct foreman_api.json to use ENV['TEST_API_VERSION'] = '2.4'