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 #60

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
42 changes: 3 additions & 39 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
source 'https://rubygems.org'

gemspec

gem 'theforeman-rubocop', '~> 0.1.0'
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ task default: :test
begin
require 'rubocop/rake_task'
RuboCop::RakeTask.new
rescue
rescue LoadError
puts 'Rubocop not loaded.'
end

Expand Down
4 changes: 0 additions & 4 deletions foreman_plugin_template.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 5 additions & 8 deletions lib/foreman_plugin_template/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
17 changes: 0 additions & 17 deletions lib/tasks/foreman_plugin_template_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
23 changes: 11 additions & 12 deletions rename.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
archanaserver marked this conversation as resolved.
Show resolved Hide resolved
next if path == './rename.rb'

# Change content on all files
Expand All @@ -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

Expand Down