Skip to content

Commit

Permalink
Use theforeman-rubcoop Gem
Browse files Browse the repository at this point in the history
Inherited strictest.yml here, this rules have NewCops enable config.
Also dropped some cops from here because that was either included in
the inherit file or was not needed anymore.
  • Loading branch information
archanaserver authored and stejskalleos committed Jul 31, 2024
1 parent e3b087a commit 7b7eae9
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 50 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/unit_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 6 additions & 37 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -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
65 changes: 65 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 1 addition & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rake/testtask'
require 'bundler/gem_tasks'

Expand All @@ -24,5 +26,5 @@ rescue LoadError
task default: :test
else
RuboCop::RakeTask.new
task default: [:rubocop, :test]
task default: %i[rubocop test]
end
2 changes: 2 additions & 0 deletions hammer_cli_foreman_discovery.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

$LOAD_PATH.unshift(File.expand_path('lib', __dir__))

# Maintain your gem's version:
Expand Down
2 changes: 2 additions & 0 deletions lib/hammer_cli_foreman_discovery.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module HammerCLIForemanDiscovery
require 'hammer_cli_foreman_discovery/version'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module HammerCLIForemanDiscovery
module CommandExtensions
class ProvisionWithPuppet < HammerCLI::CommandExtensions
Expand Down
10 changes: 5 additions & 5 deletions lib/hammer_cli_foreman_discovery/discovery.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'hammer_cli'
require 'hammer_cli_foreman'
require 'hammer_cli_foreman/fact'
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions lib/hammer_cli_foreman_discovery/discovery_references.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module HammerCLIForemanDiscovery
module DiscoveryReferences
def self.hosts(dsl)
Expand Down
2 changes: 2 additions & 0 deletions lib/hammer_cli_foreman_discovery/discovery_rule.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'hammer_cli'
require 'hammer_cli_foreman'
require 'hammer_cli_foreman_discovery/discovery_references'
Expand Down
2 changes: 2 additions & 0 deletions lib/hammer_cli_foreman_discovery/i18n.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'hammer_cli/i18n'

module HammerCLIForemanDiscovery
Expand Down
2 changes: 2 additions & 0 deletions lib/hammer_cli_foreman_discovery/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module HammerCLIForemanDiscovery
def self.version
@version ||= Gem::Version.new('1.3.0')
Expand Down
10 changes: 6 additions & 4 deletions test/unit/discovery_resource_mock.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions test/unit/discovery_rules_test.rb
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
2 changes: 2 additions & 0 deletions test/unit/discovery_test.rb
Original file line number Diff line number Diff line change
@@ -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'

Expand Down

0 comments on commit 7b7eae9

Please sign in to comment.