diff --git a/.rubocop.yml b/.rubocop.yml index 913e057..82874bc 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,39 +1,3 @@ -require: - - rubocop-performance - - rubocop-rails - - rubocop-minitest - -AllCops: - TargetRubyVersion: 2.7 - TargetRailsVersion: 6.1 - Exclude: - - 'node_modules/**/*' - - 'vendor/**/*' - -Layout/ArgumentAlignment: - EnforcedStyle: with_fixed_indentation - IndentationWidth: 2 - -Layout/EmptyLineAfterGuardClause: - Enabled: false - -Layout/LineLength: - Enabled: 111 # TODO: discuss and set this - -Rails: - Enabled: true - -Style/Alias: - EnforcedStyle: prefer_alias_method - -# Don't enforce documentation -Style/Documentation: - Enabled: false - -# Don't enforce frozen string literals -Style/FrozenStringLiteralComment: - Enabled: false - -# Support both ruby19 and hash_rockets -Style/HashSyntax: - Enabled: false +inherit_gem: + theforeman-rubocop: + - default.yml diff --git a/Gemfile b/Gemfile index fa75df1..5169d5a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ source 'https://rubygems.org' gemspec + +gem 'theforeman-rubocop', '~> 0.1.0' diff --git a/Rakefile b/Rakefile index 8c2f287..dbc8d27 100755 --- a/Rakefile +++ b/Rakefile @@ -38,7 +38,7 @@ task default: :test begin require 'rubocop/rake_task' RuboCop::RakeTask.new -rescue +rescue LoadError puts 'Rubocop not loaded.' end diff --git a/foreman_plugin_template.gemspec b/foreman_plugin_template.gemspec index c44e923..25e65ae 100644 --- a/foreman_plugin_template.gemspec +++ b/foreman_plugin_template.gemspec @@ -18,8 +18,4 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 2.7' s.add_development_dependency 'rdoc' - s.add_development_dependency 'rubocop' - s.add_development_dependency 'rubocop-minitest' - s.add_development_dependency 'rubocop-performance' - s.add_development_dependency 'rubocop-rails' end diff --git a/lib/foreman_plugin_template/engine.rb b/lib/foreman_plugin_template/engine.rb index 5677d8d..4377036 100644 --- a/lib/foreman_plugin_template/engine.rb +++ b/lib/foreman_plugin_template/engine.rb @@ -26,7 +26,7 @@ class Engine < ::Rails::Engine # Add permissions security_block :foreman_plugin_template do permission :view_foreman_plugin_template, { :'foreman_plugin_template/example' => [:new_action], - :'react' => [:index] } + :react => [:index] } end # Add a new role called 'Discovery' if it doesn't exist @@ -45,13 +45,10 @@ class Engine < ::Rails::Engine # Include concerns in this config.to_prepare block config.to_prepare do - - begin - Host::Managed.send(:include, ForemanPluginTemplate::HostExtensions) - HostsHelper.send(:include, ForemanPluginTemplate::HostsHelperExtensions) - rescue => e - Rails.logger.warn "ForemanPluginTemplate: skipping engine hook (#{e})" - end + Host::Managed.include ForemanPluginTemplate::HostExtensions + HostsHelper.include ForemanPluginTemplate::HostsHelperExtensions + rescue StandardError => e + Rails.logger.warn "ForemanPluginTemplate: skipping engine hook (#{e})" end rake_tasks do diff --git a/lib/tasks/foreman_plugin_template_tasks.rake b/lib/tasks/foreman_plugin_template_tasks.rake index 48c73c8..d997921 100644 --- a/lib/tasks/foreman_plugin_template_tasks.rake +++ b/lib/tasks/foreman_plugin_template_tasks.rake @@ -23,23 +23,6 @@ namespace :test do end end -namespace :foreman_plugin_template do - task :rubocop do - begin - require 'rubocop/rake_task' - RuboCop::RakeTask.new(:rubocop_foreman_plugin_template) do |task| - task.patterns = ["#{ForemanPluginTemplate::Engine.root}/app/**/*.rb", - "#{ForemanPluginTemplate::Engine.root}/lib/**/*.rb", - "#{ForemanPluginTemplate::Engine.root}/test/**/*.rb"] - end - rescue - puts 'Rubocop not loaded.' - end - - Rake::Task['rubocop_foreman_plugin_template'].invoke - end -end - Rake::Task[:test].enhance ['test:foreman_plugin_template'] load 'tasks/jenkins.rake' diff --git a/rename.rb b/rename.rb index 029923f..5276254 100755 --- a/rename.rb +++ b/rename.rb @@ -32,7 +32,7 @@ def usage old_dirs = [] Find.find('.') do |path| next unless File.file?(path) - next if path =~ /\.git/ + next if /\.git/.match?(path) next if path == './rename.rb' # Change content on all files @@ -45,17 +45,16 @@ def usage Find.find('.') do |path| # Change all the paths to the new snake_case name - if path =~ /foreman_plugin_template/i - new = path.gsub('foreman_plugin_template', snake) - # Recursively copy the directory and store the original for deletion - # Check for $ because we don't need to copy template/hosts for example - if File.directory?(path) && path =~ /foreman_plugin_template$/i - FileUtils.cp_r(path, new) - old_dirs << path - else - # gsub replaces all instances, so it will work on the new directories - FileUtils.mv(path, new) - end + next unless /foreman_plugin_template/i.match?(path) + new = path.gsub('foreman_plugin_template', snake) + # Recursively copy the directory and store the original for deletion + # Check for $ because we don't need to copy template/hosts for example + if File.directory?(path) && path =~ /foreman_plugin_template$/i + FileUtils.cp_r(path, new) + old_dirs << path + else + # gsub replaces all instances, so it will work on the new directories + FileUtils.mv(path, new) end end