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

Use theforeman-rubocop gem #58

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question as in https://github.com/theforeman/hammer_cli_foreman_bootdisk/pull/18/files. Can we remove all other exceptions and have the config file the same as in the https://github.com/theforeman/hammer-cli-foreman-google/blob/master/.rubocop.yml?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stejskalleos here we already have rubocop todo file so added some cops in there, because right now our focus is more on adding theforeman-rubocop gem and less focus on solving all the offenses because of the new style rules. but i tried to solve some.

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:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also updated some cops in todo file, which was causing major changes in the code, but what do you think of it?

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]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is due to Style/SymbolArray cop

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